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

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

Issue 1582353006: CountryNames: Separate data creation from usage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@571610_exposeCountryNamesToTesting
Patch Set: Just rebased Created 4 years, 11 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"
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 163
164 country_code_ = base::ToUpperASCII(base::UTF16ToASCII(value)); 164 country_code_ = base::ToUpperASCII(base::UTF16ToASCII(value));
165 return true; 165 return true;
166 } else if (type.html_type() == HTML_TYPE_FULL_ADDRESS) { 166 } else if (type.html_type() == HTML_TYPE_FULL_ADDRESS) {
167 // Parsing a full address is too hard. 167 // Parsing a full address is too hard.
168 return false; 168 return false;
169 } 169 }
170 170
171 ServerFieldType storable_type = type.GetStorableType(); 171 ServerFieldType storable_type = type.GetStorableType();
172 if (storable_type == ADDRESS_HOME_COUNTRY && !value.empty()) { 172 if (storable_type == ADDRESS_HOME_COUNTRY && !value.empty()) {
173 country_code_ = 173 country_code_ = CountryNames::GetInstance()->GetCountryCode(value);
174 CountryNames::GetInstance()->GetCountryCode(value, app_locale);
175 return !country_code_.empty(); 174 return !country_code_.empty();
176 } 175 }
177 176
178 SetRawInfo(storable_type, value); 177 SetRawInfo(storable_type, value);
179 178
180 // Give up when importing addresses with any entirely blank lines. 179 // Give up when importing addresses with any entirely blank lines.
181 // There's a good chance that this formatting is not intentional, but it's 180 // There's a good chance that this formatting is not intentional, but it's
182 // also not obviously safe to just strip the newlines. 181 // also not obviously safe to just strip the newlines.
183 if (storable_type == ADDRESS_HOME_STREET_ADDRESS && 182 if (storable_type == ADDRESS_HOME_STREET_ADDRESS &&
184 std::find(street_address_.begin(), street_address_.end(), 183 std::find(street_address_.begin(), street_address_.end(),
185 base::string16()) != street_address_.end()) { 184 base::string16()) != street_address_.end()) {
186 street_address_.clear(); 185 street_address_.clear();
187 return false; 186 return false;
188 } 187 }
189 188
190 return true; 189 return true;
191 } 190 }
192 191
193 void Address::GetMatchingTypes(const base::string16& text, 192 void Address::GetMatchingTypes(const base::string16& text,
194 const std::string& app_locale, 193 const std::string& app_locale,
195 ServerFieldTypeSet* matching_types) const { 194 ServerFieldTypeSet* matching_types) const {
196 FormGroup::GetMatchingTypes(text, app_locale, matching_types); 195 FormGroup::GetMatchingTypes(text, app_locale, matching_types);
197 196
198 // Check to see if the |text| canonicalized as a country name is a match. 197 // Check to see if the |text| canonicalized as a country name is a match.
199 std::string country_code = 198 std::string country_code = CountryNames::GetInstance()->GetCountryCode(text);
200 CountryNames::GetInstance()->GetCountryCode(text, app_locale);
201 if (!country_code.empty() && country_code_ == country_code) 199 if (!country_code.empty() && country_code_ == country_code)
202 matching_types->insert(ADDRESS_HOME_COUNTRY); 200 matching_types->insert(ADDRESS_HOME_COUNTRY);
203 } 201 }
204 202
205 void Address::GetSupportedTypes(ServerFieldTypeSet* supported_types) const { 203 void Address::GetSupportedTypes(ServerFieldTypeSet* supported_types) const {
206 supported_types->insert(ADDRESS_HOME_LINE1); 204 supported_types->insert(ADDRESS_HOME_LINE1);
207 supported_types->insert(ADDRESS_HOME_LINE2); 205 supported_types->insert(ADDRESS_HOME_LINE2);
208 supported_types->insert(ADDRESS_HOME_LINE3); 206 supported_types->insert(ADDRESS_HOME_LINE3);
209 supported_types->insert(ADDRESS_HOME_STREET_ADDRESS); 207 supported_types->insert(ADDRESS_HOME_STREET_ADDRESS);
210 supported_types->insert(ADDRESS_HOME_DEPENDENT_LOCALITY); 208 supported_types->insert(ADDRESS_HOME_DEPENDENT_LOCALITY);
211 supported_types->insert(ADDRESS_HOME_CITY); 209 supported_types->insert(ADDRESS_HOME_CITY);
212 supported_types->insert(ADDRESS_HOME_STATE); 210 supported_types->insert(ADDRESS_HOME_STATE);
213 supported_types->insert(ADDRESS_HOME_ZIP); 211 supported_types->insert(ADDRESS_HOME_ZIP);
214 supported_types->insert(ADDRESS_HOME_SORTING_CODE); 212 supported_types->insert(ADDRESS_HOME_SORTING_CODE);
215 supported_types->insert(ADDRESS_HOME_COUNTRY); 213 supported_types->insert(ADDRESS_HOME_COUNTRY);
216 } 214 }
217 215
218 void Address::TrimStreetAddress() { 216 void Address::TrimStreetAddress() {
219 while (!street_address_.empty() && street_address_.back().empty()) { 217 while (!street_address_.empty() && street_address_.back().empty()) {
220 street_address_.pop_back(); 218 street_address_.pop_back();
221 } 219 }
222 } 220 }
223 221
224 } // namespace autofill 222 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698