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_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_report.h" |
11 #include "components/feedback/feedback_util.h" | 12 #include "components/feedback/feedback_util.h" |
12 #include "components/feedback/proto/common.pb.h" | 13 #include "components/feedback/proto/common.pb.h" |
13 #include "components/feedback/proto/dom.pb.h" | 14 #include "components/feedback/proto/dom.pb.h" |
14 #include "components/feedback/proto/extension.pb.h" | 15 #include "components/feedback/proto/extension.pb.h" |
15 #include "components/feedback/proto/math.pb.h" | 16 #include "components/feedback/proto/math.pb.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 #if defined(OS_CHROMEOS) | 20 #if defined(OS_CHROMEOS) |
20 constexpr int kChromeOSProductId = 208; | 21 constexpr int kChromeOSProductId = 208; |
21 #else | 22 #else |
22 constexpr int kChromeBrowserProductId = 237; | 23 constexpr int kChromeBrowserProductId = 237; |
23 #endif | 24 #endif |
24 | 25 |
25 const char kMultilineIndicatorString[] = "<multiline>\n"; | 26 constexpr char kMultilineIndicatorString[] = "<multiline>\n"; |
26 const char kMultilineStartString[] = "---------- START ----------\n"; | 27 constexpr char kMultilineStartString[] = "---------- START ----------\n"; |
27 const char kMultilineEndString[] = "---------- END ----------\n\n"; | 28 constexpr char kMultilineEndString[] = "---------- END ----------\n\n"; |
28 | 29 |
29 // The below thresholds were chosen arbitrarily to conveniently show small data | 30 // 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 | 31 // as part of the report itself without having to look into the system_logs.zip |
31 // file. | 32 // file. |
32 const size_t kFeedbackMaxLength = 1024; | 33 constexpr size_t kFeedbackMaxLength = 1024; |
33 const size_t kFeedbackMaxLineCount = 10; | 34 constexpr size_t kFeedbackMaxLineCount = 10; |
34 | 35 |
35 const base::FilePath::CharType kLogsFilename[] = | 36 constexpr base::FilePath::CharType kLogsFilename[] = |
36 FILE_PATH_LITERAL("system_logs.txt"); | 37 FILE_PATH_LITERAL("system_logs.txt"); |
37 const char kLogsAttachmentName[] = "system_logs.zip"; | 38 constexpr char kLogsAttachmentName[] = "system_logs.zip"; |
38 | 39 |
39 const char kZipExt[] = ".zip"; | 40 constexpr char kZipExt[] = ".zip"; |
40 | 41 |
41 const char kPngMimeType[] = "image/png"; | 42 constexpr char kPngMimeType[] = "image/png"; |
42 const char kArbitraryMimeType[] = "application/octet-stream"; | 43 constexpr char kArbitraryMimeType[] = "application/octet-stream"; |
43 | 44 |
44 // Determine if the given feedback value is small enough to not need to | 45 // Determine if the given feedback value is small enough to not need to |
45 // be compressed. | 46 // be compressed. |
46 bool BelowCompressionThreshold(const std::string& content) { | 47 bool BelowCompressionThreshold(const std::string& content) { |
47 if (content.length() > kFeedbackMaxLength) | 48 if (content.length() > kFeedbackMaxLength) |
48 return false; | 49 return false; |
49 const size_t line_count = std::count(content.begin(), content.end(), '\n'); | 50 const size_t line_count = std::count(content.begin(), content.end(), '\n'); |
50 if (line_count > kFeedbackMaxLineCount) | 51 if (line_count > kFeedbackMaxLineCount) |
51 return false; | 52 return false; |
52 return true; | 53 return true; |
53 } | 54 } |
54 | 55 |
55 // Converts the system logs into a string that we can compress and send | 56 // Converts the system logs into a string that we can compress and send |
56 // with the report. | 57 // with the report. |
57 // TODO(dcheng): This should probably just take advantage of string's move | 58 // TODO(dcheng): This should probably just take advantage of string's move |
58 // constructor. | 59 // constructor. |
59 std::unique_ptr<std::string> LogsToString( | 60 std::unique_ptr<std::string> LogsToString( |
60 const FeedbackCommon::SystemLogsMap& sys_info) { | 61 const FeedbackCommon::SystemLogsMap& sys_info) { |
61 std::unique_ptr<std::string> syslogs_string(new std::string); | 62 std::unique_ptr<std::string> syslogs_string(new std::string); |
62 for (const auto& iter : sys_info) { | 63 for (const auto& iter : sys_info) { |
63 std::string key = iter.first; | 64 std::string key = iter.first; |
64 std::string value = iter.second; | 65 std::string value = iter.second; |
65 | 66 |
66 base::TrimString(key, "\n ", &key); | 67 base::TrimString(key, "\n ", &key); |
67 base::TrimString(value, "\n ", &value); | 68 base::TrimString(value, "\n ", &value); |
68 | 69 |
| 70 // We must avoid adding the crash IDs to the system_logs.txt file for |
| 71 // privacy reasons. They should just be part of the product specific data. |
| 72 if (key == feedback::FeedbackReport::kCrashReportIdsKey) |
| 73 continue; |
| 74 |
69 if (value.find("\n") != std::string::npos) { | 75 if (value.find("\n") != std::string::npos) { |
70 syslogs_string->append(key + "=" + kMultilineIndicatorString + | 76 syslogs_string->append(key + "=" + kMultilineIndicatorString + |
71 kMultilineStartString + value + "\n" + | 77 kMultilineStartString + value + "\n" + |
72 kMultilineEndString); | 78 kMultilineEndString); |
73 } else { | 79 } else { |
74 syslogs_string->append(key + "=" + value + "\n"); | 80 syslogs_string->append(key + "=" + value + "\n"); |
75 } | 81 } |
76 } | 82 } |
77 return syslogs_string; | 83 return syslogs_string; |
78 } | 84 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 233 |
228 void FeedbackCommon::CompressLogs() { | 234 void FeedbackCommon::CompressLogs() { |
229 if (!logs_) | 235 if (!logs_) |
230 return; | 236 return; |
231 std::unique_ptr<std::string> logs = LogsToString(*logs_); | 237 std::unique_ptr<std::string> logs = LogsToString(*logs_); |
232 if (!logs->empty()) { | 238 if (!logs->empty()) { |
233 CompressFile(base::FilePath(kLogsFilename), kLogsAttachmentName, | 239 CompressFile(base::FilePath(kLogsFilename), kLogsAttachmentName, |
234 std::move(logs)); | 240 std::move(logs)); |
235 } | 241 } |
236 } | 242 } |
| 243 |
237 void FeedbackCommon::AddFilesAndLogsToReport( | 244 void FeedbackCommon::AddFilesAndLogsToReport( |
238 userfeedback::ExtensionSubmit* feedback_data) const { | 245 userfeedback::ExtensionSubmit* feedback_data) const { |
239 for (size_t i = 0; i < attachments(); ++i) { | 246 for (size_t i = 0; i < attachments(); ++i) { |
240 const AttachedFile* file = attachment(i); | 247 const AttachedFile* file = attachment(i); |
241 AddAttachment(feedback_data, file->name.c_str(), *file->data); | 248 AddAttachment(feedback_data, file->name.c_str(), *file->data); |
242 } | 249 } |
243 | 250 |
244 if (!logs_) | 251 if (!logs_) |
245 return; | 252 return; |
246 | 253 |
247 for (const auto& iter : *logs_) { | 254 for (const auto& iter : *logs_) { |
248 if (BelowCompressionThreshold(iter.second)) { | 255 if (BelowCompressionThreshold(iter.second)) { |
249 // Small enough logs should end up in the report data itself. However, | 256 // 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. | 257 // they're still added as part of the system_logs.zip file. |
251 AddFeedbackData(feedback_data, iter.first, iter.second); | 258 AddFeedbackData(feedback_data, iter.first, iter.second); |
252 } | 259 } |
253 } | 260 } |
254 } | 261 } |
OLD | NEW |