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..b05bef30906a48c65ec5b7549835b5a20607fb79 100644 |
--- a/chrome/browser/ui/autofill/country_combobox_model.cc |
+++ b/chrome/browser/ui/autofill/country_combobox_model.cc |
@@ -12,9 +12,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 +62,34 @@ bool CountryComboboxModel::IsItemSeparatorAt(int index) { |
return !countries_[index]; |
} |
+void CountryComboboxModel::SelectIndex(int index) { |
+ DCHECK_GE(index, 0); |
+ DCHECK_LT(index, static_cast<int>(countries_.size())); |
+ DCHECK(!IsItemSeparatorAt(index)); |
+ selected_index_ = index; |
+} |
+ |
+void CountryComboboxModel::SelectDefaultIndex() { |
+ SelectIndex(GetDefaultIndex()); |
+} |
+ |
+void CountryComboboxModel::SelectCountry(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) { |
+ SelectIndex(i); |
+ return; |
+ } |
+ } |
+ NOTREACHED(); |
+} |
+ |
+std::string CountryComboboxModel::GetSelectedCountryCode() const { |
+ return countries_[selected_index_]->country_code(); |
+} |
+ |
+bool CountryComboboxModel::IsDefaultIndexSelected() const { |
+ return selected_index_ == GetDefaultIndex(); |
+} |
+ |
} // namespace autofill |