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

Side by Side Diff: components/autofill/browser/autofill_profile.cc

Issue 13697002: Make autofill's Address store country using the country code so that app locale isn't needed for th… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix remaining tests Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser/autofill_profile.h" 5 #include "components/autofill/browser/autofill_profile.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <map> 9 #include <map>
10 #include <ostream> 10 #include <ostream>
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 } 393 }
394 } 394 }
395 395
396 field_data->value = number; 396 field_data->value = number;
397 } 397 }
398 398
399 const string16 AutofillProfile::Label() const { 399 const string16 AutofillProfile::Label() const {
400 return label_; 400 return label_;
401 } 401 }
402 402
403 const std::string AutofillProfile::CountryCode() const {
404 return address_.country_code();
405 }
406
407 void AutofillProfile::SetCountryCode(const std::string& country_code) {
408 address_.set_country_code(country_code);
409 }
410
411 bool AutofillProfile::IsEmpty() const { 403 bool AutofillProfile::IsEmpty() const {
412 FieldTypeSet types; 404 FieldTypeSet types;
413 GetNonEmptyTypes(AutofillCountry::ApplicationLocale(), &types); 405 GetNonEmptyTypes(AutofillCountry::ApplicationLocale(), &types);
414 return types.empty(); 406 return types.empty();
415 } 407 }
416 408
417 int AutofillProfile::Compare(const AutofillProfile& profile) const { 409 int AutofillProfile::Compare(const AutofillProfile& profile) const {
418 const AutofillFieldType single_value_types[] = { COMPANY_NAME, 410 const AutofillFieldType single_value_types[] = { COMPANY_NAME,
419 ADDRESS_HOME_LINE1, 411 ADDRESS_HOME_LINE1,
420 ADDRESS_HOME_LINE2, 412 ADDRESS_HOME_LINE2,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 if (*iter == NAME_FULL) { 468 if (*iter == NAME_FULL) {
477 // Ignore the compound "full name" field type. We are only interested in 469 // Ignore the compound "full name" field type. We are only interested in
478 // comparing the constituent parts. For example, if |this| has a middle 470 // comparing the constituent parts. For example, if |this| has a middle
479 // name saved, but |profile| lacks one, |profile| could still be a subset 471 // name saved, but |profile| lacks one, |profile| could still be a subset
480 // of |this|. 472 // of |this|.
481 continue; 473 continue;
482 } else if (AutofillType(*iter).group() == AutofillType::PHONE) { 474 } else if (AutofillType(*iter).group() == AutofillType::PHONE) {
483 // Phone numbers should be canonicalized prior to being compared. 475 // Phone numbers should be canonicalized prior to being compared.
484 if (*iter != PHONE_HOME_WHOLE_NUMBER) { 476 if (*iter != PHONE_HOME_WHOLE_NUMBER) {
485 continue; 477 continue;
486 } else if (!autofill_i18n::PhoneNumbersMatch(GetRawInfo(*iter), 478 } else if (!autofill_i18n::PhoneNumbersMatch(
487 profile.GetRawInfo(*iter), 479 GetRawInfo(*iter),
488 CountryCode())) { 480 profile.GetRawInfo(*iter),
481 UTF16ToASCII(GetRawInfo(ADDRESS_HOME_COUNTRY)))) {
489 return false; 482 return false;
490 } 483 }
491 } else if (StringToLowerASCII(GetRawInfo(*iter)) != 484 } else if (StringToLowerASCII(GetRawInfo(*iter)) !=
492 StringToLowerASCII(profile.GetRawInfo(*iter))) { 485 StringToLowerASCII(profile.GetRawInfo(*iter))) {
493 return false; 486 return false;
494 } 487 }
495 } 488 }
496 489
497 return true; 490 return true;
498 } 491 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 } 608 }
616 609
617 void AutofillProfile::GetSupportedTypes(FieldTypeSet* supported_types) const { 610 void AutofillProfile::GetSupportedTypes(FieldTypeSet* supported_types) const {
618 FormGroupList info = FormGroups(); 611 FormGroupList info = FormGroups();
619 for (FormGroupList::const_iterator it = info.begin(); it != info.end(); ++it) 612 for (FormGroupList::const_iterator it = info.begin(); it != info.end(); ++it)
620 (*it)->GetSupportedTypes(supported_types); 613 (*it)->GetSupportedTypes(supported_types);
621 } 614 }
622 615
623 bool AutofillProfile::FillCountrySelectControl(FormFieldData* field_data) 616 bool AutofillProfile::FillCountrySelectControl(FormFieldData* field_data)
624 const { 617 const {
625 std::string country_code = CountryCode(); 618 std::string country_code = UTF16ToASCII(GetRawInfo(ADDRESS_HOME_COUNTRY));
626 std::string app_locale = AutofillCountry::ApplicationLocale(); 619 std::string app_locale = AutofillCountry::ApplicationLocale();
627 620
628 DCHECK_EQ(field_data->option_values.size(), 621 DCHECK_EQ(field_data->option_values.size(),
629 field_data->option_contents.size()); 622 field_data->option_contents.size());
630 for (size_t i = 0; i < field_data->option_values.size(); ++i) { 623 for (size_t i = 0; i < field_data->option_values.size(); ++i) {
631 // Canonicalize each <option> value to a country code, and compare to the 624 // Canonicalize each <option> value to a country code, and compare to the
632 // target country code. 625 // target country code.
633 string16 value = field_data->option_values[i]; 626 string16 value = field_data->option_values[i];
634 string16 contents = field_data->option_contents[i]; 627 string16 contents = field_data->option_contents[i];
635 if (country_code == AutofillCountry::GetCountryCode(value, app_locale) || 628 if (country_code == AutofillCountry::GetCountryCode(value, app_locale) ||
(...skipping 23 matching lines...) Expand all
659 values->resize(1); 652 values->resize(1);
660 (*values)[0] = GetFormGroupInfo(*this, type, app_locale); 653 (*values)[0] = GetFormGroupInfo(*this, type, app_locale);
661 } 654 }
662 } 655 }
663 656
664 void AutofillProfile::AddPhoneIfUnique(const string16& phone, 657 void AutofillProfile::AddPhoneIfUnique(const string16& phone,
665 std::vector<string16>* existing_phones) { 658 std::vector<string16>* existing_phones) {
666 DCHECK(existing_phones); 659 DCHECK(existing_phones);
667 // Phones allow "fuzzy" matching, so "1-800-FLOWERS", "18003569377", 660 // Phones allow "fuzzy" matching, so "1-800-FLOWERS", "18003569377",
668 // "(800)356-9377" and "356-9377" are considered the same. 661 // "(800)356-9377" and "356-9377" are considered the same.
669 if (std::find_if(existing_phones->begin(), existing_phones->end(), 662 if (std::find_if(
670 FindByPhone(phone, CountryCode())) == 663 existing_phones->begin(), existing_phones->end(),
664 FindByPhone(phone, UTF16ToASCII(GetRawInfo(ADDRESS_HOME_COUNTRY)))) ==
671 existing_phones->end()) { 665 existing_phones->end()) {
672 existing_phones->push_back(phone); 666 existing_phones->push_back(phone);
673 } 667 }
674 } 668 }
675 669
676 string16 AutofillProfile::ConstructInferredLabel( 670 string16 AutofillProfile::ConstructInferredLabel(
677 const std::vector<AutofillFieldType>& included_fields, 671 const std::vector<AutofillFieldType>& included_fields,
678 size_t num_fields_to_use) const { 672 size_t num_fields_to_use) const {
679 const string16 separator = 673 const string16 separator =
680 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_SUMMARY_SEPARATOR); 674 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_SUMMARY_SEPARATOR);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY)) 833 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY))
840 << " " 834 << " "
841 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) 835 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE))
842 << " " 836 << " "
843 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) 837 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP))
844 << " " 838 << " "
845 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) 839 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY))
846 << " " 840 << " "
847 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); 841 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER));
848 } 842 }
OLDNEW
« no previous file with comments | « components/autofill/browser/autofill_profile.h ('k') | components/autofill/browser/autofill_profile_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698