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

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

Issue 2972973002: [Payments] When saving an edited address in editor, clear data first. (Closed)
Patch Set: addressed comments Created 3 years, 5 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
« no previous file with comments | « no previous file | chrome/browser/ui/views/payments/shipping_address_editor_view_controller_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 autofill::AutofillProfile profile; 112 autofill::AutofillProfile profile;
113 if (!SaveFieldsToProfile(&profile, /*ignore_errors=*/false)) 113 if (!SaveFieldsToProfile(&profile, /*ignore_errors=*/false))
114 return false; 114 return false;
115 if (!profile_to_edit_) { 115 if (!profile_to_edit_) {
116 // Add the profile (will not add a duplicate). 116 // Add the profile (will not add a duplicate).
117 profile.set_origin(autofill::kSettingsOrigin); 117 profile.set_origin(autofill::kSettingsOrigin);
118 state()->GetPersonalDataManager()->AddProfile(profile); 118 state()->GetPersonalDataManager()->AddProfile(profile);
119 std::move(on_added_).Run(profile); 119 std::move(on_added_).Run(profile);
120 on_edited_.Reset(); 120 on_edited_.Reset();
121 } else { 121 } else {
122 // Copy the temporary object's data to the object to be edited. Prefer this 122 autofill::ServerFieldTypeSet all_fields;
123 // method to copying |profile| into |profile_to_edit_|, because the latter 123 profile_to_edit_->GetSupportedTypes(&all_fields);
124 // object needs to retain other properties (use count, use date, guid, 124 // Clear all the address data in |profile_to_edit_|, in anticipation of
125 // adding only the fields present in the editor. Prefer this method to
126 // copying |profile| into |profile_to_edit_|, because the latter object
127 // needs to retain other properties (use count, use date, guid,
125 // etc.). 128 // etc.).
129 for (autofill::ServerFieldType type : all_fields)
130 profile_to_edit_->SetRawInfo(type, base::string16());
131
126 bool success = SaveFieldsToProfile(profile_to_edit_, 132 bool success = SaveFieldsToProfile(profile_to_edit_,
127 /*ignore_errors=*/false); 133 /*ignore_errors=*/false);
128 DCHECK(success); 134 DCHECK(success);
129 profile_to_edit_->set_origin(autofill::kSettingsOrigin); 135 profile_to_edit_->set_origin(autofill::kSettingsOrigin);
130 state()->GetPersonalDataManager()->UpdateProfile(*profile_to_edit_); 136 state()->GetPersonalDataManager()->UpdateProfile(*profile_to_edit_);
131 state()->profile_comparator()->Invalidate(*profile_to_edit_); 137 state()->profile_comparator()->Invalidate(*profile_to_edit_);
132 std::move(on_edited_).Run(); 138 std::move(on_edited_).Run();
133 on_added_.Reset(); 139 on_added_.Reset();
134 } 140 }
135 141
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 return true; 563 return true;
558 } 564 }
559 if (error_message && field_.required) { 565 if (error_message && field_.required) {
560 *error_message = l10n_util::GetStringUTF16( 566 *error_message = l10n_util::GetStringUTF16(
561 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); 567 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE);
562 } 568 }
563 return !field_.required; 569 return !field_.required;
564 } 570 }
565 571
566 } // namespace payments 572 } // namespace payments
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/payments/shipping_address_editor_view_controller_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698