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

Side by Side Diff: chrome/browser/ui/autofill/country_combobox_model.cc

Issue 298863012: Use upstream libaddressinput in Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows compile. Created 6 years, 5 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 (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>
8 #include <iterator>
9
7 #include "base/logging.h" 10 #include "base/logging.h"
8 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
10 #include "components/autofill/core/browser/autofill_country.h" 13 #include "components/autofill/core/browser/autofill_country.h"
11 #include "components/autofill/core/browser/personal_data_manager.h" 14 #include "components/autofill/core/browser/personal_data_manager.h"
12 #include "ui/base/l10n/l10n_util_collator.h" 15 #include "ui/base/l10n/l10n_util_collator.h"
13 #include "ui/base/models/combobox_model_observer.h" 16 #include "ui/base/models/combobox_model_observer.h"
14 17
15 // TODO(rouslan): Remove this check. http://crbug.com/337587 18 // TODO(rouslan): Remove this check. http://crbug.com/337587
16 #if defined(ENABLE_AUTOFILL_DIALOG) 19 #if defined(ENABLE_AUTOFILL_DIALOG)
17 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_ui.h" 20 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui .h"
18 #endif 21 #endif
19 22
20 namespace autofill { 23 namespace autofill {
21 24
22 CountryComboboxModel::CountryComboboxModel() {} 25 CountryComboboxModel::CountryComboboxModel() {}
23 26
24 CountryComboboxModel::~CountryComboboxModel() {} 27 CountryComboboxModel::~CountryComboboxModel() {}
25 28
26 void CountryComboboxModel::SetCountries( 29 void CountryComboboxModel::SetCountries(
27 const PersonalDataManager& manager, 30 const PersonalDataManager& manager,
28 const base::Callback<bool(const std::string&)>& filter) { 31 const base::Callback<bool(const std::string&)>& filter) {
29 countries_.clear(); 32 countries_.clear();
30 33
31 // 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.
32 std::string default_country_code = 35 std::string default_country_code =
33 manager.GetDefaultCountryCodeForNewAddress(); 36 manager.GetDefaultCountryCodeForNewAddress();
34 DCHECK(!default_country_code.empty()); 37 DCHECK(!default_country_code.empty());
35 38
36 const std::string& app_locale = g_browser_process->GetApplicationLocale(); 39 const std::string& app_locale = g_browser_process->GetApplicationLocale();
37 if (filter.is_null() || filter.Run(default_country_code)) { 40 if (filter.is_null() || filter.Run(default_country_code)) {
38 countries_.push_back(new AutofillCountry(default_country_code, app_locale)); 41 countries_.push_back(new AutofillCountry(default_country_code, app_locale));
39 // The separator item. 42 // The separator item.
40 countries_.push_back(NULL); 43 countries_.push_back(NULL);
41 } 44 }
42 45
43 // The sorted list of countries. 46 // The sorted list of countries.
44 #if defined(ENABLE_AUTOFILL_DIALOG)
45 const std::vector<std::string>& available_countries =
46 ::i18n::addressinput::GetRegionCodes();
47 #else
48 std::vector<std::string> available_countries; 47 std::vector<std::string> available_countries;
49 AutofillCountry::GetAvailableCountries(&available_countries); 48 AutofillCountry::GetAvailableCountries(&available_countries);
49
50 #if defined(ENABLE_AUTOFILL_DIALOG)
51 // Filter out the countries that do not have rules for address input and
52 // validation.
53 const std::vector<std::string>& addressinput_countries =
54 ::i18n::addressinput::GetRegionCodes();
55 std::vector<std::string> filtered_countries;
56 filtered_countries.reserve(available_countries.size());
57 std::set_intersection(available_countries.begin(),
58 available_countries.end(),
59 addressinput_countries.begin(),
60 addressinput_countries.end(),
61 std::back_inserter(filtered_countries));
62 available_countries.swap(filtered_countries);
50 #endif 63 #endif
51 64
52 std::vector<AutofillCountry*> sorted_countries; 65 std::vector<AutofillCountry*> sorted_countries;
53 for (std::vector<std::string>::const_iterator it = 66 for (std::vector<std::string>::const_iterator it =
54 available_countries.begin(); it != available_countries.end(); ++it) { 67 available_countries.begin(); it != available_countries.end(); ++it) {
55 if (filter.is_null() || filter.Run(*it)) 68 if (filter.is_null() || filter.Run(*it))
56 sorted_countries.push_back(new AutofillCountry(*it, app_locale)); 69 sorted_countries.push_back(new AutofillCountry(*it, app_locale));
57 } 70 }
58 71
59 l10n_util::SortStringsUsingMethod(app_locale, 72 l10n_util::SortStringsUsingMethod(app_locale,
(...skipping 20 matching lines...) Expand all
80 93
81 bool CountryComboboxModel::IsItemSeparatorAt(int index) { 94 bool CountryComboboxModel::IsItemSeparatorAt(int index) {
82 return !countries_[index]; 95 return !countries_[index];
83 } 96 }
84 97
85 std::string CountryComboboxModel::GetDefaultCountryCode() const { 98 std::string CountryComboboxModel::GetDefaultCountryCode() const {
86 return countries_[GetDefaultIndex()]->country_code(); 99 return countries_[GetDefaultIndex()]->country_code();
87 } 100 }
88 101
89 } // namespace autofill 102 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698