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/autofill/core/common/save_password_progress_logger.h" | 5 #include "components/autofill/core/common/save_password_progress_logger.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "components/autofill/core/common/password_form.h" | 16 #include "components/autofill/core/common/password_form.h" |
17 | 17 |
18 using base::checked_cast; | 18 using base::checked_cast; |
19 using base::Value; | 19 using base::Value; |
20 using base::DictionaryValue; | 20 using base::DictionaryValue; |
21 using base::StringValue; | |
22 | 21 |
23 namespace autofill { | 22 namespace autofill { |
24 | 23 |
25 namespace { | 24 namespace { |
26 | 25 |
27 // Returns true for all characters which we don't want to see in the logged IDs | 26 // Returns true for all characters which we don't want to see in the logged IDs |
28 // or names of HTML elements. | 27 // or names of HTML elements. |
29 bool IsUnwantedInElementID(char c) { | 28 bool IsUnwantedInElementID(char c) { |
30 return !(c == '_' || c == '-' || base::IsAsciiAlpha(c) || | 29 return !(c == '_' || c == '-' || base::IsAsciiAlpha(c) || |
31 base::IsAsciiDigit(c)); | 30 base::IsAsciiDigit(c)); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 const GURL& action) { | 86 const GURL& action) { |
88 DictionaryValue log; | 87 DictionaryValue log; |
89 log.SetString(GetStringFromID(STRING_NAME_OR_ID), ScrubElementID(name_or_id)); | 88 log.SetString(GetStringFromID(STRING_NAME_OR_ID), ScrubElementID(name_or_id)); |
90 log.SetString(GetStringFromID(STRING_ACTION), ScrubURL(action)); | 89 log.SetString(GetStringFromID(STRING_ACTION), ScrubURL(action)); |
91 LogValue(label, log); | 90 LogValue(label, log); |
92 } | 91 } |
93 | 92 |
94 void SavePasswordProgressLogger::LogURL( | 93 void SavePasswordProgressLogger::LogURL( |
95 SavePasswordProgressLogger::StringID label, | 94 SavePasswordProgressLogger::StringID label, |
96 const GURL& url) { | 95 const GURL& url) { |
97 LogValue(label, StringValue(ScrubURL(url))); | 96 LogValue(label, Value(ScrubURL(url))); |
98 } | 97 } |
99 | 98 |
100 void SavePasswordProgressLogger::LogBoolean( | 99 void SavePasswordProgressLogger::LogBoolean( |
101 SavePasswordProgressLogger::StringID label, | 100 SavePasswordProgressLogger::StringID label, |
102 bool truth_value) { | 101 bool truth_value) { |
103 LogValue(label, Value(truth_value)); | 102 LogValue(label, Value(truth_value)); |
104 } | 103 } |
105 | 104 |
106 void SavePasswordProgressLogger::LogNumber( | 105 void SavePasswordProgressLogger::LogNumber( |
107 SavePasswordProgressLogger::StringID label, | 106 SavePasswordProgressLogger::StringID label, |
108 int signed_number) { | 107 int signed_number) { |
109 LogValue(label, Value(signed_number)); | 108 LogValue(label, Value(signed_number)); |
110 } | 109 } |
111 | 110 |
112 void SavePasswordProgressLogger::LogNumber( | 111 void SavePasswordProgressLogger::LogNumber( |
113 SavePasswordProgressLogger::StringID label, | 112 SavePasswordProgressLogger::StringID label, |
114 size_t unsigned_number) { | 113 size_t unsigned_number) { |
115 LogNumber(label, checked_cast<int>(unsigned_number)); | 114 LogNumber(label, checked_cast<int>(unsigned_number)); |
116 } | 115 } |
117 | 116 |
118 void SavePasswordProgressLogger::LogMessage( | 117 void SavePasswordProgressLogger::LogMessage( |
119 SavePasswordProgressLogger::StringID message) { | 118 SavePasswordProgressLogger::StringID message) { |
120 LogValue(STRING_MESSAGE, StringValue(GetStringFromID(message))); | 119 LogValue(STRING_MESSAGE, Value(GetStringFromID(message))); |
121 } | 120 } |
122 | 121 |
123 // static | 122 // static |
124 std::string SavePasswordProgressLogger::ScrubURL(const GURL& url) { | 123 std::string SavePasswordProgressLogger::ScrubURL(const GURL& url) { |
125 if (url.is_valid()) | 124 if (url.is_valid()) |
126 return url.GetWithEmptyPath().spec(); | 125 return url.GetWithEmptyPath().spec(); |
127 return std::string(); | 126 return std::string(); |
128 } | 127 } |
129 | 128 |
130 void SavePasswordProgressLogger::LogValue(StringID label, const Value& log) { | 129 void SavePasswordProgressLogger::LogValue(StringID label, const Value& log) { |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 return "Password reused from "; | 392 return "Password reused from "; |
394 case SavePasswordProgressLogger::STRING_INVALID: | 393 case SavePasswordProgressLogger::STRING_INVALID: |
395 return "INVALID"; | 394 return "INVALID"; |
396 // Intentionally no default: clause here -- all IDs need to get covered. | 395 // Intentionally no default: clause here -- all IDs need to get covered. |
397 } | 396 } |
398 NOTREACHED(); // Win compilers don't believe this is unreachable. | 397 NOTREACHED(); // Win compilers don't believe this is unreachable. |
399 return std::string(); | 398 return std::string(); |
400 } | 399 } |
401 | 400 |
402 } // namespace autofill | 401 } // namespace autofill |
OLD | NEW |