Chromium Code Reviews| Index: chrome/browser/ui/autofill/country_combobox_model.cc |
| diff --git a/chrome/browser/ui/autofill/country_combobox_model.cc b/chrome/browser/ui/autofill/country_combobox_model.cc |
| index 8962b8261f3ba65fcae4294481bf067cbabd097b..214dc84e1854000574824f1d49145cb5a1e2e854 100644 |
| --- a/chrome/browser/ui/autofill/country_combobox_model.cc |
| +++ b/chrome/browser/ui/autofill/country_combobox_model.cc |
| @@ -4,6 +4,7 @@ |
| #include "chrome/browser/ui/autofill/country_combobox_model.h" |
| +#include "base/logging.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "chrome/browser/browser_process.h" |
| #include "components/autofill/core/browser/autofill_country.h" |
| @@ -12,9 +13,10 @@ |
| namespace autofill { |
| -CountryComboboxModel::CountryComboboxModel(const PersonalDataManager& manager) { |
| +CountryComboboxModel::CountryComboboxModel(const PersonalDataManager& manager) |
| + : selected_index_(0) { |
| // Insert the default country at the top as well as in the ordered list. |
| - std::string app_locale = g_browser_process->GetApplicationLocale(); |
| + const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
| std::string default_country_code = |
| manager.GetDefaultCountryCodeForNewAddress(); |
| DCHECK(!default_country_code.empty()); |
| @@ -61,4 +63,55 @@ bool CountryComboboxModel::IsItemSeparatorAt(int index) { |
| return !countries_[index]; |
| } |
| +void CountryComboboxModel::SelectDefaultIndex() { |
| + SelectIndex(GetDefaultIndex()); |
| +} |
| + |
| +void CountryComboboxModel::SelectCountry(const std::string& country_code) { |
| + DCHECK_EQ(2U, country_code.length()); |
| + |
| + if (country_code == GetSelectedCountryCode()) |
|
Evan Stade
2014/01/14 17:19:38
redundant imo
|
| + return; |
| + |
| + for (size_t i = 0; i < countries_.size(); ++i) { |
| + if (countries_[i] && countries_[i]->country_code() == country_code) { |
| + SelectIndex(i); |
| + return; |
| + } |
| + } |
| + |
| + NOTREACHED(); |
| +} |
| + |
| +std::string CountryComboboxModel::GetSelectedCountryCode() const { |
| + return countries_[selected_index_]->country_code(); |
| +} |
| + |
| +bool CountryComboboxModel::IsDefaultIndexSelected() const { |
| + return selected_index_ == GetDefaultIndex(); |
| +} |
| + |
| +void CountryComboboxModel::AddCountryComboboxObserver( |
| + CountryComboboxModelObserver* observer) { |
| + observers_.AddObserver(observer); |
| +} |
| + |
| +void CountryComboboxModel::RemoveCountryComboboxObserver( |
| + CountryComboboxModelObserver* observer) { |
| + observers_.RemoveObserver(observer); |
| +} |
| + |
| +void CountryComboboxModel::SelectIndex(int index) { |
| + if (selected_index_ == index) |
| + return; |
| + |
| + DCHECK_GE(index, 0); |
|
Evan Stade
2014/01/14 17:19:38
why do these dchecks come after the identity check
Dan Beam
2014/01/15 03:10:48
selected_index_ should always be valid, so index s
|
| + DCHECK_LT(index, static_cast<int>(countries_.size())); |
| + DCHECK(!IsItemSeparatorAt(index)); |
| + |
| + selected_index_ = index; |
| + FOR_EACH_OBSERVER(CountryComboboxModelObserver, observers_, |
| + OnCountryComboboxModelChanged(this)); |
| +} |
| + |
| } // namespace autofill |