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 "components/autofill/core/browser/address.h" | 5 #include "components/autofill/core/browser/address.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "components/autofill/core/browser/autofill_country.h" | 14 #include "components/autofill/core/browser/autofill_country.h" |
| 15 #include "components/autofill/core/browser/autofill_field.h" | 15 #include "components/autofill/core/browser/autofill_field.h" |
| 16 #include "components/autofill/core/browser/autofill_profile.h" | |
| 16 #include "components/autofill/core/browser/autofill_type.h" | 17 #include "components/autofill/core/browser/autofill_type.h" |
| 17 #include "components/autofill/core/browser/country_names.h" | 18 #include "components/autofill/core/browser/country_names.h" |
| 19 #include "components/autofill/core/browser/state_names.h" | |
| 20 #include "components/autofill/core/common/autofill_l10n_util.h" | |
| 18 | 21 |
| 19 namespace autofill { | 22 namespace autofill { |
| 20 | 23 |
| 21 Address::Address() {} | 24 Address::Address() {} |
| 22 | 25 |
| 23 Address::Address(const Address& address) : FormGroup() { | 26 Address::Address(const Address& address) : FormGroup() { |
| 24 *this = address; | 27 *this = address; |
| 25 } | 28 } |
| 26 | 29 |
| 27 Address::~Address() {} | 30 Address::~Address() {} |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 | 194 |
| 192 void Address::GetMatchingTypes(const base::string16& text, | 195 void Address::GetMatchingTypes(const base::string16& text, |
| 193 const std::string& app_locale, | 196 const std::string& app_locale, |
| 194 ServerFieldTypeSet* matching_types) const { | 197 ServerFieldTypeSet* matching_types) const { |
| 195 FormGroup::GetMatchingTypes(text, app_locale, matching_types); | 198 FormGroup::GetMatchingTypes(text, app_locale, matching_types); |
| 196 | 199 |
| 197 // Check to see if the |text| canonicalized as a country name is a match. | 200 // Check to see if the |text| canonicalized as a country name is a match. |
| 198 std::string country_code = CountryNames::GetInstance()->GetCountryCode(text); | 201 std::string country_code = CountryNames::GetInstance()->GetCountryCode(text); |
| 199 if (!country_code.empty() && country_code_ == country_code) | 202 if (!country_code.empty() && country_code_ == country_code) |
| 200 matching_types->insert(ADDRESS_HOME_COUNTRY); | 203 matching_types->insert(ADDRESS_HOME_COUNTRY); |
| 204 | |
| 205 // Check to see if the |text| could be the full name or abbreviation of a | |
| 206 // state. | |
| 207 base::string16 canon_text = AutofillProfile::CanonicalizeProfileString(text); | |
| 208 base::string16 state_name, state_abbreviation; | |
|
vabr (Chromium)
2016/03/18 12:03:50
optional: One line per variable, please.
I believe
sebsg
2016/03/18 13:03:55
Thanks, I also changed the other calls to this met
| |
| 209 state_names::GetNameAndAbbreviation(canon_text, &state_name, | |
| 210 &state_abbreviation); | |
| 211 if (!state_name.empty() || !state_abbreviation.empty()) { | |
| 212 l10n::CaseInsensitiveCompare compare; | |
| 213 base::string16 canon_profile_state = | |
| 214 AutofillProfile::CanonicalizeProfileString( | |
| 215 GetInfo(AutofillType(ADDRESS_HOME_STATE), app_locale)); | |
| 216 if ((!state_name.empty() && | |
| 217 compare.StringsEqual(state_name, canon_profile_state)) || | |
| 218 (!state_abbreviation.empty() && | |
| 219 compare.StringsEqual(state_abbreviation, canon_profile_state))) { | |
| 220 matching_types->insert(ADDRESS_HOME_STATE); | |
| 221 } | |
| 222 } | |
| 201 } | 223 } |
| 202 | 224 |
| 203 void Address::GetSupportedTypes(ServerFieldTypeSet* supported_types) const { | 225 void Address::GetSupportedTypes(ServerFieldTypeSet* supported_types) const { |
| 204 supported_types->insert(ADDRESS_HOME_LINE1); | 226 supported_types->insert(ADDRESS_HOME_LINE1); |
| 205 supported_types->insert(ADDRESS_HOME_LINE2); | 227 supported_types->insert(ADDRESS_HOME_LINE2); |
| 206 supported_types->insert(ADDRESS_HOME_LINE3); | 228 supported_types->insert(ADDRESS_HOME_LINE3); |
| 207 supported_types->insert(ADDRESS_HOME_STREET_ADDRESS); | 229 supported_types->insert(ADDRESS_HOME_STREET_ADDRESS); |
| 208 supported_types->insert(ADDRESS_HOME_DEPENDENT_LOCALITY); | 230 supported_types->insert(ADDRESS_HOME_DEPENDENT_LOCALITY); |
| 209 supported_types->insert(ADDRESS_HOME_CITY); | 231 supported_types->insert(ADDRESS_HOME_CITY); |
| 210 supported_types->insert(ADDRESS_HOME_STATE); | 232 supported_types->insert(ADDRESS_HOME_STATE); |
| 211 supported_types->insert(ADDRESS_HOME_ZIP); | 233 supported_types->insert(ADDRESS_HOME_ZIP); |
| 212 supported_types->insert(ADDRESS_HOME_SORTING_CODE); | 234 supported_types->insert(ADDRESS_HOME_SORTING_CODE); |
| 213 supported_types->insert(ADDRESS_HOME_COUNTRY); | 235 supported_types->insert(ADDRESS_HOME_COUNTRY); |
| 214 } | 236 } |
| 215 | 237 |
| 216 void Address::TrimStreetAddress() { | 238 void Address::TrimStreetAddress() { |
| 217 while (!street_address_.empty() && street_address_.back().empty()) { | 239 while (!street_address_.empty() && street_address_.back().empty()) { |
| 218 street_address_.pop_back(); | 240 street_address_.pop_back(); |
| 219 } | 241 } |
| 220 } | 242 } |
| 221 | 243 |
| 222 } // namespace autofill | 244 } // namespace autofill |
| OLD | NEW |