| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/payments/shipping_address_editor_view_controll
er.h" | 5 #include "chrome/browser/ui/views/payments/shipping_address_editor_view_controll
er.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 NOTREACHED(); | 60 NOTREACHED(); |
| 61 return autofill::UNKNOWN_TYPE; | 61 return autofill::UNKNOWN_TYPE; |
| 62 } | 62 } |
| 63 | 63 |
| 64 } // namespace | 64 } // namespace |
| 65 | 65 |
| 66 ShippingAddressEditorViewController::ShippingAddressEditorViewController( | 66 ShippingAddressEditorViewController::ShippingAddressEditorViewController( |
| 67 PaymentRequestSpec* spec, | 67 PaymentRequestSpec* spec, |
| 68 PaymentRequestState* state, | 68 PaymentRequestState* state, |
| 69 PaymentRequestDialogView* dialog, | 69 PaymentRequestDialogView* dialog, |
| 70 base::OnceClosure on_edited, |
| 71 base::OnceCallback<void(const autofill::AutofillProfile&)> on_added, |
| 70 autofill::AutofillProfile* profile) | 72 autofill::AutofillProfile* profile) |
| 71 : EditorViewController(spec, state, dialog), | 73 : EditorViewController(spec, state, dialog), |
| 74 on_edited_(std::move(on_edited)), |
| 75 on_added_(std::move(on_added)), |
| 72 profile_to_edit_(profile), | 76 profile_to_edit_(profile), |
| 73 chosen_country_index_(0), | 77 chosen_country_index_(0), |
| 74 failed_to_load_region_data_(false) { | 78 failed_to_load_region_data_(false) { |
| 75 UpdateEditorFields(); | 79 UpdateEditorFields(); |
| 76 } | 80 } |
| 77 | 81 |
| 78 ShippingAddressEditorViewController::~ShippingAddressEditorViewController() {} | 82 ShippingAddressEditorViewController::~ShippingAddressEditorViewController() {} |
| 79 | 83 |
| 80 std::unique_ptr<views::View> | 84 std::unique_ptr<views::View> |
| 81 ShippingAddressEditorViewController::CreateHeaderView() { | 85 ShippingAddressEditorViewController::CreateHeaderView() { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 106 bool ShippingAddressEditorViewController::ValidateModelAndSave() { | 110 bool ShippingAddressEditorViewController::ValidateModelAndSave() { |
| 107 // To validate the profile first, we use a temporary object. | 111 // To validate the profile first, we use a temporary object. |
| 108 autofill::AutofillProfile profile; | 112 autofill::AutofillProfile profile; |
| 109 if (!SaveFieldsToProfile(&profile, /*ignore_errors=*/false)) | 113 if (!SaveFieldsToProfile(&profile, /*ignore_errors=*/false)) |
| 110 return false; | 114 return false; |
| 111 | 115 |
| 112 if (!profile_to_edit_) { | 116 if (!profile_to_edit_) { |
| 113 // Add the profile (will not add a duplicate). | 117 // Add the profile (will not add a duplicate). |
| 114 profile.set_origin(autofill::kSettingsOrigin); | 118 profile.set_origin(autofill::kSettingsOrigin); |
| 115 state()->GetPersonalDataManager()->AddProfile(profile); | 119 state()->GetPersonalDataManager()->AddProfile(profile); |
| 120 std::move(on_added_).Run(profile); |
| 121 on_edited_.Reset(); |
| 116 } else { | 122 } else { |
| 117 // Copy the temporary object's data to the object to be edited. Prefer this | 123 // Copy the temporary object's data to the object to be edited. Prefer this |
| 118 // method to copying |profile| into |profile_to_edit_|, because the latter | 124 // method to copying |profile| into |profile_to_edit_|, because the latter |
| 119 // object needs to retain other properties (use count, use date, guid, | 125 // object needs to retain other properties (use count, use date, guid, |
| 120 // etc.). | 126 // etc.). |
| 121 bool success = SaveFieldsToProfile(profile_to_edit_, | 127 bool success = SaveFieldsToProfile(profile_to_edit_, |
| 122 /*ignore_errors=*/false); | 128 /*ignore_errors=*/false); |
| 123 DCHECK(success); | 129 DCHECK(success); |
| 124 profile_to_edit_->set_origin(autofill::kSettingsOrigin); | 130 profile_to_edit_->set_origin(autofill::kSettingsOrigin); |
| 125 state()->GetPersonalDataManager()->UpdateProfile(*profile_to_edit_); | 131 state()->GetPersonalDataManager()->UpdateProfile(*profile_to_edit_); |
| 132 std::move(on_edited_).Run(); |
| 133 on_added_.Reset(); |
| 126 } | 134 } |
| 127 | 135 |
| 128 return true; | 136 return true; |
| 129 } | 137 } |
| 130 | 138 |
| 131 std::unique_ptr<ValidationDelegate> | 139 std::unique_ptr<ValidationDelegate> |
| 132 ShippingAddressEditorViewController::CreateValidationDelegate( | 140 ShippingAddressEditorViewController::CreateValidationDelegate( |
| 133 const EditorField& field) { | 141 const EditorField& field) { |
| 134 return base::MakeUnique< | 142 return base::MakeUnique< |
| 135 ShippingAddressEditorViewController::ShippingAddressValidationDelegate>( | 143 ShippingAddressEditorViewController::ShippingAddressValidationDelegate>( |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 bool is_required_valid = !field_.required; | 414 bool is_required_valid = !field_.required; |
| 407 const base::string16 displayed_message = | 415 const base::string16 displayed_message = |
| 408 is_required_valid ? base::ASCIIToUTF16("") | 416 is_required_valid ? base::ASCIIToUTF16("") |
| 409 : l10n_util::GetStringUTF16( | 417 : l10n_util::GetStringUTF16( |
| 410 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); | 418 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); |
| 411 controller_->DisplayErrorMessageForField(field_, displayed_message); | 419 controller_->DisplayErrorMessageForField(field_, displayed_message); |
| 412 return is_required_valid; | 420 return is_required_valid; |
| 413 } | 421 } |
| 414 | 422 |
| 415 } // namespace payments | 423 } // namespace payments |
| OLD | NEW |