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> |
11 #include <map> | 11 #include <map> |
12 #include <string> | 12 #include <string> |
13 #include <utility> | 13 #include <utility> |
14 | 14 |
15 #include "base/i18n/case_conversion.h" | 15 #include "base/i18n/case_conversion.h" |
16 #include "base/i18n/timezone.h" | 16 #include "base/i18n/timezone.h" |
17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
18 #include "base/profiler/scoped_tracker.h" | 18 #include "base/profiler/scoped_tracker.h" |
| 19 #include "base/stl_util.h" |
19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
21 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
22 #include "build/build_config.h" | 23 #include "build/build_config.h" |
23 #include "components/autofill/core/browser/address_i18n.h" | 24 #include "components/autofill/core/browser/address_i18n.h" |
24 #include "components/autofill/core/browser/autofill-inl.h" | 25 #include "components/autofill/core/browser/autofill-inl.h" |
25 #include "components/autofill/core/browser/autofill_country.h" | 26 #include "components/autofill/core/browser/autofill_country.h" |
26 #include "components/autofill/core/browser/autofill_experiments.h" | 27 #include "components/autofill/core/browser/autofill_experiments.h" |
27 #include "components/autofill/core/browser/autofill_field.h" | 28 #include "components/autofill/core/browser/autofill_field.h" |
28 #include "components/autofill/core/browser/autofill_metrics.h" | 29 #include "components/autofill/core/browser/autofill_metrics.h" |
(...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 std::string timezone_country = CountryCodeForCurrentTimezone(); | 1109 std::string timezone_country = CountryCodeForCurrentTimezone(); |
1109 if (!timezone_country.empty()) | 1110 if (!timezone_country.empty()) |
1110 country_codes.push_back(base::ToLowerASCII(timezone_country)); | 1111 country_codes.push_back(base::ToLowerASCII(timezone_country)); |
1111 | 1112 |
1112 // Only take the locale into consideration if all else fails. | 1113 // Only take the locale into consideration if all else fails. |
1113 if (country_codes.empty()) { | 1114 if (country_codes.empty()) { |
1114 country_codes.push_back(base::ToLowerASCII( | 1115 country_codes.push_back(base::ToLowerASCII( |
1115 AutofillCountry::CountryCodeForLocale(app_locale()))); | 1116 AutofillCountry::CountryCodeForLocale(app_locale()))); |
1116 } | 1117 } |
1117 | 1118 |
1118 return std::find(country_codes.begin(), country_codes.end(), | 1119 return base::ContainsValue(country_codes, base::ToLowerASCII(country_code)); |
1119 base::ToLowerASCII(country_code)) != country_codes.end(); | |
1120 } | 1120 } |
1121 | 1121 |
1122 const std::string& PersonalDataManager::GetDefaultCountryCodeForNewAddress() | 1122 const std::string& PersonalDataManager::GetDefaultCountryCodeForNewAddress() |
1123 const { | 1123 const { |
1124 if (default_country_code_.empty()) | 1124 if (default_country_code_.empty()) |
1125 default_country_code_ = MostCommonCountryCodeFromProfiles(); | 1125 default_country_code_ = MostCommonCountryCodeFromProfiles(); |
1126 | 1126 |
1127 // Failing that, guess based on system timezone. | 1127 // Failing that, guess based on system timezone. |
1128 if (default_country_code_.empty()) | 1128 if (default_country_code_.empty()) |
1129 default_country_code_ = CountryCodeForCurrentTimezone(); | 1129 default_country_code_ = CountryCodeForCurrentTimezone(); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1377 std::map<std::string, int> votes; | 1377 std::map<std::string, int> votes; |
1378 // TODO(estade): can we make this GetProfiles() instead? It seems to cause | 1378 // TODO(estade): can we make this GetProfiles() instead? It seems to cause |
1379 // errors in tests on mac trybots. See http://crbug.com/57221 | 1379 // errors in tests on mac trybots. See http://crbug.com/57221 |
1380 const std::vector<AutofillProfile*>& profiles = web_profiles(); | 1380 const std::vector<AutofillProfile*>& profiles = web_profiles(); |
1381 const std::vector<std::string>& country_codes = | 1381 const std::vector<std::string>& country_codes = |
1382 CountryDataMap::GetInstance()->country_codes(); | 1382 CountryDataMap::GetInstance()->country_codes(); |
1383 for (size_t i = 0; i < profiles.size(); ++i) { | 1383 for (size_t i = 0; i < profiles.size(); ++i) { |
1384 std::string country_code = base::ToUpperASCII(base::UTF16ToASCII( | 1384 std::string country_code = base::ToUpperASCII(base::UTF16ToASCII( |
1385 profiles[i]->GetRawInfo(ADDRESS_HOME_COUNTRY))); | 1385 profiles[i]->GetRawInfo(ADDRESS_HOME_COUNTRY))); |
1386 | 1386 |
1387 if (std::find(country_codes.begin(), country_codes.end(), country_code) != | 1387 if (base::ContainsValue(country_codes, country_code)) { |
1388 country_codes.end()) { | |
1389 // Verified profiles count 100x more than unverified ones. | 1388 // Verified profiles count 100x more than unverified ones. |
1390 votes[country_code] += profiles[i]->IsVerified() ? 100 : 1; | 1389 votes[country_code] += profiles[i]->IsVerified() ? 100 : 1; |
1391 } | 1390 } |
1392 } | 1391 } |
1393 | 1392 |
1394 // Take the most common country code. | 1393 // Take the most common country code. |
1395 if (!votes.empty()) { | 1394 if (!votes.empty()) { |
1396 std::map<std::string, int>::iterator iter = | 1395 std::map<std::string, int>::iterator iter = |
1397 std::max_element(votes.begin(), votes.end(), CompareVotes); | 1396 std::max_element(votes.begin(), votes.end(), CompareVotes); |
1398 return iter->first; | 1397 return iter->first; |
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2076 existing_profiles->back().SetRawInfo(EMAIL_ADDRESS, email); | 2075 existing_profiles->back().SetRawInfo(EMAIL_ADDRESS, email); |
2077 | 2076 |
2078 AutofillMetrics::LogWalletAddressConversionType( | 2077 AutofillMetrics::LogWalletAddressConversionType( |
2079 AutofillMetrics::CONVERTED_ADDRESS_ADDED); | 2078 AutofillMetrics::CONVERTED_ADDRESS_ADDED); |
2080 } | 2079 } |
2081 | 2080 |
2082 return guid; | 2081 return guid; |
2083 } | 2082 } |
2084 | 2083 |
2085 } // namespace autofill | 2084 } // namespace autofill |
OLD | NEW |