Chromium Code Reviews| 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 194984df437acc259b94549c71ea08aa8dff2295..35152c6658298fd287095211b3334235cb4abd82 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 |
| @@ -191,14 +191,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 to check for failure here. |
| + 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()); |
|
please use gerrit instead
2017/04/11 21:05:35
This should be "return std::move(model);" instead.
MAD
2017/04/12 02:46:07
Done.
|
| } |
| default: |
| NOTREACHED(); |
| @@ -215,7 +223,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(); |
| } |
| } |
| @@ -245,7 +254,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; |
| @@ -286,7 +294,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( |
| @@ -312,8 +321,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(); |
| @@ -325,6 +333,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, |
| @@ -344,6 +366,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()) { |