OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/feedback/feedback_util.h" | 5 #include "chrome/browser/feedback/feedback_util.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 const int kHttpPostSuccessNoContent = 204; | 85 const int kHttpPostSuccessNoContent = 204; |
86 const int kHttpPostFailNoConnection = -1; | 86 const int kHttpPostFailNoConnection = -1; |
87 const int kHttpPostFailClientError = 400; | 87 const int kHttpPostFailClientError = 400; |
88 const int kHttpPostFailServerError = 500; | 88 const int kHttpPostFailServerError = 500; |
89 | 89 |
90 const int64 kInitialRetryDelay = 900000; // 15 minutes | 90 const int64 kInitialRetryDelay = 900000; // 15 minutes |
91 const int64 kRetryDelayIncreaseFactor = 2; | 91 const int64 kRetryDelayIncreaseFactor = 2; |
92 const int64 kRetryDelayLimit = 14400000; // 4 hours | 92 const int64 kRetryDelayLimit = 14400000; // 4 hours |
93 | 93 |
94 const char kArbitraryMimeType[] = "application/octet-stream"; | 94 const char kArbitraryMimeType[] = "application/octet-stream"; |
95 const char kHistogramsAttachmentName[] = "histograms.zip"; | |
95 const char kLogsAttachmentName[] = "system_logs.zip"; | 96 const char kLogsAttachmentName[] = "system_logs.zip"; |
96 | 97 |
97 #if defined(OS_CHROMEOS) | 98 #if defined(OS_CHROMEOS) |
98 const int kChromeOSProductId = 208; | 99 const int kChromeOSProductId = 208; |
99 #else | 100 #else |
100 const int kChromeBrowserProductId = 237; | 101 const int kChromeBrowserProductId = 237; |
101 #endif | 102 #endif |
102 | 103 |
103 // Simple net::URLFetcherDelegate to clean up URLFetcher on completion. | 104 // Simple net::URLFetcherDelegate to clean up URLFetcher on completion. |
104 class PostCleanup : public net::URLFetcherDelegate { | 105 class PostCleanup : public net::URLFetcherDelegate { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 // Don't bother with empty keys or values | 211 // Don't bother with empty keys or values |
211 if (key == "" || value == "") return; | 212 if (key == "" || value == "") return; |
212 // Create log_value object and add it to the web_data object | 213 // Create log_value object and add it to the web_data object |
213 userfeedback::ProductSpecificData log_value; | 214 userfeedback::ProductSpecificData log_value; |
214 log_value.set_key(key); | 215 log_value.set_key(key); |
215 log_value.set_value(value); | 216 log_value.set_value(value); |
216 userfeedback::WebData* web_data = feedback_data->mutable_web_data(); | 217 userfeedback::WebData* web_data = feedback_data->mutable_web_data(); |
217 *(web_data->add_product_specific_data()) = log_value; | 218 *(web_data->add_product_specific_data()) = log_value; |
218 } | 219 } |
219 | 220 |
221 // Adds data as an attachment to feedback_data if the data is non-empty. | |
222 void AddAttachment(userfeedback::ExtensionSubmit* feedback_data, | |
223 const char* name, | |
224 std::string* data) { | |
225 if (data == NULL || data->empty()) | |
226 return; | |
227 | |
228 userfeedback::ProductSpecificBinaryData attachment; | |
229 attachment.set_mime_type(kArbitraryMimeType); | |
230 attachment.set_name(name); | |
231 attachment.set_data(*data); | |
232 *(feedback_data->add_product_specific_binary_data()) = attachment; | |
Alexei Svitkine (slow)
2013/11/02 00:05:26
Nit: Why not:
userfeedback::ProductSpecificBinary
michaelpg
2013/11/02 17:39:09
I'm not familiar with protobuf. It looks like Repe
Alexei Svitkine (slow)
2013/11/04 15:26:40
I don't think your statement is correct (that it's
michaelpg
2013/11/04 17:25:18
You're right, I was thinking a RepeatedField rathe
| |
233 } | |
234 | |
220 } // namespace | 235 } // namespace |
221 | 236 |
222 namespace chrome { | 237 namespace chrome { |
223 | 238 |
224 const char kAppLauncherCategoryTag[] = "AppLauncher"; | 239 const char kAppLauncherCategoryTag[] = "AppLauncher"; |
225 | 240 |
226 void ShowFeedbackPage(Browser* browser, | 241 void ShowFeedbackPage(Browser* browser, |
227 const std::string& description_template, | 242 const std::string& description_template, |
228 const std::string& category_tag) { | 243 const std::string& category_tag) { |
229 GURL page_url; | 244 GURL page_url; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 web_data->mutable_navigator()->set_user_agent(content::GetUserAgent(GURL())); | 296 web_data->mutable_navigator()->set_user_agent(content::GetUserAgent(GURL())); |
282 | 297 |
283 gfx::Rect screen_size; | 298 gfx::Rect screen_size; |
284 if (data->sys_info()) { | 299 if (data->sys_info()) { |
285 for (FeedbackData::SystemLogsMap::const_iterator i = | 300 for (FeedbackData::SystemLogsMap::const_iterator i = |
286 data->sys_info()->begin(); i != data->sys_info()->end(); ++i) { | 301 data->sys_info()->begin(); i != data->sys_info()->end(); ++i) { |
287 if (FeedbackData::BelowCompressionThreshold(i->second)) | 302 if (FeedbackData::BelowCompressionThreshold(i->second)) |
288 AddFeedbackData(&feedback_data, i->first, i->second); | 303 AddFeedbackData(&feedback_data, i->first, i->second); |
289 } | 304 } |
290 | 305 |
291 if (data->compressed_logs() && data->compressed_logs()->size()) { | 306 AddAttachment(&feedback_data, kLogsAttachmentName, data->compressed_logs()); |
292 userfeedback::ProductSpecificBinaryData attachment; | |
293 attachment.set_mime_type(kArbitraryMimeType); | |
294 attachment.set_name(kLogsAttachmentName); | |
295 attachment.set_data(*(data->compressed_logs())); | |
296 *(feedback_data.add_product_specific_binary_data()) = attachment; | |
297 } | |
298 } | 307 } |
299 | 308 |
300 if (!data->attached_filename().empty() && | 309 if (data->histograms()) { |
301 data->attached_filedata() && | 310 AddAttachment(&feedback_data, |
302 !data->attached_filedata()->empty()) { | 311 kHistogramsAttachmentName, |
303 userfeedback::ProductSpecificBinaryData attached_file; | 312 data->compressed_histograms()); |
304 attached_file.set_mime_type(kArbitraryMimeType); | 313 } |
314 | |
315 if (!data->attached_filename().empty()) { | |
305 // We need to use the UTF8Unsafe methods here to accomodate Windows, which | 316 // We need to use the UTF8Unsafe methods here to accomodate Windows, which |
306 // uses wide strings to store filepaths. | 317 // uses wide strings to store filepaths. |
307 std::string name = base::FilePath::FromUTF8Unsafe( | 318 std::string name = base::FilePath::FromUTF8Unsafe( |
308 data->attached_filename()).BaseName().AsUTF8Unsafe(); | 319 data->attached_filename()).BaseName().AsUTF8Unsafe(); |
309 attached_file.set_name(name); | 320 AddAttachment(&feedback_data, name.c_str(), data->attached_filedata()); |
310 attached_file.set_data(*data->attached_filedata()); | |
311 *(feedback_data.add_product_specific_binary_data()) = attached_file; | |
312 } | 321 } |
313 | 322 |
314 // NOTE: Screenshot needs to be processed after system info since we'll get | 323 // NOTE: Screenshot needs to be processed after system info since we'll get |
315 // the screenshot dimensions from system info. | 324 // the screenshot dimensions from system info. |
316 if (data->image() && data->image()->size()) { | 325 if (data->image() && data->image()->size()) { |
317 userfeedback::PostedScreenshot screenshot; | 326 userfeedback::PostedScreenshot screenshot; |
318 screenshot.set_mime_type(kPngMimeType); | 327 screenshot.set_mime_type(kPngMimeType); |
319 | 328 |
320 // Set that we 'have' dimensions of the screenshot. These dimensions are | 329 // Set that we 'have' dimensions of the screenshot. These dimensions are |
321 // ignored by the server but are a 'required' field in the protobuf. | 330 // ignored by the server but are a 'required' field in the protobuf. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
380 if (!zip::Zip(temp_path, zip_file, false)) | 389 if (!zip::Zip(temp_path, zip_file, false)) |
381 return false; | 390 return false; |
382 | 391 |
383 if (!base::ReadFileToString(zip_file, compressed_logs)) | 392 if (!base::ReadFileToString(zip_file, compressed_logs)) |
384 return false; | 393 return false; |
385 | 394 |
386 return true; | 395 return true; |
387 } | 396 } |
388 | 397 |
389 } // namespace feedback_util | 398 } // namespace feedback_util |
OLD | NEW |