1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/api/feedback_private/feedback_service.h"
7 #include "base/callback.h"
8 #include "base/memory/weak_ptr.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "content/public/browser/browser_thread.h"
13 using content::BrowserThread;
15 namespace extensions {
18 void FeedbackService::PopulateSystemInfo(
19 SystemInformationList* sys_info_list,
20 const std::string& key,
21 const std::string& value) {
22 base::DictionaryValue sys_info_value;
23 sys_info_value.Set("key", new base::StringValue(key));
24 sys_info_value.Set("value", new base::StringValue(value));
26 linked_ptr<SystemInformation> sys_info(new SystemInformation());
27 SystemInformation::Populate(sys_info_value, sys_info.get());
29 sys_info_list->push_back(sys_info);
32 FeedbackService::FeedbackService() {
35 FeedbackService::~FeedbackService() {
38 void FeedbackService::SendFeedback(
40 scoped_refptr<FeedbackData> feedback_data,
41 const SendFeedbackCallback& callback) {
42 send_feedback_callback_ = callback;
43 feedback_data_ = feedback_data;
45 if (!feedback_data_->attached_file_uuid().empty()) {
46 // Self-deleting object.
47 BlobReader* attached_file_reader = new BlobReader(
48 profile, feedback_data_->attached_file_uuid(),
49 base::Bind(&FeedbackService::AttachedFileCallback,
51 attached_file_reader->Start();
54 if (!feedback_data_->screenshot_uuid().empty()) {
55 // Self-deleting object.
56 BlobReader* screenshot_reader = new BlobReader(
57 profile, feedback_data_->screenshot_uuid(),
58 base::Bind(&FeedbackService::ScreenshotCallback,
60 screenshot_reader->Start();
63 CompleteSendFeedback();
66 void FeedbackService::AttachedFileCallback(scoped_ptr<std::string> data) {
68 feedback_data_->set_attached_file_uuid(std::string());
70 feedback_data_->AttachAndCompressFileData(data.Pass());
72 CompleteSendFeedback();
75 void FeedbackService::ScreenshotCallback(scoped_ptr<std::string> data) {
77 feedback_data_->set_screenshot_uuid(std::string());
79 feedback_data_->set_image(data.Pass());
81 CompleteSendFeedback();
84 void FeedbackService::CompleteSendFeedback() {
85 // A particular data collection is considered completed if,
86 // a.) The blob URL is invalid - this will either happen because we never had
87 // a URL and never needed to read this data, or that the data read failed
88 // and we set it to invalid in the data read callback.
89 // b.) The associated data object exists, meaning that the data has been read
90 // and the read callback has updated the associated data on the feedback
92 bool attached_file_completed =
93 feedback_data_->attached_file_uuid().empty() ||
94 feedback_data_->attached_filedata();
95 bool screenshot_completed =
96 feedback_data_->screenshot_uuid().empty() ||
97 feedback_data_->image();
99 if (screenshot_completed && attached_file_completed) {
100 // Signal the feedback object that the data from the feedback page has been
101 // filled - the object will manage sending of the actual report.
102 feedback_data_->OnFeedbackPageDataComplete();
103 // TODO(rkc): Change this once we have FeedbackData/Util refactored to
104 // report the status of the report being sent.
105 send_feedback_callback_.Run(true);
109 } // namespace extensions