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

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

Issue 176843022: Move UTF16ToASCII, remove WideToASCII. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // required as determined by its country code. 82 // required as determined by its country code.
83 // No verification of validity of the contents is preformed. This is an 83 // No verification of validity of the contents is preformed. This is an
84 // existence check only. 84 // existence check only.
85 bool IsMinimumAddress(const AutofillProfile& profile, 85 bool IsMinimumAddress(const AutofillProfile& profile,
86 const std::string& app_locale) { 86 const std::string& app_locale) {
87 // All countries require at least one address line. 87 // All countries require at least one address line.
88 if (profile.GetRawInfo(ADDRESS_HOME_LINE1).empty()) 88 if (profile.GetRawInfo(ADDRESS_HOME_LINE1).empty())
89 return false; 89 return false;
90 90
91 std::string country_code = 91 std::string country_code =
92 UTF16ToASCII(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)); 92 base::UTF16ToASCII(profile.GetRawInfo(ADDRESS_HOME_COUNTRY));
93 if (country_code.empty()) 93 if (country_code.empty())
94 country_code = AutofillCountry::CountryCodeForLocale(app_locale); 94 country_code = AutofillCountry::CountryCodeForLocale(app_locale);
95 95
96 AutofillCountry country(country_code, app_locale); 96 AutofillCountry country(country_code, app_locale);
97 97
98 if (country.requires_city() && profile.GetRawInfo(ADDRESS_HOME_CITY).empty()) 98 if (country.requires_city() && profile.GetRawInfo(ADDRESS_HOME_CITY).empty())
99 return false; 99 return false;
100 100
101 if (country.requires_state() && 101 if (country.requires_state() &&
102 profile.GetRawInfo(ADDRESS_HOME_STATE).empty()) 102 profile.GetRawInfo(ADDRESS_HOME_STATE).empty())
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 return guid; 763 return guid;
764 } 764 }
765 765
766 bool PersonalDataManager::IsCountryOfInterest(const std::string& country_code) 766 bool PersonalDataManager::IsCountryOfInterest(const std::string& country_code)
767 const { 767 const {
768 DCHECK_EQ(2U, country_code.size()); 768 DCHECK_EQ(2U, country_code.size());
769 769
770 const std::vector<AutofillProfile*>& profiles = web_profiles(); 770 const std::vector<AutofillProfile*>& profiles = web_profiles();
771 std::list<std::string> country_codes; 771 std::list<std::string> country_codes;
772 for (size_t i = 0; i < profiles.size(); ++i) { 772 for (size_t i = 0; i < profiles.size(); ++i) {
773 country_codes.push_back(StringToLowerASCII(UTF16ToASCII( 773 country_codes.push_back(StringToLowerASCII(base::UTF16ToASCII(
774 profiles[i]->GetRawInfo(ADDRESS_HOME_COUNTRY)))); 774 profiles[i]->GetRawInfo(ADDRESS_HOME_COUNTRY))));
775 } 775 }
776 776
777 std::string timezone_country = CountryCodeForCurrentTimezone(); 777 std::string timezone_country = CountryCodeForCurrentTimezone();
778 if (!timezone_country.empty()) 778 if (!timezone_country.empty())
779 country_codes.push_back(StringToLowerASCII(timezone_country)); 779 country_codes.push_back(StringToLowerASCII(timezone_country));
780 780
781 // Only take the locale into consideration if all else fails. 781 // Only take the locale into consideration if all else fails.
782 if (country_codes.empty()) { 782 if (country_codes.empty()) {
783 country_codes.push_back(StringToLowerASCII( 783 country_codes.push_back(StringToLowerASCII(
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 return std::string(); 1046 return std::string();
1047 1047
1048 // Count up country codes from existing profiles. 1048 // Count up country codes from existing profiles.
1049 std::map<std::string, int> votes; 1049 std::map<std::string, int> votes;
1050 // TODO(estade): can we make this GetProfiles() instead? It seems to cause 1050 // TODO(estade): can we make this GetProfiles() instead? It seems to cause
1051 // errors in tests on mac trybots. See http://crbug.com/57221 1051 // errors in tests on mac trybots. See http://crbug.com/57221
1052 const std::vector<AutofillProfile*>& profiles = web_profiles(); 1052 const std::vector<AutofillProfile*>& profiles = web_profiles();
1053 std::vector<std::string> country_codes; 1053 std::vector<std::string> country_codes;
1054 AutofillCountry::GetAvailableCountries(&country_codes); 1054 AutofillCountry::GetAvailableCountries(&country_codes);
1055 for (size_t i = 0; i < profiles.size(); ++i) { 1055 for (size_t i = 0; i < profiles.size(); ++i) {
1056 std::string country_code = StringToUpperASCII(UTF16ToASCII( 1056 std::string country_code = StringToUpperASCII(base::UTF16ToASCII(
1057 profiles[i]->GetRawInfo(ADDRESS_HOME_COUNTRY))); 1057 profiles[i]->GetRawInfo(ADDRESS_HOME_COUNTRY)));
1058 1058
1059 if (std::find(country_codes.begin(), country_codes.end(), country_code) != 1059 if (std::find(country_codes.begin(), country_codes.end(), country_code) !=
1060 country_codes.end()) { 1060 country_codes.end()) {
1061 // Verified profiles count 100x more than unverified ones. 1061 // Verified profiles count 100x more than unverified ones.
1062 votes[country_code] += profiles[i]->IsVerified() ? 100 : 1; 1062 votes[country_code] += profiles[i]->IsVerified() ? 100 : 1;
1063 } 1063 }
1064 } 1064 }
1065 1065
1066 // Take the most common country code. 1066 // Take the most common country code.
1067 if (!votes.empty()) { 1067 if (!votes.empty()) {
1068 std::map<std::string, int>::iterator iter = 1068 std::map<std::string, int>::iterator iter =
1069 std::max_element(votes.begin(), votes.end(), CompareVotes); 1069 std::max_element(votes.begin(), votes.end(), CompareVotes);
1070 return iter->first; 1070 return iter->first;
1071 } 1071 }
1072 1072
1073 return std::string(); 1073 return std::string();
1074 } 1074 }
1075 1075
1076 void PersonalDataManager::EnabledPrefChanged() { 1076 void PersonalDataManager::EnabledPrefChanged() {
1077 default_country_code_.clear(); 1077 default_country_code_.clear();
1078 NotifyPersonalDataChanged(); 1078 NotifyPersonalDataChanged();
1079 } 1079 }
1080 1080
1081 } // namespace autofill 1081 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_profile.cc ('k') | components/autofill/core/browser/phone_number.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698