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

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

Issue 2218303002: Fix system info being dropped from system_logs.zip (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 11 matching lines...) Expand all
22 constexpr int kChromeBrowserProductId = 237; 22 constexpr int kChromeBrowserProductId = 237;
23 #endif 23 #endif
24 24
25 const char kMultilineIndicatorString[] = "<multiline>\n"; 25 const char kMultilineIndicatorString[] = "<multiline>\n";
26 const char kMultilineStartString[] = "---------- START ----------\n"; 26 const char kMultilineStartString[] = "---------- START ----------\n";
27 const char kMultilineEndString[] = "---------- END ----------\n\n"; 27 const 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 = 4 * 1024; 32 const size_t kFeedbackMaxLength = 1024;
33 const size_t kFeedbackMaxLineCount = 40; 33 const size_t kFeedbackMaxLineCount = 10;
34 34
35 const base::FilePath::CharType kLogsFilename[] = 35 const 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 const char kLogsAttachmentName[] = "system_logs.zip";
38 38
39 const char kZipExt[] = ".zip"; 39 const char kZipExt[] = ".zip";
40 40
41 const char kPngMimeType[] = "image/png"; 41 const char kPngMimeType[] = "image/png";
42 const char kArbitraryMimeType[] = "application/octet-stream"; 42 const char kArbitraryMimeType[] = "application/octet-stream";
43 43
44 // Determine if the given feedback value is small enough to not need to 44 // Determine if the given feedback value is small enough to not need to
45 // be compressed. 45 // be compressed.
46 bool BelowCompressionThreshold(const std::string& content) { 46 bool BelowCompressionThreshold(const std::string& content) {
47 if (content.length() > kFeedbackMaxLength) 47 if (content.length() > kFeedbackMaxLength)
48 return false; 48 return false;
49 const size_t line_count = std::count(content.begin(), content.end(), '\n'); 49 const size_t line_count = std::count(content.begin(), content.end(), '\n');
50 if (line_count > kFeedbackMaxLineCount) 50 if (line_count > kFeedbackMaxLineCount)
51 return false; 51 return false;
52 return true; 52 return true;
53 } 53 }
54 54
55 // Converts the system logs into a string that we can compress and send 55 // Converts the system logs into a string that we can compress and send
56 // with the report. This method only converts those logs that we want in 56 // with the report.
57 // the compressed zip file sent with the report, hence it ignores any logs
58 // below the size threshold of what we want compressed.
59 // TODO(dcheng): This should probably just take advantage of string's move 57 // TODO(dcheng): This should probably just take advantage of string's move
60 // constructor. 58 // constructor.
61 std::unique_ptr<std::string> LogsToString( 59 std::unique_ptr<std::string> LogsToString(
62 const FeedbackCommon::SystemLogsMap& sys_info) { 60 const FeedbackCommon::SystemLogsMap& sys_info) {
63 std::unique_ptr<std::string> syslogs_string(new std::string); 61 std::unique_ptr<std::string> syslogs_string(new std::string);
64 for (const auto& iter : sys_info) { 62 for (const auto& iter : sys_info) {
65 std::string key = iter.first; 63 std::string key = iter.first;
66 std::string value = iter.second; 64 std::string value = iter.second;
67 65
68 if (BelowCompressionThreshold(value))
69 continue;
70
71 base::TrimString(key, "\n ", &key); 66 base::TrimString(key, "\n ", &key);
72 base::TrimString(value, "\n ", &value); 67 base::TrimString(value, "\n ", &value);
73 68
74 if (value.find("\n") != std::string::npos) { 69 if (value.find("\n") != std::string::npos) {
75 syslogs_string->append(key + "=" + kMultilineIndicatorString + 70 syslogs_string->append(key + "=" + kMultilineIndicatorString +
76 kMultilineStartString + value + "\n" + 71 kMultilineStartString + value + "\n" +
77 kMultilineEndString); 72 kMultilineEndString);
78 } else { 73 } else {
79 syslogs_string->append(key + "=" + value + "\n"); 74 syslogs_string->append(key + "=" + value + "\n");
80 } 75 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 return; 245 return;
251 246
252 for (const auto& iter : *logs_) { 247 for (const auto& iter : *logs_) {
253 if (BelowCompressionThreshold(iter.second)) { 248 if (BelowCompressionThreshold(iter.second)) {
254 // Small enough logs should end up in the report data itself. However, 249 // Small enough logs should end up in the report data itself. However,
255 // they're still added as part of the system_logs.zip file. 250 // they're still added as part of the system_logs.zip file.
256 AddFeedbackData(feedback_data, iter.first, iter.second); 251 AddFeedbackData(feedback_data, iter.first, iter.second);
257 } 252 }
258 } 253 }
259 } 254 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698