OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/api/feedback_private/feedback_service.h" | 5 #include "chrome/browser/extensions/api/feedback_private/feedback_service.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/common/chrome_content_client.h" | 14 #include "chrome/common/chrome_content_client.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 | 16 |
17 using content::BrowserThread; | 17 using content::BrowserThread; |
18 using feedback::FeedbackData; | 18 using feedback::FeedbackData; |
19 | 19 |
| 20 namespace extensions { |
| 21 |
20 namespace { | 22 namespace { |
21 | 23 |
22 void PopulateSystemInfo( | 24 void PopulateSystemInfo(SystemInformationList* sys_info_list, |
23 extensions::SystemInformationList* sys_info_list, | 25 const std::string& key, |
24 const std::string& key, | 26 const std::string& value) { |
25 const std::string& value) { | |
26 base::DictionaryValue sys_info_value; | 27 base::DictionaryValue sys_info_value; |
27 sys_info_value.Set("key", new base::StringValue(key)); | 28 sys_info_value.Set("key", new base::StringValue(key)); |
28 sys_info_value.Set("value", new base::StringValue(value)); | 29 sys_info_value.Set("value", new base::StringValue(value)); |
29 | 30 |
30 linked_ptr<SystemInformation> sys_info(new SystemInformation()); | 31 linked_ptr<SystemInformation> sys_info(new SystemInformation()); |
31 SystemInformation::Populate(sys_info_value, sys_info.get()); | 32 SystemInformation::Populate(sys_info_value, sys_info.get()); |
32 | 33 |
33 sys_info_list->push_back(sys_info); | 34 sys_info_list->push_back(sys_info); |
34 } | 35 } |
35 | 36 |
36 } // namespace | 37 } // namespace |
37 | 38 |
38 namespace extensions { | |
39 | |
40 FeedbackService::FeedbackService() { | 39 FeedbackService::FeedbackService() { |
41 } | 40 } |
42 | 41 |
43 FeedbackService::~FeedbackService() { | 42 FeedbackService::~FeedbackService() { |
44 } | 43 } |
45 | 44 |
46 void FeedbackService::SendFeedback( | 45 void FeedbackService::SendFeedback( |
47 Profile* profile, | 46 Profile* profile, |
48 scoped_refptr<FeedbackData> feedback_data, | 47 scoped_refptr<FeedbackData> feedback_data, |
49 const SendFeedbackCallback& callback) { | 48 const SendFeedbackCallback& callback) { |
50 send_feedback_callback_ = callback; | 49 feedback_data->set_locale(g_browser_process->GetApplicationLocale()); |
51 feedback_data_ = feedback_data; | 50 feedback_data->set_user_agent(GetUserAgent()); |
52 feedback_data_->set_locale(g_browser_process->GetApplicationLocale()); | |
53 feedback_data_->set_user_agent(GetUserAgent()); | |
54 | 51 |
55 if (!feedback_data_->attached_file_uuid().empty()) { | 52 if (!feedback_data->attached_file_uuid().empty()) { |
56 // Self-deleting object. | 53 // Self-deleting object. |
57 BlobReader* attached_file_reader = new BlobReader( | 54 BlobReader* attached_file_reader = |
58 profile, feedback_data_->attached_file_uuid(), | 55 new BlobReader(profile, feedback_data->attached_file_uuid(), |
59 base::Bind(&FeedbackService::AttachedFileCallback, AsWeakPtr())); | 56 base::Bind(&FeedbackService::AttachedFileCallback, |
| 57 AsWeakPtr(), feedback_data, callback)); |
60 attached_file_reader->Start(); | 58 attached_file_reader->Start(); |
61 } | 59 } |
62 | 60 |
63 if (!feedback_data_->screenshot_uuid().empty()) { | 61 if (!feedback_data->screenshot_uuid().empty()) { |
64 // Self-deleting object. | 62 // Self-deleting object. |
65 BlobReader* screenshot_reader = new BlobReader( | 63 BlobReader* screenshot_reader = |
66 profile, feedback_data_->screenshot_uuid(), | 64 new BlobReader(profile, feedback_data->screenshot_uuid(), |
67 base::Bind(&FeedbackService::ScreenshotCallback, AsWeakPtr())); | 65 base::Bind(&FeedbackService::ScreenshotCallback, |
| 66 AsWeakPtr(), feedback_data, callback)); |
68 screenshot_reader->Start(); | 67 screenshot_reader->Start(); |
69 } | 68 } |
70 | 69 |
71 CompleteSendFeedback(); | 70 CompleteSendFeedback(feedback_data, callback); |
72 } | |
73 | |
74 void FeedbackService::AttachedFileCallback(scoped_ptr<std::string> data, | |
75 int64_t /* total_blob_length */) { | |
76 feedback_data_->set_attached_file_uuid(std::string()); | |
77 if (data) | |
78 feedback_data_->AttachAndCompressFileData(std::move(data)); | |
79 | |
80 CompleteSendFeedback(); | |
81 } | |
82 | |
83 void FeedbackService::ScreenshotCallback(scoped_ptr<std::string> data, | |
84 int64_t /* total_blob_length */) { | |
85 feedback_data_->set_screenshot_uuid(std::string()); | |
86 if (data) | |
87 feedback_data_->set_image(std::move(data)); | |
88 | |
89 CompleteSendFeedback(); | |
90 } | 71 } |
91 | 72 |
92 void FeedbackService::GetSystemInformation( | 73 void FeedbackService::GetSystemInformation( |
93 const GetSystemInformationCallback& callback) { | 74 const GetSystemInformationCallback& callback) { |
94 system_information_callback_ = callback; | |
95 | |
96 system_logs::ScrubbedSystemLogsFetcher* fetcher = | 75 system_logs::ScrubbedSystemLogsFetcher* fetcher = |
97 new system_logs::ScrubbedSystemLogsFetcher(); | 76 new system_logs::ScrubbedSystemLogsFetcher(); |
98 fetcher->Fetch( | 77 fetcher->Fetch(base::Bind(&FeedbackService::OnSystemLogsFetchComplete, |
99 base::Bind(&FeedbackService::OnSystemLogsFetchComplete, AsWeakPtr())); | 78 AsWeakPtr(), callback)); |
100 } | 79 } |
101 | 80 |
| 81 void FeedbackService::AttachedFileCallback( |
| 82 scoped_refptr<feedback::FeedbackData> feedback_data, |
| 83 const SendFeedbackCallback& callback, |
| 84 scoped_ptr<std::string> data, |
| 85 int64_t /* total_blob_length */) { |
| 86 feedback_data->set_attached_file_uuid(std::string()); |
| 87 if (data) |
| 88 feedback_data->AttachAndCompressFileData(std::move(data)); |
| 89 |
| 90 CompleteSendFeedback(feedback_data, callback); |
| 91 } |
| 92 |
| 93 void FeedbackService::ScreenshotCallback( |
| 94 scoped_refptr<feedback::FeedbackData> feedback_data, |
| 95 const SendFeedbackCallback& callback, |
| 96 scoped_ptr<std::string> data, |
| 97 int64_t /* total_blob_length */) { |
| 98 feedback_data->set_screenshot_uuid(std::string()); |
| 99 if (data) |
| 100 feedback_data->set_image(std::move(data)); |
| 101 |
| 102 CompleteSendFeedback(feedback_data, callback); |
| 103 } |
102 | 104 |
103 void FeedbackService::OnSystemLogsFetchComplete( | 105 void FeedbackService::OnSystemLogsFetchComplete( |
| 106 const GetSystemInformationCallback& callback, |
104 scoped_ptr<system_logs::SystemLogsResponse> sys_info_map) { | 107 scoped_ptr<system_logs::SystemLogsResponse> sys_info_map) { |
105 SystemInformationList sys_info_list; | 108 SystemInformationList sys_info_list; |
106 if (!sys_info_map.get()) { | 109 if (sys_info_map.get()) { |
107 system_information_callback_.Run(sys_info_list); | 110 for (const auto& itr : *sys_info_map) |
108 return; | 111 PopulateSystemInfo(&sys_info_list, itr.first, itr.second); |
109 } | 112 } |
110 | 113 |
111 for (system_logs::SystemLogsResponse::iterator it = sys_info_map->begin(); | 114 callback.Run(sys_info_list); |
112 it != sys_info_map->end(); ++it) | |
113 PopulateSystemInfo(&sys_info_list, it->first, it->second); | |
114 | |
115 system_information_callback_.Run(sys_info_list); | |
116 } | 115 } |
117 | 116 |
118 void FeedbackService::CompleteSendFeedback() { | 117 void FeedbackService::CompleteSendFeedback( |
| 118 scoped_refptr<feedback::FeedbackData> feedback_data, |
| 119 const SendFeedbackCallback& callback) { |
119 // A particular data collection is considered completed if, | 120 // A particular data collection is considered completed if, |
120 // a.) The blob URL is invalid - this will either happen because we never had | 121 // a.) The blob URL is invalid - this will either happen because we never had |
121 // a URL and never needed to read this data, or that the data read failed | 122 // a URL and never needed to read this data, or that the data read failed |
122 // and we set it to invalid in the data read callback. | 123 // and we set it to invalid in the data read callback. |
123 // b.) The associated data object exists, meaning that the data has been read | 124 // b.) The associated data object exists, meaning that the data has been read |
124 // and the read callback has updated the associated data on the feedback | 125 // and the read callback has updated the associated data on the feedback |
125 // object. | 126 // object. |
126 bool attached_file_completed = feedback_data_->attached_file_uuid().empty(); | 127 const bool attached_file_completed = |
127 bool screenshot_completed = feedback_data_->screenshot_uuid().empty(); | 128 feedback_data->attached_file_uuid().empty(); |
| 129 const bool screenshot_completed = feedback_data->screenshot_uuid().empty(); |
128 | 130 |
129 if (screenshot_completed && attached_file_completed) { | 131 if (screenshot_completed && attached_file_completed) { |
130 // Signal the feedback object that the data from the feedback page has been | 132 // Signal the feedback object that the data from the feedback page has been |
131 // filled - the object will manage sending of the actual report. | 133 // filled - the object will manage sending of the actual report. |
132 feedback_data_->OnFeedbackPageDataComplete(); | 134 feedback_data->OnFeedbackPageDataComplete(); |
| 135 |
133 // TODO(rkc): Change this once we have FeedbackData/Util refactored to | 136 // TODO(rkc): Change this once we have FeedbackData/Util refactored to |
134 // report the status of the report being sent. | 137 // report the status of the report being sent. |
135 send_feedback_callback_.Run(true); | 138 callback.Run(true); |
136 } | 139 } |
137 } | 140 } |
138 | 141 |
139 } // namespace extensions | 142 } // namespace extensions |
OLD | NEW |