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()); | |
Dan Beam
2014/01/02 22:10:39
nit: check that country_code is valid (not just 2
Evan Stade
2014/01/02 22:23:16
I think this is overkill, I was mainly just worrie
| |
755 | |
756 const std::vector<AutofillProfile*>& profiles = web_profiles(); | |
Dan Beam
2014/01/02 22:10:39
^ what about auxiliary profiles? (i.e. why not Get
Evan Stade
2014/01/02 22:23:16
because that causes mac to hang sometimes
Dan Beam
2014/01/02 22:30:37
this means we're ignoring additional data sources
Evan Stade
2014/01/02 22:36:15
yes, unfortunately.
| |
757 std::list<std::string> country_codes; | |
758 for (size_t i = 0; i < profiles.size(); ++i) { | |
759 country_codes.push_back(StringToLowerASCII(UTF16ToASCII( | |
Dan Beam
2014/01/02 22:10:39
^ all UTF conversion functions need to have base::
Evan Stade
2014/01/02 22:23:16
are you sure about that? These functions don't app
Dan Beam
2014/01/02 22:30:37
i'll let you and the compiler reconcile this.
Dan Beam
2014/01/02 22:35:27
nvm, yep, sorry, avi@ didn't change this
| |
760 profiles[i]->GetRawInfo(ADDRESS_HOME_COUNTRY)))); | |
761 } | |
762 country_codes.push_back(StringToLowerASCII( | |
763 CountryCodeForCurrentTimezone())); | |
764 | |
765 return std::find(country_codes.begin(), country_codes.end(), | |
766 StringToLowerASCII(country_code)) != country_codes.end(); | |
767 } | |
768 | |
748 const std::string& PersonalDataManager::GetDefaultCountryCodeForNewAddress() | 769 const std::string& PersonalDataManager::GetDefaultCountryCodeForNewAddress() |
749 const { | 770 const { |
750 if (default_country_code_.empty()) | 771 if (default_country_code_.empty()) |
751 default_country_code_ = MostCommonCountryCodeFromProfiles(); | 772 default_country_code_ = MostCommonCountryCodeFromProfiles(); |
752 | 773 |
753 // Failing that, guess based on system timezone. | 774 // Failing that, guess based on system timezone. |
754 if (default_country_code_.empty()) | 775 if (default_country_code_.empty()) |
755 default_country_code_ = base::CountryCodeForCurrentTimezone(); | 776 default_country_code_ = CountryCodeForCurrentTimezone(); |
756 | 777 |
757 // Failing that, guess based on locale. | 778 // Failing that, guess based on locale. |
758 if (default_country_code_.empty()) | 779 if (default_country_code_.empty()) |
759 default_country_code_ = AutofillCountry::CountryCodeForLocale(app_locale()); | 780 default_country_code_ = AutofillCountry::CountryCodeForLocale(app_locale()); |
760 | 781 |
761 return default_country_code_; | 782 return default_country_code_; |
762 } | 783 } |
763 | 784 |
764 void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) { | 785 void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) { |
765 if (is_off_the_record_) | 786 if (is_off_the_record_) |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1017 if (!votes.empty()) { | 1038 if (!votes.empty()) { |
1018 std::map<std::string, int>::iterator iter = | 1039 std::map<std::string, int>::iterator iter = |
1019 std::max_element(votes.begin(), votes.end(), CompareVotes); | 1040 std::max_element(votes.begin(), votes.end(), CompareVotes); |
1020 return iter->first; | 1041 return iter->first; |
1021 } | 1042 } |
1022 | 1043 |
1023 return std::string(); | 1044 return std::string(); |
1024 } | 1045 } |
1025 | 1046 |
1026 } // namespace autofill | 1047 } // namespace autofill |
OLD | NEW |