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

Side by Side Diff: components/autofill/core/browser/address.cc

Issue 2110563002: Use AutofillProfileComparator in place of ad-hoc merge logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@merge
Patch Set: Rebase Created 4 years, 5 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
OLDNEW
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_profile.h"
17 #include "components/autofill/core/browser/autofill_profile_comparator.h"
17 #include "components/autofill/core/browser/autofill_type.h" 18 #include "components/autofill/core/browser/autofill_type.h"
18 #include "components/autofill/core/browser/country_names.h" 19 #include "components/autofill/core/browser/country_names.h"
19 #include "components/autofill/core/browser/state_names.h" 20 #include "components/autofill/core/browser/state_names.h"
20 #include "components/autofill/core/common/autofill_l10n_util.h" 21 #include "components/autofill/core/common/autofill_l10n_util.h"
21 22
22 namespace autofill { 23 namespace autofill {
23 24
24 Address::Address() {} 25 Address::Address() {}
25 26
26 Address::Address(const Address& address) : FormGroup() { 27 Address::Address(const Address& address) : FormGroup() {
27 *this = address; 28 *this = address;
28 } 29 }
29 30
30 Address::~Address() {} 31 Address::~Address() {}
31 32
32 Address& Address::operator=(const Address& address) { 33 Address& Address::operator=(const Address& address) {
33 if (this == &address) 34 if (this == &address)
34 return *this; 35 return *this;
35 36
36 street_address_ = address.street_address_; 37 street_address_ = address.street_address_;
37 dependent_locality_ = address.dependent_locality_; 38 dependent_locality_ = address.dependent_locality_;
38 city_ = address.city_; 39 city_ = address.city_;
39 state_ = address.state_; 40 state_ = address.state_;
40 country_code_ = address.country_code_; 41 country_code_ = address.country_code_;
41 zip_code_ = address.zip_code_; 42 zip_code_ = address.zip_code_;
42 sorting_code_ = address.sorting_code_; 43 sorting_code_ = address.sorting_code_;
43 return *this; 44 return *this;
44 } 45 }
45 46
47 bool Address::operator==(const Address& other) const {
48 if (this == &other)
49 return true;
50 return street_address_ == other.street_address_ &&
51 dependent_locality_ == other.dependent_locality_ &&
52 city_ == other.city_ && state_ == other.state_ &&
53 zip_code_ == other.zip_code_ && sorting_code_ == other.sorting_code_ &&
54 country_code_ == other.country_code_;
55 }
56
46 base::string16 Address::GetRawInfo(ServerFieldType type) const { 57 base::string16 Address::GetRawInfo(ServerFieldType type) const {
47 DCHECK_EQ(ADDRESS_HOME, AutofillType(type).group()); 58 DCHECK_EQ(ADDRESS_HOME, AutofillType(type).group());
48 switch (type) { 59 switch (type) {
49 case ADDRESS_HOME_LINE1: 60 case ADDRESS_HOME_LINE1:
50 return street_address_.size() > 0 ? street_address_[0] : base::string16(); 61 return street_address_.size() > 0 ? street_address_[0] : base::string16();
51 62
52 case ADDRESS_HOME_LINE2: 63 case ADDRESS_HOME_LINE2:
53 return street_address_.size() > 1 ? street_address_[1] : base::string16(); 64 return street_address_.size() > 1 ? street_address_[1] : base::string16();
54 65
55 case ADDRESS_HOME_LINE3: 66 case ADDRESS_HOME_LINE3:
(...skipping 13 matching lines...) Expand all
69 80
70 case ADDRESS_HOME_SORTING_CODE: 81 case ADDRESS_HOME_SORTING_CODE:
71 return sorting_code_; 82 return sorting_code_;
72 83
73 case ADDRESS_HOME_COUNTRY: 84 case ADDRESS_HOME_COUNTRY:
74 return base::ASCIIToUTF16(country_code_); 85 return base::ASCIIToUTF16(country_code_);
75 86
76 case ADDRESS_HOME_STREET_ADDRESS: 87 case ADDRESS_HOME_STREET_ADDRESS:
77 return base::JoinString(street_address_, base::ASCIIToUTF16("\n")); 88 return base::JoinString(street_address_, base::ASCIIToUTF16("\n"));
78 89
90 case ADDRESS_HOME_APT_NUM:
91 return base::string16();
92
79 default: 93 default:
80 NOTREACHED(); 94 NOTREACHED() << "Unrecognized type: " << type;
81 return base::string16(); 95 return base::string16();
82 } 96 }
83 } 97 }
84 98
85 void Address::SetRawInfo(ServerFieldType type, const base::string16& value) { 99 void Address::SetRawInfo(ServerFieldType type, const base::string16& value) {
86 DCHECK_EQ(ADDRESS_HOME, AutofillType(type).group()); 100 DCHECK_EQ(ADDRESS_HOME, AutofillType(type).group());
87 switch (type) { 101 switch (type) {
88 case ADDRESS_HOME_LINE1: 102 case ADDRESS_HOME_LINE1:
89 if (street_address_.empty()) 103 if (street_address_.empty())
90 street_address_.resize(1); 104 street_address_.resize(1);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 void Address::GetMatchingTypes(const base::string16& text, 209 void Address::GetMatchingTypes(const base::string16& text,
196 const std::string& app_locale, 210 const std::string& app_locale,
197 ServerFieldTypeSet* matching_types) const { 211 ServerFieldTypeSet* matching_types) const {
198 FormGroup::GetMatchingTypes(text, app_locale, matching_types); 212 FormGroup::GetMatchingTypes(text, app_locale, matching_types);
199 213
200 // Check to see if the |text| canonicalized as a country name is a match. 214 // Check to see if the |text| canonicalized as a country name is a match.
201 std::string country_code = CountryNames::GetInstance()->GetCountryCode(text); 215 std::string country_code = CountryNames::GetInstance()->GetCountryCode(text);
202 if (!country_code.empty() && country_code_ == country_code) 216 if (!country_code.empty() && country_code_ == country_code)
203 matching_types->insert(ADDRESS_HOME_COUNTRY); 217 matching_types->insert(ADDRESS_HOME_COUNTRY);
204 218
219 AutofillProfileComparator comparator(app_locale);
205 // Check to see if the |text| could be the full name or abbreviation of a 220 // Check to see if the |text| could be the full name or abbreviation of a
206 // state. 221 // state.
207 base::string16 canon_text = AutofillProfile::CanonicalizeProfileString(text); 222 base::string16 canon_text = comparator.NormalizeForComparison(text);
208 base::string16 state_name; 223 base::string16 state_name;
209 base::string16 state_abbreviation; 224 base::string16 state_abbreviation;
210 state_names::GetNameAndAbbreviation(canon_text, &state_name, 225 state_names::GetNameAndAbbreviation(canon_text, &state_name,
211 &state_abbreviation); 226 &state_abbreviation);
212 if (!state_name.empty() || !state_abbreviation.empty()) { 227 if (!state_name.empty() || !state_abbreviation.empty()) {
213 l10n::CaseInsensitiveCompare compare; 228 l10n::CaseInsensitiveCompare compare;
214 base::string16 canon_profile_state = 229 base::string16 canon_profile_state =
215 AutofillProfile::CanonicalizeProfileString( 230 comparator.NormalizeForComparison(
216 GetInfo(AutofillType(ADDRESS_HOME_STATE), app_locale)); 231 GetInfo(AutofillType(ADDRESS_HOME_STATE), app_locale));
217 if ((!state_name.empty() && 232 if ((!state_name.empty() &&
218 compare.StringsEqual(state_name, canon_profile_state)) || 233 compare.StringsEqual(state_name, canon_profile_state)) ||
219 (!state_abbreviation.empty() && 234 (!state_abbreviation.empty() &&
220 compare.StringsEqual(state_abbreviation, canon_profile_state))) { 235 compare.StringsEqual(state_abbreviation, canon_profile_state))) {
221 matching_types->insert(ADDRESS_HOME_STATE); 236 matching_types->insert(ADDRESS_HOME_STATE);
222 } 237 }
223 } 238 }
224 } 239 }
225 240
(...skipping 10 matching lines...) Expand all
236 supported_types->insert(ADDRESS_HOME_COUNTRY); 251 supported_types->insert(ADDRESS_HOME_COUNTRY);
237 } 252 }
238 253
239 void Address::TrimStreetAddress() { 254 void Address::TrimStreetAddress() {
240 while (!street_address_.empty() && street_address_.back().empty()) { 255 while (!street_address_.empty() && street_address_.back().empty()) {
241 street_address_.pop_back(); 256 street_address_.pop_back();
242 } 257 }
243 } 258 }
244 259
245 } // namespace autofill 260 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/address.h ('k') | components/autofill/core/browser/autofill_merge_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698