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/personal_data_manager.h" | 5 #include "components/autofill/core/browser/personal_data_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <iterator> | 9 #include <iterator> |
10 | 10 |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 (filter.is_null() || filter.Run(*profile))) { | 595 (filter.is_null() || filter.Run(*profile))) { |
596 matched_profiles.push_back(profile); | 596 matched_profiles.push_back(profile); |
597 values->push_back(multi_values[i]); | 597 values->push_back(multi_values[i]); |
598 guid_pairs->push_back(GUIDPair(profile->guid(), i)); | 598 guid_pairs->push_back(GUIDPair(profile->guid(), i)); |
599 } | 599 } |
600 } else { | 600 } else { |
601 if (multi_values[i].empty()) | 601 if (multi_values[i].empty()) |
602 continue; | 602 continue; |
603 | 603 |
604 base::string16 profile_value_lower_case( | 604 base::string16 profile_value_lower_case( |
605 StringToLowerASCII(multi_values[i])); | 605 base::StringToLowerASCII(multi_values[i])); |
606 base::string16 field_value_lower_case( | 606 base::string16 field_value_lower_case( |
607 StringToLowerASCII(field_contents)); | 607 base::StringToLowerASCII(field_contents)); |
608 // Phone numbers could be split in US forms, so field value could be | 608 // Phone numbers could be split in US forms, so field value could be |
609 // either prefix or suffix of the phone. | 609 // either prefix or suffix of the phone. |
610 bool matched_phones = false; | 610 bool matched_phones = false; |
611 if (type.GetStorableType() == PHONE_HOME_NUMBER && | 611 if (type.GetStorableType() == PHONE_HOME_NUMBER && |
612 !field_value_lower_case.empty() && | 612 !field_value_lower_case.empty() && |
613 profile_value_lower_case.find(field_value_lower_case) != | 613 profile_value_lower_case.find(field_value_lower_case) != |
614 base::string16::npos) { | 614 base::string16::npos) { |
615 matched_phones = true; | 615 matched_phones = true; |
616 } | 616 } |
617 | 617 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 std::string guid = new_profile.guid(); | 744 std::string guid = new_profile.guid(); |
745 | 745 |
746 // If we have already saved this address, merge in any missing values. | 746 // If we have already saved this address, merge in any missing values. |
747 // Only merge with the first match. | 747 // Only merge with the first match. |
748 for (std::vector<AutofillProfile*>::const_iterator iter = | 748 for (std::vector<AutofillProfile*>::const_iterator iter = |
749 existing_profiles.begin(); | 749 existing_profiles.begin(); |
750 iter != existing_profiles.end(); ++iter) { | 750 iter != existing_profiles.end(); ++iter) { |
751 AutofillProfile* existing_profile = *iter; | 751 AutofillProfile* existing_profile = *iter; |
752 if (!matching_profile_found && | 752 if (!matching_profile_found && |
753 !new_profile.PrimaryValue().empty() && | 753 !new_profile.PrimaryValue().empty() && |
754 StringToLowerASCII(existing_profile->PrimaryValue()) == | 754 base::StringToLowerASCII(existing_profile->PrimaryValue()) == |
755 StringToLowerASCII(new_profile.PrimaryValue())) { | 755 base::StringToLowerASCII(new_profile.PrimaryValue())) { |
756 // Unverified profiles should always be updated with the newer data, | 756 // Unverified profiles should always be updated with the newer data, |
757 // whereas verified profiles should only ever be overwritten by verified | 757 // whereas verified profiles should only ever be overwritten by verified |
758 // data. If an automatically aggregated profile would overwrite a | 758 // data. If an automatically aggregated profile would overwrite a |
759 // verified profile, just drop it. | 759 // verified profile, just drop it. |
760 matching_profile_found = true; | 760 matching_profile_found = true; |
761 guid = existing_profile->guid(); | 761 guid = existing_profile->guid(); |
762 if (!existing_profile->IsVerified() || new_profile.IsVerified()) | 762 if (!existing_profile->IsVerified() || new_profile.IsVerified()) |
763 existing_profile->OverwriteWithOrAddTo(new_profile, app_locale); | 763 existing_profile->OverwriteWithOrAddTo(new_profile, app_locale); |
764 } | 764 } |
765 merged_profiles->push_back(*existing_profile); | 765 merged_profiles->push_back(*existing_profile); |
766 } | 766 } |
767 | 767 |
768 // If the new profile was not merged with an existing one, add it to the list. | 768 // If the new profile was not merged with an existing one, add it to the list. |
769 if (!matching_profile_found) | 769 if (!matching_profile_found) |
770 merged_profiles->push_back(new_profile); | 770 merged_profiles->push_back(new_profile); |
771 | 771 |
772 return guid; | 772 return guid; |
773 } | 773 } |
774 | 774 |
775 bool PersonalDataManager::IsCountryOfInterest(const std::string& country_code) | 775 bool PersonalDataManager::IsCountryOfInterest(const std::string& country_code) |
776 const { | 776 const { |
777 DCHECK_EQ(2U, country_code.size()); | 777 DCHECK_EQ(2U, country_code.size()); |
778 | 778 |
779 const std::vector<AutofillProfile*>& profiles = web_profiles(); | 779 const std::vector<AutofillProfile*>& profiles = web_profiles(); |
780 std::list<std::string> country_codes; | 780 std::list<std::string> country_codes; |
781 for (size_t i = 0; i < profiles.size(); ++i) { | 781 for (size_t i = 0; i < profiles.size(); ++i) { |
782 country_codes.push_back(StringToLowerASCII(base::UTF16ToASCII( | 782 country_codes.push_back(base::StringToLowerASCII(base::UTF16ToASCII( |
783 profiles[i]->GetRawInfo(ADDRESS_HOME_COUNTRY)))); | 783 profiles[i]->GetRawInfo(ADDRESS_HOME_COUNTRY)))); |
784 } | 784 } |
785 | 785 |
786 std::string timezone_country = CountryCodeForCurrentTimezone(); | 786 std::string timezone_country = CountryCodeForCurrentTimezone(); |
787 if (!timezone_country.empty()) | 787 if (!timezone_country.empty()) |
788 country_codes.push_back(StringToLowerASCII(timezone_country)); | 788 country_codes.push_back(base::StringToLowerASCII(timezone_country)); |
789 | 789 |
790 // Only take the locale into consideration if all else fails. | 790 // Only take the locale into consideration if all else fails. |
791 if (country_codes.empty()) { | 791 if (country_codes.empty()) { |
792 country_codes.push_back(StringToLowerASCII( | 792 country_codes.push_back(base::StringToLowerASCII( |
793 AutofillCountry::CountryCodeForLocale(app_locale()))); | 793 AutofillCountry::CountryCodeForLocale(app_locale()))); |
794 } | 794 } |
795 | 795 |
796 return std::find(country_codes.begin(), country_codes.end(), | 796 return std::find(country_codes.begin(), country_codes.end(), |
797 StringToLowerASCII(country_code)) != country_codes.end(); | 797 base::StringToLowerASCII(country_code)) != |
| 798 country_codes.end(); |
798 } | 799 } |
799 | 800 |
800 const std::string& PersonalDataManager::GetDefaultCountryCodeForNewAddress() | 801 const std::string& PersonalDataManager::GetDefaultCountryCodeForNewAddress() |
801 const { | 802 const { |
802 if (default_country_code_.empty()) | 803 if (default_country_code_.empty()) |
803 default_country_code_ = MostCommonCountryCodeFromProfiles(); | 804 default_country_code_ = MostCommonCountryCodeFromProfiles(); |
804 | 805 |
805 // Failing that, guess based on system timezone. | 806 // Failing that, guess based on system timezone. |
806 if (default_country_code_.empty()) | 807 if (default_country_code_.empty()) |
807 default_country_code_ = CountryCodeForCurrentTimezone(); | 808 default_country_code_ = CountryCodeForCurrentTimezone(); |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 // Populates |auxiliary_profiles_|. | 1103 // Populates |auxiliary_profiles_|. |
1103 LoadAuxiliaryProfiles(record_metrics); | 1104 LoadAuxiliaryProfiles(record_metrics); |
1104 | 1105 |
1105 profiles_.insert(profiles_.end(), web_profiles_.begin(), web_profiles_.end()); | 1106 profiles_.insert(profiles_.end(), web_profiles_.begin(), web_profiles_.end()); |
1106 profiles_.insert( | 1107 profiles_.insert( |
1107 profiles_.end(), auxiliary_profiles_.begin(), auxiliary_profiles_.end()); | 1108 profiles_.end(), auxiliary_profiles_.begin(), auxiliary_profiles_.end()); |
1108 return profiles_; | 1109 return profiles_; |
1109 } | 1110 } |
1110 | 1111 |
1111 } // namespace autofill | 1112 } // namespace autofill |
OLD | NEW |