Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: components/feedback/feedback_common.cc

Issue 2242833003: Add the most recent crash report IDs to feedback reports (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: RFR Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_common.h" 5 #include "components/feedback/feedback_common.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "components/feedback/feedback_util.h" 11 #include "components/feedback/feedback_util.h"
12 #include "components/feedback/proto/common.pb.h" 12 #include "components/feedback/proto/common.pb.h"
13 #include "components/feedback/proto/dom.pb.h" 13 #include "components/feedback/proto/dom.pb.h"
14 #include "components/feedback/proto/extension.pb.h" 14 #include "components/feedback/proto/extension.pb.h"
15 #include "components/feedback/proto/math.pb.h" 15 #include "components/feedback/proto/math.pb.h"
16 16
17 namespace { 17 namespace {
18 18
19 #if defined(OS_CHROMEOS) 19 #if defined(OS_CHROMEOS)
20 constexpr int kChromeOSProductId = 208; 20 constexpr int kChromeOSProductId = 208;
21 #else 21 #else
22 constexpr int kChromeBrowserProductId = 237; 22 constexpr int kChromeBrowserProductId = 237;
23 #endif 23 #endif
24 24
25 const char kMultilineIndicatorString[] = "<multiline>\n"; 25 constexpr char kMultilineIndicatorString[] = "<multiline>\n";
26 const char kMultilineStartString[] = "---------- START ----------\n"; 26 constexpr char kMultilineStartString[] = "---------- START ----------\n";
27 const char kMultilineEndString[] = "---------- END ----------\n\n"; 27 constexpr char kMultilineEndString[] = "---------- END ----------\n\n";
28 28
29 // The below thresholds were chosen arbitrarily to conveniently show small data 29 // The below thresholds were chosen arbitrarily to conveniently show small data
30 // as part of the report itself without having to look into the system_logs.zip 30 // as part of the report itself without having to look into the system_logs.zip
31 // file. 31 // file.
32 const size_t kFeedbackMaxLength = 1024; 32 constexpr size_t kFeedbackMaxLength = 1024;
33 const size_t kFeedbackMaxLineCount = 10; 33 constexpr size_t kFeedbackMaxLineCount = 10;
34 34
35 const base::FilePath::CharType kLogsFilename[] = 35 constexpr base::FilePath::CharType kLogsFilename[] =
36 FILE_PATH_LITERAL("system_logs.txt"); 36 FILE_PATH_LITERAL("system_logs.txt");
37 const char kLogsAttachmentName[] = "system_logs.zip"; 37 constexpr char kLogsAttachmentName[] = "system_logs.zip";
38 38
39 const char kZipExt[] = ".zip"; 39 constexpr char kZipExt[] = ".zip";
40 40
41 const char kPngMimeType[] = "image/png"; 41 constexpr char kPngMimeType[] = "image/png";
42 const char kArbitraryMimeType[] = "application/octet-stream"; 42 constexpr char kArbitraryMimeType[] = "application/octet-stream";
43
44 // The ID of the product specific data as stored by the feedback server.
45 constexpr char kCrashReportIds[] = "crash_report_ids";
Rahul Chaturvedi 2016/09/08 19:58:24 Can this be made global and used from the crash re
afakhry 2016/09/09 22:20:10 I couldn't agree more! Thanks! Done. :)
43 46
44 // Determine if the given feedback value is small enough to not need to 47 // Determine if the given feedback value is small enough to not need to
45 // be compressed. 48 // be compressed.
46 bool BelowCompressionThreshold(const std::string& content) { 49 bool BelowCompressionThreshold(const std::string& content) {
47 if (content.length() > kFeedbackMaxLength) 50 if (content.length() > kFeedbackMaxLength)
48 return false; 51 return false;
49 const size_t line_count = std::count(content.begin(), content.end(), '\n'); 52 const size_t line_count = std::count(content.begin(), content.end(), '\n');
50 if (line_count > kFeedbackMaxLineCount) 53 if (line_count > kFeedbackMaxLineCount)
51 return false; 54 return false;
52 return true; 55 return true;
53 } 56 }
54 57
55 // Converts the system logs into a string that we can compress and send 58 // Converts the system logs into a string that we can compress and send
56 // with the report. 59 // with the report.
57 // TODO(dcheng): This should probably just take advantage of string's move 60 // TODO(dcheng): This should probably just take advantage of string's move
58 // constructor. 61 // constructor.
59 std::unique_ptr<std::string> LogsToString( 62 std::unique_ptr<std::string> LogsToString(
60 const FeedbackCommon::SystemLogsMap& sys_info) { 63 const FeedbackCommon::SystemLogsMap& sys_info) {
61 std::unique_ptr<std::string> syslogs_string(new std::string); 64 std::unique_ptr<std::string> syslogs_string(new std::string);
62 for (const auto& iter : sys_info) { 65 for (const auto& iter : sys_info) {
63 std::string key = iter.first; 66 std::string key = iter.first;
64 std::string value = iter.second; 67 std::string value = iter.second;
65 68
66 base::TrimString(key, "\n ", &key); 69 base::TrimString(key, "\n ", &key);
67 base::TrimString(value, "\n ", &value); 70 base::TrimString(value, "\n ", &value);
68 71
72 // We must avoid adding the crash IDs to the system_logs.txt file for
73 // privacy reasons. They should just be part of the product specific data.
74 if (key == kCrashReportIds)
75 continue;
76
69 if (value.find("\n") != std::string::npos) { 77 if (value.find("\n") != std::string::npos) {
70 syslogs_string->append(key + "=" + kMultilineIndicatorString + 78 syslogs_string->append(key + "=" + kMultilineIndicatorString +
71 kMultilineStartString + value + "\n" + 79 kMultilineStartString + value + "\n" +
72 kMultilineEndString); 80 kMultilineEndString);
73 } else { 81 } else {
74 syslogs_string->append(key + "=" + value + "\n"); 82 syslogs_string->append(key + "=" + value + "\n");
75 } 83 }
76 } 84 }
77 return syslogs_string; 85 return syslogs_string;
78 } 86 }
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 235
228 void FeedbackCommon::CompressLogs() { 236 void FeedbackCommon::CompressLogs() {
229 if (!logs_) 237 if (!logs_)
230 return; 238 return;
231 std::unique_ptr<std::string> logs = LogsToString(*logs_); 239 std::unique_ptr<std::string> logs = LogsToString(*logs_);
232 if (!logs->empty()) { 240 if (!logs->empty()) {
233 CompressFile(base::FilePath(kLogsFilename), kLogsAttachmentName, 241 CompressFile(base::FilePath(kLogsFilename), kLogsAttachmentName,
234 std::move(logs)); 242 std::move(logs));
235 } 243 }
236 } 244 }
245
237 void FeedbackCommon::AddFilesAndLogsToReport( 246 void FeedbackCommon::AddFilesAndLogsToReport(
238 userfeedback::ExtensionSubmit* feedback_data) const { 247 userfeedback::ExtensionSubmit* feedback_data) const {
239 for (size_t i = 0; i < attachments(); ++i) { 248 for (size_t i = 0; i < attachments(); ++i) {
240 const AttachedFile* file = attachment(i); 249 const AttachedFile* file = attachment(i);
241 AddAttachment(feedback_data, file->name.c_str(), *file->data); 250 AddAttachment(feedback_data, file->name.c_str(), *file->data);
242 } 251 }
243 252
244 if (!logs_) 253 if (!logs_)
245 return; 254 return;
246 255
247 for (const auto& iter : *logs_) { 256 for (const auto& iter : *logs_) {
248 if (BelowCompressionThreshold(iter.second)) { 257 if (BelowCompressionThreshold(iter.second)) {
249 // Small enough logs should end up in the report data itself. However, 258 // Small enough logs should end up in the report data itself. However,
250 // they're still added as part of the system_logs.zip file. 259 // they're still added as part of the system_logs.zip file.
251 AddFeedbackData(feedback_data, iter.first, iter.second); 260 AddFeedbackData(feedback_data, iter.first, iter.second);
252 } 261 }
253 } 262 }
254 } 263 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698