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" |
11 #include "components/feedback/feedback_data.h" | 11 #include "components/feedback/feedback_data.h" |
12 #include "components/feedback/feedback_uploader.h" | 12 #include "components/feedback/feedback_uploader.h" |
13 #include "components/feedback/feedback_uploader_factory.h" | 13 #include "components/feedback/feedback_uploader_factory.h" |
14 #include "components/feedback/proto/common.pb.h" | 14 #include "components/feedback/proto/common.pb.h" |
15 #include "components/feedback/proto/dom.pb.h" | 15 #include "components/feedback/proto/dom.pb.h" |
16 #include "components/feedback/proto/extension.pb.h" | 16 #include "components/feedback/proto/extension.pb.h" |
17 #include "components/feedback/proto/math.pb.h" | 17 #include "components/feedback/proto/math.pb.h" |
18 #include "third_party/zlib/google/zip.h" | 18 #include "third_party/zlib/google/zip.h" |
19 | 19 |
20 using feedback::FeedbackData; | 20 using feedback::FeedbackData; |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 const char kPngMimeType[] = "image/png"; | |
25 const char kArbitraryMimeType[] = "application/octet-stream"; | |
26 const char kHistogramsAttachmentName[] = "histograms.zip"; | |
27 const char kLogsAttachmentName[] = "system_logs.zip"; | |
28 | |
29 #if defined(OS_CHROMEOS) | 24 #if defined(OS_CHROMEOS) |
30 const int kChromeOSProductId = 208; | 25 const int kChromeOSProductId = 208; |
31 #else | 26 #else |
32 const int kChromeBrowserProductId = 237; | 27 const int kChromeBrowserProductId = 237; |
33 #endif | 28 #endif |
34 | 29 |
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 | 30 } // namespace |
62 | 31 |
63 namespace feedback_util { | 32 namespace feedback_util { |
64 | 33 |
65 void SendReport(scoped_refptr<FeedbackData> data) { | 34 void SendReport(scoped_refptr<FeedbackData> data) { |
66 if (!data.get()) { | 35 if (!data.get()) { |
67 LOG(ERROR) << "SendReport called with NULL data!"; | 36 LOG(ERROR) << "SendReport called with NULL data!"; |
68 NOTREACHED(); | 37 NOTREACHED(); |
69 return; | 38 return; |
70 } | 39 } |
71 | 40 |
72 userfeedback::ExtensionSubmit feedback_data; | 41 userfeedback::ExtensionSubmit feedback_data; |
73 // Unused field, needs to be 0 though. | 42 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 | 43 |
132 // Set whether we're reporting from ChromeOS or Chrome on another platform. | 44 // Set whether we're reporting from ChromeOS or Chrome on another platform. |
133 userfeedback::ChromeData chrome_data; | 45 userfeedback::ChromeData chrome_data; |
134 #if defined(OS_CHROMEOS) | 46 #if defined(OS_CHROMEOS) |
135 chrome_data.set_chrome_platform( | 47 chrome_data.set_chrome_platform( |
136 userfeedback::ChromeData_ChromePlatform_CHROME_OS); | 48 userfeedback::ChromeData_ChromePlatform_CHROME_OS); |
137 userfeedback::ChromeOsData chrome_os_data; | 49 userfeedback::ChromeOsData chrome_os_data; |
138 chrome_os_data.set_category( | 50 chrome_os_data.set_category( |
139 userfeedback::ChromeOsData_ChromeOsCategory_OTHER); | 51 userfeedback::ChromeOsData_ChromeOsCategory_OTHER); |
140 *(chrome_data.mutable_chrome_os_data()) = chrome_os_data; | 52 *(chrome_data.mutable_chrome_os_data()) = chrome_os_data; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 zip::Zip(temp_path, zip_file, false) && | 90 zip::Zip(temp_path, zip_file, false) && |
179 base::ReadFileToString(zip_file, compressed_logs); | 91 base::ReadFileToString(zip_file, compressed_logs); |
180 | 92 |
181 base::DeleteFile(temp_path, true); | 93 base::DeleteFile(temp_path, true); |
182 base::DeleteFile(zip_file, false); | 94 base::DeleteFile(zip_file, false); |
183 | 95 |
184 return succeed; | 96 return succeed; |
185 } | 97 } |
186 | 98 |
187 } // namespace feedback_util | 99 } // namespace feedback_util |
OLD | NEW |