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

Unified Diff: components/autofill/core/browser/region_combobox_model.cc

Issue 2803443003: [Payments] Added region load failure tolerance and tests to PR editor. (Closed)
Patch Set: Rename function post-rebase Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/browser/region_combobox_model.cc
diff --git a/components/autofill/core/browser/region_combobox_model.cc b/components/autofill/core/browser/region_combobox_model.cc
index ffdb13e315984feafd8400f8522ee7be0e63eb6b..709b42e5e5440f688ab22914ac54cfb3f0fbdeaa 100644
--- a/components/autofill/core/browser/region_combobox_model.cc
+++ b/components/autofill/core/browser/region_combobox_model.cc
@@ -24,6 +24,7 @@ RegionComboboxModel::RegionComboboxModel(
const std::string& country_code)
: app_locale_(app_locale),
region_data_supplier_(source.release(), storage.release()) {
please use gerrit instead 2017/04/11 21:05:35 Constructor initialization is neat to organize lik
MAD 2017/04/12 02:46:08 I had done it like this to make it clear that it's
+ pending_region_data_load_ = true;
region_data_supplier_callback_.reset(::i18n::addressinput::BuildCallback(
this, &RegionComboboxModel::RegionDataLoaded));
region_data_supplier_.LoadRules(country_code,
@@ -35,9 +36,7 @@ RegionComboboxModel::~RegionComboboxModel() {}
int RegionComboboxModel::GetItemCount() const {
// The combobox view needs to always have at least one item. If the regions
// have not been completely loaded yet, we display a single "loading" item.
- // But if we failed to load, we return 0 so that the view can be identified
- // as empty and potentially replaced by another view during ReLayout.
- if (regions_.size() == 0 && !failed_to_load_data_)
+ if (regions_.size() == 0)
return 1;
return regions_.size();
}
@@ -72,18 +71,32 @@ void RegionComboboxModel::RemoveObserver(ui::ComboboxModelObserver* observer) {
observers_.RemoveObserver(observer);
}
+void RegionComboboxModel::SetFailureModeForTests(bool failed_to_load_data) {
+ failed_to_load_data_ = failed_to_load_data;
+ for (auto& observer : observers_) {
+ observer.OnComboboxModelChanged(this);
+ }
+}
+
void RegionComboboxModel::RegionDataLoaded(bool success,
const std::string& country_code,
int rule_count) {
+ pending_region_data_load_ = false;
if (success) {
- failed_to_load_data_ = false;
std::string best_region_tree_language_tag;
::i18n::addressinput::RegionDataBuilder builder(&region_data_supplier_);
const std::vector<const ::i18n::addressinput::RegionData*>& regions =
builder.Build(country_code, app_locale_, &best_region_tree_language_tag)
.sub_regions();
- for (auto* const region : regions) {
- regions_.push_back(std::make_pair(region->key(), region->name()));
+ // For some reason, some countries expose a state field but have not
please use gerrit instead 2017/04/11 21:05:35 Please remove "For some reason". That's a property
MAD 2017/04/12 02:46:08 Done.
+ // region names available.
+ if (regions.size() > 0) {
+ failed_to_load_data_ = false;
+ for (auto* const region : regions) {
+ regions_.push_back(std::make_pair(region->key(), region->name()));
+ }
+ } else {
+ failed_to_load_data_ = true;
}
} else {
// TODO(mad): Maybe use a static list as is done for countries in

Powered by Google App Engine
This is Rietveld 408576698