Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/feedback/feedback_util.h" | 5 #include "components/feedback/feedback_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 const char kArbitraryMimeType[] = "application/octet-stream"; | 25 const char kArbitraryMimeType[] = "application/octet-stream"; |
| 26 const char kHistogramsAttachmentName[] = "histograms.zip"; | 26 const char kHistogramsAttachmentName[] = "histograms.zip"; |
| 27 const char kLogsAttachmentName[] = "system_logs.zip"; | 27 const char kLogsAttachmentName[] = "system_logs.zip"; |
| 28 | 28 |
| 29 #if defined(OS_CHROMEOS) | 29 #if defined(OS_CHROMEOS) |
| 30 const int kChromeOSProductId = 208; | 30 const int kChromeOSProductId = 208; |
| 31 #else | 31 #else |
| 32 const int kChromeBrowserProductId = 237; | 32 const int kChromeBrowserProductId = 237; |
| 33 #endif | 33 #endif |
| 34 | 34 |
| 35 void AddFeedbackData(userfeedback::ExtensionSubmit* feedback_data, | |
| 36 const std::string& key, const std::string& value) { | |
| 37 // Don't bother with empty keys or values | |
| 38 if (key == "" || value == "") return; | |
| 39 // Create log_value object and add it to the web_data object | |
| 40 userfeedback::ProductSpecificData log_value; | |
| 41 log_value.set_key(key); | |
| 42 log_value.set_value(value); | |
| 43 userfeedback::WebData* web_data = feedback_data->mutable_web_data(); | |
| 44 *(web_data->add_product_specific_data()) = log_value; | |
| 45 } | |
| 46 | |
| 47 // Adds data as an attachment to feedback_data if the data is non-empty. | |
| 48 void AddAttachment(userfeedback::ExtensionSubmit* feedback_data, | |
| 49 const char* name, | |
| 50 std::string* data) { | |
| 51 if (data == NULL || data->empty()) | |
| 52 return; | |
| 53 | |
| 54 userfeedback::ProductSpecificBinaryData* attachment = | |
| 55 feedback_data->add_product_specific_binary_data(); | |
| 56 attachment->set_mime_type(kArbitraryMimeType); | |
| 57 attachment->set_name(name); | |
| 58 attachment->set_data(*data); | |
| 59 } | |
| 60 | |
| 61 } // namespace | 35 } // namespace |
| 62 | 36 |
| 63 namespace feedback_util { | 37 namespace feedback_util { |
| 64 | 38 |
| 65 void SendReport(scoped_refptr<FeedbackData> data) { | 39 void SendReport(scoped_refptr<FeedbackData> data) { |
| 66 if (!data.get()) { | 40 if (!data.get()) { |
| 67 LOG(ERROR) << "SendReport called with NULL data!"; | 41 LOG(ERROR) << "SendReport called with NULL data!"; |
| 68 NOTREACHED(); | 42 NOTREACHED(); |
| 69 return; | 43 return; |
| 70 } | 44 } |
| 71 | 45 |
| 72 userfeedback::ExtensionSubmit feedback_data; | 46 userfeedback::ExtensionSubmit feedback_data; |
| 73 // Unused field, needs to be 0 though. | 47 data->PrepareReport(&feedback_data); |
| 74 feedback_data.set_type_id(0); | |
| 75 | |
| 76 userfeedback::CommonData* common_data = feedback_data.mutable_common_data(); | |
| 77 // We're not using gaia ids, we're using the e-mail field instead. | |
| 78 common_data->set_gaia_id(0); | |
| 79 common_data->set_user_email(data->user_email()); | |
| 80 common_data->set_description(data->description()); | |
| 81 common_data->set_source_description_language(data->locale()); | |
| 82 | |
| 83 userfeedback::WebData* web_data = feedback_data.mutable_web_data(); | |
| 84 web_data->set_url(data->page_url()); | |
| 85 web_data->mutable_navigator()->set_user_agent(data->user_agent()); | |
| 86 | |
| 87 if (data->sys_info()) { | |
| 88 for (FeedbackData::SystemLogsMap::const_iterator i = | |
| 89 data->sys_info()->begin(); i != data->sys_info()->end(); ++i) { | |
| 90 if (FeedbackData::BelowCompressionThreshold(i->second)) | |
| 91 AddFeedbackData(&feedback_data, i->first, i->second); | |
| 92 } | |
| 93 | |
| 94 AddAttachment(&feedback_data, kLogsAttachmentName, data->compressed_logs()); | |
| 95 } | |
| 96 | |
| 97 if (data->histograms()) { | |
| 98 AddAttachment(&feedback_data, | |
| 99 kHistogramsAttachmentName, | |
| 100 data->compressed_histograms()); | |
| 101 } | |
| 102 | |
| 103 if (!data->attached_filename().empty()) { | |
| 104 // We need to use the UTF8Unsafe methods here to accomodate Windows, which | |
| 105 // uses wide strings to store filepaths. | |
| 106 std::string name = base::FilePath::FromUTF8Unsafe( | |
| 107 data->attached_filename()).BaseName().AsUTF8Unsafe(); | |
| 108 AddAttachment(&feedback_data, name.c_str(), data->attached_filedata()); | |
| 109 } | |
| 110 | |
| 111 // NOTE: Screenshot needs to be processed after system info since we'll get | |
| 112 // the screenshot dimensions from system info. | |
| 113 if (data->image() && data->image()->size()) { | |
| 114 userfeedback::PostedScreenshot screenshot; | |
| 115 screenshot.set_mime_type(kPngMimeType); | |
| 116 | |
| 117 // Set that we 'have' dimensions of the screenshot. These dimensions are | |
| 118 // ignored by the server but are a 'required' field in the protobuf. | |
| 119 userfeedback::Dimensions dimensions; | |
| 120 dimensions.set_width(0.0); | |
| 121 dimensions.set_height(0.0); | |
| 122 | |
| 123 *(screenshot.mutable_dimensions()) = dimensions; | |
| 124 screenshot.set_binary_content(*data->image()); | |
| 125 | |
| 126 *(feedback_data.mutable_screenshot()) = screenshot; | |
| 127 } | |
| 128 | |
| 129 if (data->category_tag().size()) | |
| 130 feedback_data.set_bucket(data->category_tag()); | |
| 131 | 48 |
| 132 // Set whether we're reporting from ChromeOS or Chrome on another platform. | 49 // Set whether we're reporting from ChromeOS or Chrome on another platform. |
| 133 userfeedback::ChromeData chrome_data; | 50 userfeedback::ChromeData chrome_data; |
| 134 #if defined(OS_CHROMEOS) | 51 #if defined(OS_CHROMEOS) |
| 135 chrome_data.set_chrome_platform( | 52 chrome_data.set_chrome_platform( |
| 136 userfeedback::ChromeData_ChromePlatform_CHROME_OS); | 53 userfeedback::ChromeData_ChromePlatform_CHROME_OS); |
| 137 userfeedback::ChromeOsData chrome_os_data; | 54 userfeedback::ChromeOsData chrome_os_data; |
| 138 chrome_os_data.set_category( | 55 chrome_os_data.set_category( |
| 139 userfeedback::ChromeOsData_ChromeOsCategory_OTHER); | 56 userfeedback::ChromeOsData_ChromeOsCategory_OTHER); |
| 140 *(chrome_data.mutable_chrome_os_data()) = chrome_os_data; | 57 *(chrome_data.mutable_chrome_os_data()) = chrome_os_data; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 return false; | 92 return false; |
| 176 | 93 |
| 177 bool succeed = base::CreateTemporaryFile(&zip_file) && | 94 bool succeed = base::CreateTemporaryFile(&zip_file) && |
| 178 zip::Zip(temp_path, zip_file, false) && | 95 zip::Zip(temp_path, zip_file, false) && |
| 179 base::ReadFileToString(zip_file, compressed_logs); | 96 base::ReadFileToString(zip_file, compressed_logs); |
| 180 | 97 |
| 181 base::DeleteFile(temp_path, true); | 98 base::DeleteFile(temp_path, true); |
| 182 base::DeleteFile(zip_file, false); | 99 base::DeleteFile(zip_file, false); |
| 183 | 100 |
| 184 return succeed; | 101 return succeed; |
| 185 } | 102 } // feedback_util |
|
Zachary Kuznia
2014/05/28 21:39:36
This comment is wrong.
achaulk
2014/05/29 17:22:29
Done.
| |
| 186 | 103 |
| 187 } // namespace feedback_util | 104 } // namespace feedback_util |
| OLD | NEW |