OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/autofill/country_combobox_model.h" | 5 #include "chrome/browser/ui/autofill/country_combobox_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "components/autofill/core/browser/autofill_country.h" | 14 #include "components/autofill/core/browser/autofill_country.h" |
15 #include "components/autofill/core/browser/country_data.h" | 15 #include "components/autofill/core/browser/country_data.h" |
16 #include "components/autofill/core/browser/personal_data_manager.h" | 16 #include "components/autofill/core/browser/personal_data_manager.h" |
| 17 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
.h" |
17 #include "ui/base/l10n/l10n_util_collator.h" | 18 #include "ui/base/l10n/l10n_util_collator.h" |
18 #include "ui/base/models/combobox_model_observer.h" | 19 #include "ui/base/models/combobox_model_observer.h" |
19 | 20 |
20 // TODO(rouslan): Remove this check. http://crbug.com/337587 | |
21 #if defined(ENABLE_AUTOFILL_DIALOG) | |
22 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
.h" | |
23 #endif | |
24 | |
25 namespace autofill { | 21 namespace autofill { |
26 | 22 |
27 CountryComboboxModel::CountryComboboxModel() {} | 23 CountryComboboxModel::CountryComboboxModel() {} |
28 | 24 |
29 CountryComboboxModel::~CountryComboboxModel() {} | 25 CountryComboboxModel::~CountryComboboxModel() {} |
30 | 26 |
31 void CountryComboboxModel::SetCountries( | 27 void CountryComboboxModel::SetCountries( |
32 const PersonalDataManager& manager, | 28 const PersonalDataManager& manager, |
33 const base::Callback<bool(const std::string&)>& filter) { | 29 const base::Callback<bool(const std::string&)>& filter) { |
34 countries_.clear(); | 30 countries_.clear(); |
(...skipping 10 matching lines...) Expand all Loading... |
45 // The separator item. On Android, there are separators after all items, so | 41 // The separator item. On Android, there are separators after all items, so |
46 // this is unnecessary. | 42 // this is unnecessary. |
47 countries_.push_back(NULL); | 43 countries_.push_back(NULL); |
48 #endif | 44 #endif |
49 } | 45 } |
50 | 46 |
51 // The sorted list of country codes. | 47 // The sorted list of country codes. |
52 const std::vector<std::string>* available_countries = | 48 const std::vector<std::string>* available_countries = |
53 &CountryDataMap::GetInstance()->country_codes(); | 49 &CountryDataMap::GetInstance()->country_codes(); |
54 | 50 |
55 #if defined(ENABLE_AUTOFILL_DIALOG) | |
56 // Filter out the countries that do not have rules for address input and | 51 // Filter out the countries that do not have rules for address input and |
57 // validation. | 52 // validation. |
58 const std::vector<std::string>& addressinput_countries = | 53 const std::vector<std::string>& addressinput_countries = |
59 ::i18n::addressinput::GetRegionCodes(); | 54 ::i18n::addressinput::GetRegionCodes(); |
60 std::vector<std::string> filtered_countries; | 55 std::vector<std::string> filtered_countries; |
61 filtered_countries.reserve(available_countries->size()); | 56 filtered_countries.reserve(available_countries->size()); |
62 std::set_intersection( | 57 std::set_intersection( |
63 available_countries->begin(), available_countries->end(), | 58 available_countries->begin(), available_countries->end(), |
64 addressinput_countries.begin(), addressinput_countries.end(), | 59 addressinput_countries.begin(), addressinput_countries.end(), |
65 std::back_inserter(filtered_countries)); | 60 std::back_inserter(filtered_countries)); |
66 available_countries = &filtered_countries; | 61 available_countries = &filtered_countries; |
67 #endif | |
68 | 62 |
69 std::vector<AutofillCountry*> sorted_countries; | 63 std::vector<AutofillCountry*> sorted_countries; |
70 for (const auto& country_code : *available_countries) { | 64 for (const auto& country_code : *available_countries) { |
71 if (filter.is_null() || filter.Run(country_code)) | 65 if (filter.is_null() || filter.Run(country_code)) |
72 sorted_countries.push_back(new AutofillCountry(country_code, app_locale)); | 66 sorted_countries.push_back(new AutofillCountry(country_code, app_locale)); |
73 } | 67 } |
74 | 68 |
75 l10n_util::SortStringsUsingMethod(app_locale, | 69 l10n_util::SortStringsUsingMethod(app_locale, |
76 &sorted_countries, | 70 &sorted_countries, |
77 &AutofillCountry::name); | 71 &AutofillCountry::name); |
(...skipping 18 matching lines...) Expand all Loading... |
96 | 90 |
97 bool CountryComboboxModel::IsItemSeparatorAt(int index) { | 91 bool CountryComboboxModel::IsItemSeparatorAt(int index) { |
98 return !countries_[index]; | 92 return !countries_[index]; |
99 } | 93 } |
100 | 94 |
101 std::string CountryComboboxModel::GetDefaultCountryCode() const { | 95 std::string CountryComboboxModel::GetDefaultCountryCode() const { |
102 return countries_[GetDefaultIndex()]->country_code(); | 96 return countries_[GetDefaultIndex()]->country_code(); |
103 } | 97 } |
104 | 98 |
105 } // namespace autofill | 99 } // namespace autofill |
OLD | NEW |