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..01cc8d36dac0fdf242d0e150f7360b379775c539 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,39 @@ 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()) |
+ 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::SelectIndex(int index) { |
+ DCHECK_GE(index, 0); |
+ DCHECK_LT(index, static_cast<int>(countries_.size())); |
+ DCHECK(!IsItemSeparatorAt(index)); |
+ selected_index_ = index; |
+} |
+ |
} // namespace autofill |