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

Side by Side Diff: chrome/browser/ui/views/payments/shipping_address_editor_view_controller.cc

Issue 2841643002: When a new Payments address is created from the editor, use it as the chosen address (Closed)
Patch Set: Self CR 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 unified diff | Download patch
OLDNEW
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 <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 NOTREACHED(); 67 NOTREACHED();
68 return autofill::UNKNOWN_TYPE; 68 return autofill::UNKNOWN_TYPE;
69 } 69 }
70 70
71 } // namespace 71 } // namespace
72 72
73 ShippingAddressEditorViewController::ShippingAddressEditorViewController( 73 ShippingAddressEditorViewController::ShippingAddressEditorViewController(
74 PaymentRequestSpec* spec, 74 PaymentRequestSpec* spec,
75 PaymentRequestState* state, 75 PaymentRequestState* state,
76 PaymentRequestDialogView* dialog, 76 PaymentRequestDialogView* dialog,
77 base::OnceClosure on_edited,
78 base::OnceCallback<void(const autofill::AutofillProfile&)> on_added,
77 autofill::AutofillProfile* profile) 79 autofill::AutofillProfile* profile)
78 : EditorViewController(spec, state, dialog), 80 : EditorViewController(spec, state, dialog),
81 on_edited_(std::move(on_edited)),
82 on_added_(std::move(on_added)),
79 profile_to_edit_(profile), 83 profile_to_edit_(profile),
80 chosen_country_index_(0), 84 chosen_country_index_(0),
81 failed_to_load_region_data_(false) { 85 failed_to_load_region_data_(false) {
82 UpdateEditorFields(); 86 UpdateEditorFields();
83 } 87 }
84 88
85 ShippingAddressEditorViewController::~ShippingAddressEditorViewController() {} 89 ShippingAddressEditorViewController::~ShippingAddressEditorViewController() {}
86 90
87 std::unique_ptr<views::View> 91 std::unique_ptr<views::View>
88 ShippingAddressEditorViewController::CreateHeaderView() { 92 ShippingAddressEditorViewController::CreateHeaderView() {
(...skipping 24 matching lines...) Expand all
113 bool ShippingAddressEditorViewController::ValidateModelAndSave() { 117 bool ShippingAddressEditorViewController::ValidateModelAndSave() {
114 // To validate the profile first, we use a temporary object. 118 // To validate the profile first, we use a temporary object.
115 autofill::AutofillProfile profile; 119 autofill::AutofillProfile profile;
116 if (!SaveFieldsToProfile(&profile, /*ignore_errors=*/false)) 120 if (!SaveFieldsToProfile(&profile, /*ignore_errors=*/false))
117 return false; 121 return false;
118 122
119 if (!profile_to_edit_) { 123 if (!profile_to_edit_) {
120 // Add the profile (will not add a duplicate). 124 // Add the profile (will not add a duplicate).
121 profile.set_origin(autofill::kSettingsOrigin); 125 profile.set_origin(autofill::kSettingsOrigin);
122 state()->GetPersonalDataManager()->AddProfile(profile); 126 state()->GetPersonalDataManager()->AddProfile(profile);
127 std::move(on_added_).Run(profile);
123 } else { 128 } else {
124 // Copy the temporary object's data to the object to be edited. Prefer this 129 // Copy the temporary object's data to the object to be edited. Prefer this
125 // method to copying |profile| into |profile_to_edit_|, because the latter 130 // method to copying |profile| into |profile_to_edit_|, because the latter
126 // object needs to retain other properties (use count, use date, guid, 131 // object needs to retain other properties (use count, use date, guid,
127 // etc.). 132 // etc.).
128 bool success = SaveFieldsToProfile(profile_to_edit_, 133 bool success = SaveFieldsToProfile(profile_to_edit_,
129 /*ignore_errors=*/false); 134 /*ignore_errors=*/false);
130 DCHECK(success); 135 DCHECK(success);
131 profile_to_edit_->set_origin(autofill::kSettingsOrigin); 136 profile_to_edit_->set_origin(autofill::kSettingsOrigin);
132 state()->GetPersonalDataManager()->UpdateProfile(*profile_to_edit_); 137 state()->GetPersonalDataManager()->UpdateProfile(*profile_to_edit_);
138 std::move(on_edited_).Run();
133 } 139 }
134 140
135 return true; 141 return true;
136 } 142 }
137 143
138 std::unique_ptr<ValidationDelegate> 144 std::unique_ptr<ValidationDelegate>
139 ShippingAddressEditorViewController::CreateValidationDelegate( 145 ShippingAddressEditorViewController::CreateValidationDelegate(
140 const EditorField& field) { 146 const EditorField& field) {
141 return base::MakeUnique< 147 return base::MakeUnique<
142 ShippingAddressEditorViewController::ShippingAddressValidationDelegate>( 148 ShippingAddressEditorViewController::ShippingAddressValidationDelegate>(
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 bool is_required_valid = !field_.required; 410 bool is_required_valid = !field_.required;
405 const base::string16 displayed_message = 411 const base::string16 displayed_message =
406 is_required_valid ? base::ASCIIToUTF16("") 412 is_required_valid ? base::ASCIIToUTF16("")
407 : l10n_util::GetStringUTF16( 413 : l10n_util::GetStringUTF16(
408 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); 414 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE);
409 controller_->DisplayErrorMessageForField(field_, displayed_message); 415 controller_->DisplayErrorMessageForField(field_, displayed_message);
410 return is_required_valid; 416 return is_required_valid;
411 } 417 }
412 418
413 } // namespace payments 419 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698