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

Unified Diff: chrome/browser/ui/views/payments/shipping_address_editor_view_controller.cc

Issue 2803443003: [Payments] Added region load failure tolerance and tests to PR editor. (Closed)
Patch Set: Sign bot error fixes 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: chrome/browser/ui/views/payments/shipping_address_editor_view_controller.cc
diff --git a/chrome/browser/ui/views/payments/shipping_address_editor_view_controller.cc b/chrome/browser/ui/views/payments/shipping_address_editor_view_controller.cc
index 4ce0cbd8de428943195ddc351bc67287e2db45a0..e97b2b964b22b1a7565222bf2ae4d9833e8e03a6 100644
--- a/chrome/browser/ui/views/payments/shipping_address_editor_view_controller.cc
+++ b/chrome/browser/ui/views/payments/shipping_address_editor_view_controller.cc
@@ -123,7 +123,6 @@ bool ShippingAddressEditorViewController::ValidateModelAndSave() {
// Add the profile (will not add a duplicate).
state()->GetPersonalDataManager()->AddProfile(profile);
-
return true;
}
@@ -155,14 +154,22 @@ ShippingAddressEditorViewController::GetComboboxModelForType(
return std::unique_ptr<ui::ComboboxModel>(model.release());
}
case autofill::ADDRESS_HOME_STATE: {
- return std::unique_ptr<
- ui::ComboboxModel>(new autofill::RegionComboboxModel(
+ std::unique_ptr<autofill::RegionComboboxModel> model = base::MakeUnique<
+ autofill::RegionComboboxModel>(
base::WrapUnique(new autofill::ChromeMetadataSource(
I18N_ADDRESS_VALIDATION_DATA_URL,
state()->GetPersonalDataManager()->GetURLRequestContextGetter())),
autofill::ValidationRulesStorageFactory::CreateStorage(),
state()->GetApplicationLocale(),
- country_codes_[chosen_country_index_]));
+ country_codes_[chosen_country_index_]);
+ // If the data was already pre-loaded, the observer won't get notified so
+ // we have check for failure here.
Mathieu 2017/04/05 00:25:14 nit: *we have to check
MAD 2017/04/07 18:50:40 Done.
+ if (!model->pending_region_data_load()) {
+ failed_to_load_region_data_ = model->failed_to_load_data();
+ if (failed_to_load_region_data_)
+ OnDataChanged();
+ }
+ return std::unique_ptr<ui::ComboboxModel>(model.release());
}
default:
NOTREACHED();
@@ -179,7 +186,8 @@ void ShippingAddressEditorViewController::OnPerformAction(
DCHECK_GE(sender->selected_index(), 0);
if (chosen_country_index_ != static_cast<size_t>(sender->selected_index())) {
chosen_country_index_ = sender->selected_index();
- OnCountryChanged(sender);
+ failed_to_load_region_data_ = false;
+ OnDataChanged();
}
}
@@ -209,7 +217,6 @@ void ShippingAddressEditorViewController::UpdateEditorFields() {
autofill::GetAddressComponents(chosen_country_code,
state()->GetApplicationLocale(),
components.get(), &unused);
-
for (size_t line_index = 0; line_index < components->GetSize();
++line_index) {
const base::ListValue* line = nullptr;
@@ -250,7 +257,8 @@ void ShippingAddressEditorViewController::UpdateEditorFields() {
EditorField::ControlType control_type =
EditorField::ControlType::TEXTFIELD;
if (server_field_type == autofill::ADDRESS_HOME_COUNTRY ||
- server_field_type == autofill::ADDRESS_HOME_STATE) {
+ (server_field_type == autofill::ADDRESS_HOME_STATE &&
+ !failed_to_load_region_data_)) {
control_type = EditorField::ControlType::COMBOBOX;
}
editor_fields_.emplace_back(
@@ -276,8 +284,7 @@ void ShippingAddressEditorViewController::UpdateEditorFields() {
EditorField::ControlType::TEXTFIELD);
}
-void ShippingAddressEditorViewController::OnCountryChanged(
- views::Combobox* combobox) {
+void ShippingAddressEditorViewController::OnDataChanged() {
// TODO(crbug.com/703764): save the current state so we can map it to the new
// country fields as best we can.
UpdateEditorFields();
@@ -289,6 +296,20 @@ void ShippingAddressEditorViewController::OnCountryChanged(
base::Unretained(this)));
}
+void ShippingAddressEditorViewController::OnComboboxModelChanged(
+ views::Combobox* combobox) {
+ if (combobox->id() != autofill::ADDRESS_HOME_STATE)
+ return;
+ autofill::RegionComboboxModel* model =
+ static_cast<autofill::RegionComboboxModel*>(combobox->model());
+ if (model->pending_region_data_load())
+ return;
+ if (model->failed_to_load_data()) {
+ failed_to_load_region_data_ = true;
+ OnDataChanged();
+ }
+}
+
ShippingAddressEditorViewController::ShippingAddressValidationDelegate::
ShippingAddressValidationDelegate(
ShippingAddressEditorViewController* controller,
@@ -308,6 +329,11 @@ bool ShippingAddressEditorViewController::ShippingAddressValidationDelegate::
return ValidateValue(combobox->GetTextForRow(combobox->selected_index()));
}
+void ShippingAddressEditorViewController::ShippingAddressValidationDelegate::
+ ComboboxModelChanged(views::Combobox* combobox) {
+ controller_->OnComboboxModelChanged(combobox);
+}
+
bool ShippingAddressEditorViewController::ShippingAddressValidationDelegate::
ValidateValue(const base::string16& value) {
if (!value.empty()) {

Powered by Google App Engine
This is Rietveld 408576698