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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <list> | 10 #include <list> |
(...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1108 std::string timezone_country = CountryCodeForCurrentTimezone(); | 1108 std::string timezone_country = CountryCodeForCurrentTimezone(); |
1109 if (!timezone_country.empty()) | 1109 if (!timezone_country.empty()) |
1110 country_codes.push_back(base::ToLowerASCII(timezone_country)); | 1110 country_codes.push_back(base::ToLowerASCII(timezone_country)); |
1111 | 1111 |
1112 // Only take the locale into consideration if all else fails. | 1112 // Only take the locale into consideration if all else fails. |
1113 if (country_codes.empty()) { | 1113 if (country_codes.empty()) { |
1114 country_codes.push_back(base::ToLowerASCII( | 1114 country_codes.push_back(base::ToLowerASCII( |
1115 AutofillCountry::CountryCodeForLocale(app_locale()))); | 1115 AutofillCountry::CountryCodeForLocale(app_locale()))); |
1116 } | 1116 } |
1117 | 1117 |
1118 return std::find(country_codes.begin(), country_codes.end(), | 1118 return base::ContainsValue(country_codes, base::ToLowerASCII(country_code)); |
vabr (Chromium)
2017/07/09 18:23:59
Please also #include "base/stl_util.h" in this fil
deejay
2017/07/10 03:47:16
Done.
| |
1119 base::ToLowerASCII(country_code)) != country_codes.end(); | |
1120 } | 1119 } |
1121 | 1120 |
1122 const std::string& PersonalDataManager::GetDefaultCountryCodeForNewAddress() | 1121 const std::string& PersonalDataManager::GetDefaultCountryCodeForNewAddress() |
1123 const { | 1122 const { |
1124 if (default_country_code_.empty()) | 1123 if (default_country_code_.empty()) |
1125 default_country_code_ = MostCommonCountryCodeFromProfiles(); | 1124 default_country_code_ = MostCommonCountryCodeFromProfiles(); |
1126 | 1125 |
1127 // Failing that, guess based on system timezone. | 1126 // Failing that, guess based on system timezone. |
1128 if (default_country_code_.empty()) | 1127 if (default_country_code_.empty()) |
1129 default_country_code_ = CountryCodeForCurrentTimezone(); | 1128 default_country_code_ = CountryCodeForCurrentTimezone(); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1377 std::map<std::string, int> votes; | 1376 std::map<std::string, int> votes; |
1378 // TODO(estade): can we make this GetProfiles() instead? It seems to cause | 1377 // TODO(estade): can we make this GetProfiles() instead? It seems to cause |
1379 // errors in tests on mac trybots. See http://crbug.com/57221 | 1378 // errors in tests on mac trybots. See http://crbug.com/57221 |
1380 const std::vector<AutofillProfile*>& profiles = web_profiles(); | 1379 const std::vector<AutofillProfile*>& profiles = web_profiles(); |
1381 const std::vector<std::string>& country_codes = | 1380 const std::vector<std::string>& country_codes = |
1382 CountryDataMap::GetInstance()->country_codes(); | 1381 CountryDataMap::GetInstance()->country_codes(); |
1383 for (size_t i = 0; i < profiles.size(); ++i) { | 1382 for (size_t i = 0; i < profiles.size(); ++i) { |
1384 std::string country_code = base::ToUpperASCII(base::UTF16ToASCII( | 1383 std::string country_code = base::ToUpperASCII(base::UTF16ToASCII( |
1385 profiles[i]->GetRawInfo(ADDRESS_HOME_COUNTRY))); | 1384 profiles[i]->GetRawInfo(ADDRESS_HOME_COUNTRY))); |
1386 | 1385 |
1387 if (std::find(country_codes.begin(), country_codes.end(), country_code) != | 1386 if (base::ContainsValue(country_codes, country_code)) { |
1388 country_codes.end()) { | |
1389 // Verified profiles count 100x more than unverified ones. | 1387 // Verified profiles count 100x more than unverified ones. |
1390 votes[country_code] += profiles[i]->IsVerified() ? 100 : 1; | 1388 votes[country_code] += profiles[i]->IsVerified() ? 100 : 1; |
1391 } | 1389 } |
1392 } | 1390 } |
1393 | 1391 |
1394 // Take the most common country code. | 1392 // Take the most common country code. |
1395 if (!votes.empty()) { | 1393 if (!votes.empty()) { |
1396 std::map<std::string, int>::iterator iter = | 1394 std::map<std::string, int>::iterator iter = |
1397 std::max_element(votes.begin(), votes.end(), CompareVotes); | 1395 std::max_element(votes.begin(), votes.end(), CompareVotes); |
1398 return iter->first; | 1396 return iter->first; |
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2076 existing_profiles->back().SetRawInfo(EMAIL_ADDRESS, email); | 2074 existing_profiles->back().SetRawInfo(EMAIL_ADDRESS, email); |
2077 | 2075 |
2078 AutofillMetrics::LogWalletAddressConversionType( | 2076 AutofillMetrics::LogWalletAddressConversionType( |
2079 AutofillMetrics::CONVERTED_ADDRESS_ADDED); | 2077 AutofillMetrics::CONVERTED_ADDRESS_ADDED); |
2080 } | 2078 } |
2081 | 2079 |
2082 return guid; | 2080 return guid; |
2083 } | 2081 } |
2084 | 2082 |
2085 } // namespace autofill | 2083 } // namespace autofill |
OLD | NEW |