Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <ostream> | 5 #include <ostream> |
| 6 #include <sstream> | 6 #include <sstream> |
| 7 | 7 |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "components/autofill/core/common/password_form.h" | 13 #include "components/autofill/core/common/password_form.h" |
| 14 | 14 |
| 15 namespace autofill { | 15 namespace autofill { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 base::string16 OtherPossibleUsernamesToString( | |
|
vabr (Chromium)
2017/03/16 21:00:42
You can also implement it as two pass processing:
kolos1
2017/03/17 14:09:34
Done.
| |
| 20 PossibleUsernamesVector possible_usernames) { | |
|
vabr (Chromium)
2017/03/16 21:00:42
const PossibleUsernamesVector&
kolos1
2017/03/17 14:09:34
Done.
| |
| 21 base::string16 result; | |
| 22 for (const PossibleUsernamePair pair : possible_usernames) { | |
|
vabr (Chromium)
2017/03/16 21:00:41
use const ref not const value:
const PossibleUsern
kolos1
2017/03/17 14:09:34
Done.
| |
| 23 if (!result.empty()) | |
| 24 result += base::ASCIIToUTF16(", "); | |
| 25 result += pair.first + base::ASCIIToUTF16("+") + pair.second; | |
| 26 } | |
| 27 return result; | |
| 28 } | |
| 29 | |
| 19 // Serializes a PasswordForm to a JSON object. Used only for logging in tests. | 30 // Serializes a PasswordForm to a JSON object. Used only for logging in tests. |
| 20 void PasswordFormToJSON(const PasswordForm& form, | 31 void PasswordFormToJSON(const PasswordForm& form, |
| 21 base::DictionaryValue* target) { | 32 base::DictionaryValue* target) { |
| 22 target->SetInteger("scheme", form.scheme); | 33 target->SetInteger("scheme", form.scheme); |
| 23 target->SetString("signon_realm", form.signon_realm); | 34 target->SetString("signon_realm", form.signon_realm); |
| 24 target->SetBoolean("is_public_suffix_match", form.is_public_suffix_match); | 35 target->SetBoolean("is_public_suffix_match", form.is_public_suffix_match); |
| 25 target->SetBoolean("is_affiliation_based_match", | 36 target->SetBoolean("is_affiliation_based_match", |
| 26 form.is_affiliation_based_match); | 37 form.is_affiliation_based_match); |
| 27 target->SetString("origin", form.origin.possibly_invalid_spec()); | 38 target->SetString("origin", form.origin.possibly_invalid_spec()); |
| 28 target->SetString("action", form.action.possibly_invalid_spec()); | 39 target->SetString("action", form.action.possibly_invalid_spec()); |
| 29 target->SetString("submit_element", form.submit_element); | 40 target->SetString("submit_element", form.submit_element); |
| 30 target->SetString("username_elem", form.username_element); | 41 target->SetString("username_elem", form.username_element); |
| 31 target->SetBoolean("username_marked_by_site", form.username_marked_by_site); | 42 target->SetBoolean("username_marked_by_site", form.username_marked_by_site); |
| 32 target->SetString("username_value", form.username_value); | 43 target->SetString("username_value", form.username_value); |
| 33 target->SetString("password_elem", form.password_element); | 44 target->SetString("password_elem", form.password_element); |
| 34 target->SetString("password_value", form.password_value); | 45 target->SetString("password_value", form.password_value); |
| 35 target->SetBoolean("password_value_is_default", | 46 target->SetBoolean("password_value_is_default", |
| 36 form.password_value_is_default); | 47 form.password_value_is_default); |
| 37 target->SetString("new_password_element", form.new_password_element); | 48 target->SetString("new_password_element", form.new_password_element); |
| 38 target->SetString("new_password_value", form.new_password_value); | 49 target->SetString("new_password_value", form.new_password_value); |
| 39 target->SetBoolean("new_password_value_is_default", | 50 target->SetBoolean("new_password_value_is_default", |
| 40 form.new_password_value_is_default); | 51 form.new_password_value_is_default); |
| 41 target->SetBoolean("new_password_marked_by_site", | 52 target->SetBoolean("new_password_marked_by_site", |
| 42 form.new_password_marked_by_site); | 53 form.new_password_marked_by_site); |
| 43 target->SetString("other_possible_usernames", | 54 target->SetString( |
| 44 base::JoinString(form.other_possible_usernames, | 55 "other_possible_usernames", |
| 45 base::ASCIIToUTF16("|"))); | 56 OtherPossibleUsernamesToString(form.other_possible_usernames)); |
| 46 target->SetBoolean("blacklisted", form.blacklisted_by_user); | 57 target->SetBoolean("blacklisted", form.blacklisted_by_user); |
| 47 target->SetBoolean("preferred", form.preferred); | 58 target->SetBoolean("preferred", form.preferred); |
| 48 target->SetDouble("date_created", form.date_created.ToDoubleT()); | 59 target->SetDouble("date_created", form.date_created.ToDoubleT()); |
| 49 target->SetDouble("date_synced", form.date_synced.ToDoubleT()); | 60 target->SetDouble("date_synced", form.date_synced.ToDoubleT()); |
| 50 target->SetInteger("type", form.type); | 61 target->SetInteger("type", form.type); |
| 51 target->SetInteger("times_used", form.times_used); | 62 target->SetInteger("times_used", form.times_used); |
| 52 std::ostringstream form_data_string_stream; | 63 std::ostringstream form_data_string_stream; |
| 53 form_data_string_stream << form.form_data; | 64 form_data_string_stream << form.form_data; |
| 54 target->SetString("form_data", form_data_string_stream.str()); | 65 target->SetString("form_data", form_data_string_stream.str()); |
| 55 target->SetInteger("generation_upload_status", form.generation_upload_status); | 66 target->SetInteger("generation_upload_status", form.generation_upload_status); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 base::JSONWriter::WriteWithOptions( | 211 base::JSONWriter::WriteWithOptions( |
| 201 form_json, base::JSONWriter::OPTIONS_PRETTY_PRINT, &form_as_string); | 212 form_json, base::JSONWriter::OPTIONS_PRETTY_PRINT, &form_as_string); |
| 202 base::TrimWhitespaceASCII(form_as_string, base::TRIM_ALL, &form_as_string); | 213 base::TrimWhitespaceASCII(form_as_string, base::TRIM_ALL, &form_as_string); |
| 203 return os << "PasswordForm(" << form_as_string << ")"; | 214 return os << "PasswordForm(" << form_as_string << ")"; |
| 204 } | 215 } |
| 205 | 216 |
| 206 std::ostream& operator<<(std::ostream& os, PasswordForm* form) { | 217 std::ostream& operator<<(std::ostream& os, PasswordForm* form) { |
| 207 return os << "&" << *form; | 218 return os << "&" << *form; |
| 208 } | 219 } |
| 209 | 220 |
| 221 base::string16 OtherPossibleUsernamesToStr(const PasswordForm& form) { | |
| 222 return OtherPossibleUsernamesToString(form.other_possible_usernames); | |
| 223 } | |
| 224 | |
| 210 } // namespace autofill | 225 } // namespace autofill |
| OLD | NEW |