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

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: Make StringCanonicalizer not a scoped_ptr. 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 const PersonalDataManager& manager, 26 const PersonalDataManager& manager,
24 const base::Callback<bool(const std::string&)>& filter) { 27 const base::Callback<bool(const std::string&)>& filter) {
25 // Insert the default country at the top as well as in the ordered list. 28 // Insert the default country at the top as well as in the ordered list.
26 std::string default_country_code = 29 std::string default_country_code =
27 manager.GetDefaultCountryCodeForNewAddress(); 30 manager.GetDefaultCountryCodeForNewAddress();
28 DCHECK(!default_country_code.empty()); 31 DCHECK(!default_country_code.empty());
29 32
30 const std::string& app_locale = g_browser_process->GetApplicationLocale(); 33 const std::string& app_locale = g_browser_process->GetApplicationLocale();
31 if (filter.is_null() || filter.Run(default_country_code)) { 34 if (filter.is_null() || filter.Run(default_country_code)) {
32 countries_.push_back(new AutofillCountry(default_country_code, app_locale)); 35 countries_.push_back(new AutofillCountry(default_country_code, app_locale));
33 // The separator item. 36 // The separator item.
34 countries_.push_back(NULL); 37 countries_.push_back(NULL);
35 } 38 }
36 39
37 // The sorted list of countries. 40 // The sorted list of countries.
38 #if defined(ENABLE_AUTOFILL_DIALOG)
39 const std::vector<std::string>& available_countries =
40 ::i18n::addressinput::GetRegionCodes();
41 #else
42 std::vector<std::string> available_countries; 41 std::vector<std::string> available_countries;
43 AutofillCountry::GetAvailableCountries(&available_countries); 42 AutofillCountry::GetAvailableCountries(&available_countries);
43
44 #if defined(ENABLE_AUTOFILL_DIALOG)
45 // Filter out the countries that do not have rules for address input and
46 // validation.
47 const std::vector<std::string>& addressinput_countries =
48 ::i18n::addressinput::GetRegionCodes();
49 std::vector<std::string> filtered_countries;
50 filtered_countries.reserve(available_countries.size());
51 std::set_intersection(available_countries.begin(),
52 available_countries.end(),
53 addressinput_countries.begin(),
54 addressinput_countries.end(),
55 std::back_inserter(filtered_countries));
56 available_countries.swap(filtered_countries);
44 #endif 57 #endif
45 58
46 std::vector<AutofillCountry*> sorted_countries; 59 std::vector<AutofillCountry*> sorted_countries;
47 for (std::vector<std::string>::const_iterator it = 60 for (std::vector<std::string>::const_iterator it =
48 available_countries.begin(); it != available_countries.end(); ++it) { 61 available_countries.begin(); it != available_countries.end(); ++it) {
49 if (filter.is_null() || filter.Run(*it)) 62 if (filter.is_null() || filter.Run(*it))
50 sorted_countries.push_back(new AutofillCountry(*it, app_locale)); 63 sorted_countries.push_back(new AutofillCountry(*it, app_locale));
51 } 64 }
52 65
53 l10n_util::SortStringsUsingMethod(app_locale, 66 l10n_util::SortStringsUsingMethod(app_locale,
(...skipping 22 matching lines...) Expand all
76 89
77 bool CountryComboboxModel::IsItemSeparatorAt(int index) { 90 bool CountryComboboxModel::IsItemSeparatorAt(int index) {
78 return !countries_[index]; 91 return !countries_[index];
79 } 92 }
80 93
81 std::string CountryComboboxModel::GetDefaultCountryCode() const { 94 std::string CountryComboboxModel::GetDefaultCountryCode() const {
82 return countries_[GetDefaultIndex()]->country_code(); 95 return countries_[GetDefaultIndex()]->country_code();
83 } 96 }
84 97
85 } // namespace autofill 98 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698