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 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 icons->push_back(base::UTF8ToUTF16(credit_card->type())); | 675 icons->push_back(base::UTF8ToUTF16(credit_card->type())); |
676 guid_pairs->push_back(GUIDPair(credit_card->guid(), 0)); | 676 guid_pairs->push_back(GUIDPair(credit_card->guid(), 0)); |
677 } | 677 } |
678 } | 678 } |
679 } | 679 } |
680 | 680 |
681 bool PersonalDataManager::IsAutofillEnabled() const { | 681 bool PersonalDataManager::IsAutofillEnabled() const { |
682 return pref_service_->GetBoolean(prefs::kAutofillEnabled); | 682 return pref_service_->GetBoolean(prefs::kAutofillEnabled); |
683 } | 683 } |
684 | 684 |
| 685 std::string PersonalDataManager::CountryCodeForCurrentTimezone() const { |
| 686 return base::CountryCodeForCurrentTimezone(); |
| 687 } |
| 688 |
685 // static | 689 // static |
686 bool PersonalDataManager::IsValidLearnableProfile( | 690 bool PersonalDataManager::IsValidLearnableProfile( |
687 const AutofillProfile& profile, | 691 const AutofillProfile& profile, |
688 const std::string& app_locale) { | 692 const std::string& app_locale) { |
689 if (!IsMinimumAddress(profile, app_locale)) | 693 if (!IsMinimumAddress(profile, app_locale)) |
690 return false; | 694 return false; |
691 | 695 |
692 base::string16 email = profile.GetRawInfo(EMAIL_ADDRESS); | 696 base::string16 email = profile.GetRawInfo(EMAIL_ADDRESS); |
693 if (!email.empty() && !IsValidEmailAddress(email)) | 697 if (!email.empty() && !IsValidEmailAddress(email)) |
694 return false; | 698 return false; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 merged_profiles->push_back(*existing_profile); | 742 merged_profiles->push_back(*existing_profile); |
739 } | 743 } |
740 | 744 |
741 // If the new profile was not merged with an existing one, add it to the list. | 745 // If the new profile was not merged with an existing one, add it to the list. |
742 if (!matching_profile_found) | 746 if (!matching_profile_found) |
743 merged_profiles->push_back(new_profile); | 747 merged_profiles->push_back(new_profile); |
744 | 748 |
745 return guid; | 749 return guid; |
746 } | 750 } |
747 | 751 |
| 752 bool PersonalDataManager::IsCountryOfInterest(const std::string& country_code) |
| 753 const { |
| 754 DCHECK_EQ(2U, country_code.size()); |
| 755 |
| 756 const std::vector<AutofillProfile*>& profiles = web_profiles(); |
| 757 std::list<std::string> country_codes; |
| 758 for (size_t i = 0; i < profiles.size(); ++i) { |
| 759 country_codes.push_back(StringToLowerASCII(UTF16ToASCII( |
| 760 profiles[i]->GetRawInfo(ADDRESS_HOME_COUNTRY)))); |
| 761 } |
| 762 |
| 763 std::string timezone_country = CountryCodeForCurrentTimezone(); |
| 764 if (!timezone_country.empty()) |
| 765 country_codes.push_back(StringToLowerASCII(timezone_country)); |
| 766 |
| 767 // Only take the locale into consideration if all else fails. |
| 768 if (country_codes.empty()) { |
| 769 country_codes.push_back(StringToLowerASCII( |
| 770 AutofillCountry::CountryCodeForLocale(app_locale()))); |
| 771 } |
| 772 |
| 773 return std::find(country_codes.begin(), country_codes.end(), |
| 774 StringToLowerASCII(country_code)) != country_codes.end(); |
| 775 } |
| 776 |
748 const std::string& PersonalDataManager::GetDefaultCountryCodeForNewAddress() | 777 const std::string& PersonalDataManager::GetDefaultCountryCodeForNewAddress() |
749 const { | 778 const { |
750 if (default_country_code_.empty()) | 779 if (default_country_code_.empty()) |
751 default_country_code_ = MostCommonCountryCodeFromProfiles(); | 780 default_country_code_ = MostCommonCountryCodeFromProfiles(); |
752 | 781 |
753 // Failing that, guess based on system timezone. | 782 // Failing that, guess based on system timezone. |
754 if (default_country_code_.empty()) | 783 if (default_country_code_.empty()) |
755 default_country_code_ = base::CountryCodeForCurrentTimezone(); | 784 default_country_code_ = CountryCodeForCurrentTimezone(); |
756 | 785 |
757 // Failing that, guess based on locale. | 786 // Failing that, guess based on locale. |
758 if (default_country_code_.empty()) | 787 if (default_country_code_.empty()) |
759 default_country_code_ = AutofillCountry::CountryCodeForLocale(app_locale()); | 788 default_country_code_ = AutofillCountry::CountryCodeForLocale(app_locale()); |
760 | 789 |
761 return default_country_code_; | 790 return default_country_code_; |
762 } | 791 } |
763 | 792 |
764 void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) { | 793 void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) { |
765 if (is_off_the_record_) | 794 if (is_off_the_record_) |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 if (!votes.empty()) { | 1046 if (!votes.empty()) { |
1018 std::map<std::string, int>::iterator iter = | 1047 std::map<std::string, int>::iterator iter = |
1019 std::max_element(votes.begin(), votes.end(), CompareVotes); | 1048 std::max_element(votes.begin(), votes.end(), CompareVotes); |
1020 return iter->first; | 1049 return iter->first; |
1021 } | 1050 } |
1022 | 1051 |
1023 return std::string(); | 1052 return std::string(); |
1024 } | 1053 } |
1025 | 1054 |
1026 } // namespace autofill | 1055 } // namespace autofill |
OLD | NEW |