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

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

Issue 2705773002: [Autofill] Move country combo box model from chrome to component. (Closed)
Patch Set: Created 3 years, 10 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
OLDNEW
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 "components/autofill/core/browser/country_combobox_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <utility>
9 10
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "build/build_config.h" 14 #include "build/build_config.h"
Mathieu 2017/02/21 00:57:19 unused?
MAD 2017/02/21 15:56:18 Done.
14 #include "chrome/browser/browser_process.h"
15 #include "components/autofill/core/browser/autofill_country.h" 15 #include "components/autofill/core/browser/autofill_country.h"
16 #include "components/autofill/core/browser/country_data.h" 16 #include "components/autofill/core/browser/country_data.h"
17 #include "components/autofill/core/browser/personal_data_manager.h" 17 #include "components/autofill/core/browser/personal_data_manager.h"
18 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui .h" 18 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui .h"
19 #include "ui/base/l10n/l10n_util_collator.h" 19 #include "ui/base/l10n/l10n_util_collator.h"
20 #include "ui/base/models/combobox_model_observer.h" 20 #include "ui/base/models/combobox_model_observer.h"
21 21
22 namespace autofill { 22 namespace autofill {
23 23
24 CountryComboboxModel::CountryComboboxModel() {} 24 CountryComboboxModel::CountryComboboxModel() {}
25 25
26 CountryComboboxModel::~CountryComboboxModel() {} 26 CountryComboboxModel::~CountryComboboxModel() {}
27 27
28 void CountryComboboxModel::SetCountries( 28 void CountryComboboxModel::SetCountries(
29 const PersonalDataManager& manager, 29 const PersonalDataManager& manager,
30 const base::Callback<bool(const std::string&)>& filter) { 30 const base::Callback<bool(const std::string&)>& filter,
31 const std::string& app_locale) {
31 countries_.clear(); 32 countries_.clear();
32 33
33 // Insert the default country at the top as well as in the ordered list. 34 // Insert the default country at the top as well as in the ordered list.
34 std::string default_country_code = 35 std::string default_country_code =
35 manager.GetDefaultCountryCodeForNewAddress(); 36 manager.GetDefaultCountryCodeForNewAddress();
36 DCHECK(!default_country_code.empty()); 37 DCHECK(!default_country_code.empty());
37 38
38 const std::string& app_locale = g_browser_process->GetApplicationLocale();
39 if (filter.is_null() || filter.Run(default_country_code)) { 39 if (filter.is_null() || filter.Run(default_country_code)) {
40 countries_.push_back( 40 countries_.push_back(
41 base::MakeUnique<AutofillCountry>(default_country_code, app_locale)); 41 base::MakeUnique<AutofillCountry>(default_country_code, app_locale));
42 #if !defined(OS_ANDROID) 42 #if !defined(OS_ANDROID)
43 // The separator item. On Android, there are separators after all items, so 43 // The separator item. On Android, there are separators after all items, so
44 // this is unnecessary. 44 // this is unnecessary.
45 countries_.push_back(nullptr); 45 countries_.push_back(nullptr);
46 #endif 46 #endif
47 } 47 }
48 48
(...skipping 13 matching lines...) Expand all
62 std::back_inserter(filtered_countries)); 62 std::back_inserter(filtered_countries));
63 available_countries = &filtered_countries; 63 available_countries = &filtered_countries;
64 64
65 CountryVector sorted_countries; 65 CountryVector sorted_countries;
66 for (const auto& country_code : *available_countries) { 66 for (const auto& country_code : *available_countries) {
67 if (filter.is_null() || filter.Run(country_code)) 67 if (filter.is_null() || filter.Run(country_code))
68 sorted_countries.push_back( 68 sorted_countries.push_back(
69 base::MakeUnique<AutofillCountry>(country_code, app_locale)); 69 base::MakeUnique<AutofillCountry>(country_code, app_locale));
70 } 70 }
71 71
72 l10n_util::SortStringsUsingMethod(app_locale, 72 l10n_util::SortStringsUsingMethod(app_locale, &sorted_countries,
73 &sorted_countries,
74 &AutofillCountry::name); 73 &AutofillCountry::name);
75 std::move(sorted_countries.begin(), sorted_countries.end(), 74 std::move(sorted_countries.begin(), sorted_countries.end(),
76 std::back_inserter(countries_)); 75 std::back_inserter(countries_));
77 } 76 }
78 77
79 int CountryComboboxModel::GetItemCount() const { 78 int CountryComboboxModel::GetItemCount() const {
80 return countries_.size(); 79 return countries_.size();
81 } 80 }
82 81
83 base::string16 CountryComboboxModel::GetItemAt(int index) { 82 base::string16 CountryComboboxModel::GetItemAt(int index) {
84 AutofillCountry* country = countries_[index].get(); 83 AutofillCountry* country = countries_[index].get();
85 if (country) 84 if (country)
86 return countries_[index]->name(); 85 return countries_[index]->name();
87 86
88 // The separator item. Implemented for platforms that don't yet support 87 // The separator item. Implemented for platforms that don't yet support
89 // IsItemSeparatorAt(). 88 // IsItemSeparatorAt().
90 return base::ASCIIToUTF16("---"); 89 return base::ASCIIToUTF16("---");
91 } 90 }
92 91
93 bool CountryComboboxModel::IsItemSeparatorAt(int index) { 92 bool CountryComboboxModel::IsItemSeparatorAt(int index) {
94 return !countries_[index].get(); 93 return !countries_[index].get();
95 } 94 }
96 95
97 std::string CountryComboboxModel::GetDefaultCountryCode() const { 96 std::string CountryComboboxModel::GetDefaultCountryCode() const {
98 return countries_[GetDefaultIndex()]->country_code(); 97 return countries_[GetDefaultIndex()]->country_code();
99 } 98 }
100 99
101 } // namespace autofill 100 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698