| 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 #include "net/base/network_change_notifier.h" | 16 #include "net/base/network_change_notifier.h" |
| 17 | 17 |
| 18 using content::BrowserThread; | 18 using content::BrowserThread; |
| 19 using extensions::api::feedback_private::SystemInformation; | |
| 20 using feedback::FeedbackData; | 19 using feedback::FeedbackData; |
| 21 | 20 |
| 22 namespace extensions { | 21 namespace extensions { |
| 23 | 22 |
| 24 namespace { | |
| 25 | |
| 26 void PopulateSystemInfo(SystemInformationList* sys_info_list, | |
| 27 const std::string& key, | |
| 28 const std::string& value) { | |
| 29 base::DictionaryValue sys_info_value; | |
| 30 sys_info_value.Set("key", new base::StringValue(key)); | |
| 31 sys_info_value.Set("value", new base::StringValue(value)); | |
| 32 | |
| 33 SystemInformation sys_info; | |
| 34 SystemInformation::Populate(sys_info_value, &sys_info); | |
| 35 | |
| 36 sys_info_list->push_back(std::move(sys_info)); | |
| 37 } | |
| 38 | |
| 39 } // namespace | |
| 40 | |
| 41 FeedbackService::FeedbackService() { | 23 FeedbackService::FeedbackService() { |
| 42 } | 24 } |
| 43 | 25 |
| 44 FeedbackService::~FeedbackService() { | 26 FeedbackService::~FeedbackService() { |
| 45 } | 27 } |
| 46 | 28 |
| 47 void FeedbackService::SendFeedback( | 29 void FeedbackService::SendFeedback( |
| 48 Profile* profile, | 30 Profile* profile, |
| 49 scoped_refptr<FeedbackData> feedback_data, | 31 scoped_refptr<FeedbackData> feedback_data, |
| 50 const SendFeedbackCallback& callback) { | 32 const SendFeedbackCallback& callback) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 66 new BlobReader(profile, feedback_data->screenshot_uuid(), | 48 new BlobReader(profile, feedback_data->screenshot_uuid(), |
| 67 base::Bind(&FeedbackService::ScreenshotCallback, | 49 base::Bind(&FeedbackService::ScreenshotCallback, |
| 68 AsWeakPtr(), feedback_data, callback)); | 50 AsWeakPtr(), feedback_data, callback)); |
| 69 screenshot_reader->Start(); | 51 screenshot_reader->Start(); |
| 70 } | 52 } |
| 71 | 53 |
| 72 CompleteSendFeedback(feedback_data, callback); | 54 CompleteSendFeedback(feedback_data, callback); |
| 73 } | 55 } |
| 74 | 56 |
| 75 void FeedbackService::GetSystemInformation( | 57 void FeedbackService::GetSystemInformation( |
| 76 const GetSystemInformationCallback& callback) { | 58 const system_logs::SysLogsFetcherCallback& callback) { |
| 77 system_logs::ScrubbedSystemLogsFetcher* fetcher = | 59 system_logs::ScrubbedSystemLogsFetcher* fetcher = |
| 78 new system_logs::ScrubbedSystemLogsFetcher(); | 60 new system_logs::ScrubbedSystemLogsFetcher(); |
| 79 fetcher->Fetch(base::Bind(&FeedbackService::OnSystemLogsFetchComplete, | 61 fetcher->Fetch(callback); |
| 80 AsWeakPtr(), callback)); | |
| 81 } | 62 } |
| 82 | 63 |
| 83 void FeedbackService::AttachedFileCallback( | 64 void FeedbackService::AttachedFileCallback( |
| 84 scoped_refptr<feedback::FeedbackData> feedback_data, | 65 scoped_refptr<feedback::FeedbackData> feedback_data, |
| 85 const SendFeedbackCallback& callback, | 66 const SendFeedbackCallback& callback, |
| 86 std::unique_ptr<std::string> data, | 67 std::unique_ptr<std::string> data, |
| 87 int64_t /* total_blob_length */) { | 68 int64_t /* total_blob_length */) { |
| 88 feedback_data->set_attached_file_uuid(std::string()); | 69 feedback_data->set_attached_file_uuid(std::string()); |
| 89 if (data) | 70 if (data) |
| 90 feedback_data->AttachAndCompressFileData(std::move(data)); | 71 feedback_data->AttachAndCompressFileData(std::move(data)); |
| 91 | 72 |
| 92 CompleteSendFeedback(feedback_data, callback); | 73 CompleteSendFeedback(feedback_data, callback); |
| 93 } | 74 } |
| 94 | 75 |
| 95 void FeedbackService::ScreenshotCallback( | 76 void FeedbackService::ScreenshotCallback( |
| 96 scoped_refptr<feedback::FeedbackData> feedback_data, | 77 scoped_refptr<feedback::FeedbackData> feedback_data, |
| 97 const SendFeedbackCallback& callback, | 78 const SendFeedbackCallback& callback, |
| 98 std::unique_ptr<std::string> data, | 79 std::unique_ptr<std::string> data, |
| 99 int64_t /* total_blob_length */) { | 80 int64_t /* total_blob_length */) { |
| 100 feedback_data->set_screenshot_uuid(std::string()); | 81 feedback_data->set_screenshot_uuid(std::string()); |
| 101 if (data) | 82 if (data) |
| 102 feedback_data->set_image(std::move(data)); | 83 feedback_data->set_image(std::move(data)); |
| 103 | 84 |
| 104 CompleteSendFeedback(feedback_data, callback); | 85 CompleteSendFeedback(feedback_data, callback); |
| 105 } | 86 } |
| 106 | 87 |
| 107 void FeedbackService::OnSystemLogsFetchComplete( | |
| 108 const GetSystemInformationCallback& callback, | |
| 109 std::unique_ptr<system_logs::SystemLogsResponse> sys_info_map) { | |
| 110 SystemInformationList sys_info_list; | |
| 111 if (sys_info_map.get()) { | |
| 112 for (const auto& itr : *sys_info_map) | |
| 113 PopulateSystemInfo(&sys_info_list, itr.first, itr.second); | |
| 114 } | |
| 115 | |
| 116 callback.Run(sys_info_list); | |
| 117 } | |
| 118 | |
| 119 void FeedbackService::CompleteSendFeedback( | 88 void FeedbackService::CompleteSendFeedback( |
| 120 scoped_refptr<feedback::FeedbackData> feedback_data, | 89 scoped_refptr<feedback::FeedbackData> feedback_data, |
| 121 const SendFeedbackCallback& callback) { | 90 const SendFeedbackCallback& callback) { |
| 122 // A particular data collection is considered completed if, | 91 // A particular data collection is considered completed if, |
| 123 // a.) The blob URL is invalid - this will either happen because we never had | 92 // a.) The blob URL is invalid - this will either happen because we never had |
| 124 // a URL and never needed to read this data, or that the data read failed | 93 // a URL and never needed to read this data, or that the data read failed |
| 125 // and we set it to invalid in the data read callback. | 94 // and we set it to invalid in the data read callback. |
| 126 // b.) The associated data object exists, meaning that the data has been read | 95 // b.) The associated data object exists, meaning that the data has been read |
| 127 // and the read callback has updated the associated data on the feedback | 96 // and the read callback has updated the associated data on the feedback |
| 128 // object. | 97 // object. |
| 129 const bool attached_file_completed = | 98 const bool attached_file_completed = |
| 130 feedback_data->attached_file_uuid().empty(); | 99 feedback_data->attached_file_uuid().empty(); |
| 131 const bool screenshot_completed = feedback_data->screenshot_uuid().empty(); | 100 const bool screenshot_completed = feedback_data->screenshot_uuid().empty(); |
| 132 | 101 |
| 133 if (screenshot_completed && attached_file_completed) { | 102 if (screenshot_completed && attached_file_completed) { |
| 134 // Signal the feedback object that the data from the feedback page has been | 103 // Signal the feedback object that the data from the feedback page has been |
| 135 // filled - the object will manage sending of the actual report. | 104 // filled - the object will manage sending of the actual report. |
| 136 feedback_data->OnFeedbackPageDataComplete(); | 105 feedback_data->OnFeedbackPageDataComplete(); |
| 137 | 106 |
| 138 // Sending the feedback will be delayed if the user is offline. | 107 // Sending the feedback will be delayed if the user is offline. |
| 139 const bool result = !net::NetworkChangeNotifier::IsOffline(); | 108 const bool result = !net::NetworkChangeNotifier::IsOffline(); |
| 140 | 109 |
| 141 // TODO(rkc): Change this once we have FeedbackData/Util refactored to | 110 // TODO(rkc): Change this once we have FeedbackData/Util refactored to |
| 142 // report the status of the report being sent. | 111 // report the status of the report being sent. |
| 143 callback.Run(result); | 112 callback.Run(result); |
| 144 } | 113 } |
| 145 } | 114 } |
| 146 | 115 |
| 147 } // namespace extensions | 116 } // namespace extensions |
| OLD | NEW |