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

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

Issue 1530403003: Add anonymizer tool (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 "feedback_common.h" 5 #include "components/feedback/feedback_common.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "components/feedback/anonymizer_tool.h"
8 #include "components/feedback/proto/common.pb.h" 9 #include "components/feedback/proto/common.pb.h"
9 #include "components/feedback/proto/dom.pb.h" 10 #include "components/feedback/proto/dom.pb.h"
10 #include "components/feedback/proto/extension.pb.h" 11 #include "components/feedback/proto/extension.pb.h"
11 #include "components/feedback/proto/math.pb.h" 12 #include "components/feedback/proto/math.pb.h"
12 13
13 namespace { 14 namespace {
14 15
15 const char kMultilineIndicatorString[] = "<multiline>\n"; 16 const char kMultilineIndicatorString[] = "<multiline>\n";
16 const char kMultilineStartString[] = "---------- START ----------\n"; 17 const char kMultilineStartString[] = "---------- START ----------\n";
17 const char kMultilineEndString[] = "---------- END ----------\n\n"; 18 const char kMultilineEndString[] = "---------- END ----------\n\n";
18 19
19 const size_t kFeedbackMaxLength = 4 * 1024; 20 const size_t kFeedbackMaxLength = 4 * 1024;
20 const size_t kFeedbackMaxLineCount = 40; 21 const size_t kFeedbackMaxLineCount = 40;
21 22
22 const base::FilePath::CharType kLogsFilename[] = 23 const base::FilePath::CharType kLogsFilename[] =
23 FILE_PATH_LITERAL("system_logs.txt"); 24 FILE_PATH_LITERAL("system_logs.txt");
24 const char kLogsAttachmentName[] = "system_logs.zip"; 25 const char kLogsAttachmentName[] = "system_logs.zip";
25 26
26 const char kZipExt[] = ".zip"; 27 const char kZipExt[] = ".zip";
27 28
28 const char kPngMimeType[] = "image/png"; 29 const char kPngMimeType[] = "image/png";
29 const char kArbitraryMimeType[] = "application/octet-stream"; 30 const char kArbitraryMimeType[] = "application/octet-stream";
30 31
31 // Converts the system logs into a string that we can compress and send 32 // Converts the system logs into a string that we can compress and send
32 // with the report. This method only converts those logs that we want in 33 // with the report. This method only converts those logs that we want in
33 // the compressed zip file sent with the report, hence it ignores any logs 34 // the compressed zip file sent with the report, hence it ignores any logs
34 // below the size threshold of what we want compressed. 35 // below the size threshold of what we want compressed.
36 // Logs files are anonymized by the AnonymizerTool.
35 std::string* LogsToString(const FeedbackCommon::SystemLogsMap& sys_info) { 37 std::string* LogsToString(const FeedbackCommon::SystemLogsMap& sys_info) {
36 std::string* syslogs_string = new std::string; 38 std::string* syslogs_string = new std::string;
39 feedback::AnonymizerTool anonymizer;
37 for (FeedbackCommon::SystemLogsMap::const_iterator it = sys_info.begin(); 40 for (FeedbackCommon::SystemLogsMap::const_iterator it = sys_info.begin();
38 it != sys_info.end(); 41 it != sys_info.end();
39 ++it) { 42 ++it) {
40 std::string key = it->first; 43 std::string key = it->first;
41 std::string value = it->second; 44 std::string value = it->second;
42 45
43 if (FeedbackCommon::BelowCompressionThreshold(value)) 46 if (FeedbackCommon::BelowCompressionThreshold(value))
44 continue; 47 continue;
45 48
46 base::TrimString(key, "\n ", &key); 49 base::TrimString(key, "\n ", &key);
47 base::TrimString(value, "\n ", &value); 50 base::TrimString(value, "\n ", &value);
48 51
52 value = anonymizer.Anonymize(value);
53
49 if (value.find("\n") != std::string::npos) { 54 if (value.find("\n") != std::string::npos) {
50 syslogs_string->append(key + "=" + kMultilineIndicatorString + 55 syslogs_string->append(key + "=" + kMultilineIndicatorString +
51 kMultilineStartString + value + "\n" + 56 kMultilineStartString + value + "\n" +
52 kMultilineEndString); 57 kMultilineEndString);
53 } else { 58 } else {
54 syslogs_string->append(key + "=" + value + "\n"); 59 syslogs_string->append(key + "=" + value + "\n");
55 } 60 }
56 } 61 }
57 return syslogs_string; 62 return syslogs_string;
58 } 63 }
59 64
65 // Data is anonymized by the AnonymizerTool.
60 void AddFeedbackData(userfeedback::ExtensionSubmit* feedback_data, 66 void AddFeedbackData(userfeedback::ExtensionSubmit* feedback_data,
61 const std::string& key, 67 const std::string& key,
62 const std::string& value) { 68 const std::string& value) {
63 // Don't bother with empty keys or values. 69 // Don't bother with empty keys or values.
64 if (key.empty() || value.empty()) 70 if (key.empty() || value.empty())
65 return; 71 return;
72
73 feedback::AnonymizerTool anonymizer;
74
66 // Create log_value object and add it to the web_data object. 75 // Create log_value object and add it to the web_data object.
67 userfeedback::ProductSpecificData log_value; 76 userfeedback::ProductSpecificData log_value;
68 log_value.set_key(key); 77 log_value.set_key(key);
69 log_value.set_value(value); 78 log_value.set_value(anonymizer.Anonymize(value));
70 userfeedback::WebData* web_data = feedback_data->mutable_web_data(); 79 userfeedback::WebData* web_data = feedback_data->mutable_web_data();
71 *(web_data->add_product_specific_data()) = log_value; 80 *(web_data->add_product_specific_data()) = log_value;
72 } 81 }
73 82
74 // Adds data as an attachment to feedback_data if the data is non-empty. 83 // Adds data as an attachment to feedback_data if the data is non-empty.
75 void AddAttachment(userfeedback::ExtensionSubmit* feedback_data, 84 void AddAttachment(userfeedback::ExtensionSubmit* feedback_data,
76 const char* name, 85 const char* name,
77 const std::string& data) { 86 const std::string& data) {
78 if (data.empty()) 87 if (data.empty())
79 return; 88 return;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 214
206 *(screenshot.mutable_dimensions()) = dimensions; 215 *(screenshot.mutable_dimensions()) = dimensions;
207 screenshot.set_binary_content(*image()); 216 screenshot.set_binary_content(*image());
208 217
209 *(feedback_data->mutable_screenshot()) = screenshot; 218 *(feedback_data->mutable_screenshot()) = screenshot;
210 } 219 }
211 220
212 if (category_tag().size()) 221 if (category_tag().size())
213 feedback_data->set_bucket(category_tag()); 222 feedback_data->set_bucket(category_tag());
214 } 223 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698