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..707b76fabe3a73d173aaacf1afbd2ea0eef4565d 100644 |
--- a/chrome/browser/ui/autofill/country_combobox_model.cc |
+++ b/chrome/browser/ui/autofill/country_combobox_model.cc |
@@ -4,17 +4,20 @@ |
#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" |
#include "components/autofill/core/browser/personal_data_manager.h" |
#include "ui/base/l10n/l10n_util_collator.h" |
+#include "ui/base/models/combobox_model_observer.h" |
namespace autofill { |
-CountryComboboxModel::CountryComboboxModel(const PersonalDataManager& manager) { |
+CountryComboboxModel::CountryComboboxModel(const PersonalDataManager& manager) |
+ : default_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 +64,50 @@ bool CountryComboboxModel::IsItemSeparatorAt(int index) { |
return !countries_[index]; |
} |
+int CountryComboboxModel::GetDefaultIndex() const { |
+ return default_index_; |
+} |
+ |
+void CountryComboboxModel::AddObserver(ui::ComboboxModelObserver* observer) { |
+ observers_.AddObserver(observer); |
+} |
+ |
+void CountryComboboxModel::RemoveObserver(ui::ComboboxModelObserver* observer) { |
+ observers_.RemoveObserver(observer); |
+} |
+ |
+void CountryComboboxModel::ResetDefault() { |
+ SetDefaultIndex(0); |
+} |
+ |
+void CountryComboboxModel::SetDefaultCountry(const std::string& country_code) { |
+ DCHECK_EQ(2U, country_code.length()); |
+ |
+ for (size_t i = 0; i < countries_.size(); ++i) { |
+ if (countries_[i] && countries_[i]->country_code() == country_code) { |
+ SetDefaultIndex(i); |
+ return; |
+ } |
+ } |
+ |
+ NOTREACHED(); |
+} |
+ |
+std::string CountryComboboxModel::GetDefaultCountryCode() const { |
+ return countries_[default_index_]->country_code(); |
+} |
+ |
+void CountryComboboxModel::SetDefaultIndex(int index) { |
+ DCHECK_GE(index, 0); |
+ DCHECK_LT(index, static_cast<int>(countries_.size())); |
+ DCHECK(!IsItemSeparatorAt(index)); |
+ |
+ if (index == default_index_) |
+ return; |
+ |
+ default_index_ = index; |
+ FOR_EACH_OBSERVER(ui::ComboboxModelObserver, observers_, |
+ OnComboboxModelChanged(this)); |
+} |
+ |
} // namespace autofill |