| Index: chrome/browser/ui/views/payments/credit_card_editor_view_controller.cc
|
| diff --git a/chrome/browser/ui/views/payments/credit_card_editor_view_controller.cc b/chrome/browser/ui/views/payments/credit_card_editor_view_controller.cc
|
| index b44d6b2c08c5c3950472be92de4e354b1fffd7f8..0d98f7dec9a314be93760bea2715e12292f0e744 100644
|
| --- a/chrome/browser/ui/views/payments/credit_card_editor_view_controller.cc
|
| +++ b/chrome/browser/ui/views/payments/credit_card_editor_view_controller.cc
|
| @@ -82,8 +82,10 @@ std::vector<base::string16> GetExpirationYearItems() {
|
| CreditCardEditorViewController::CreditCardEditorViewController(
|
| PaymentRequestSpec* spec,
|
| PaymentRequestState* state,
|
| - PaymentRequestDialogView* dialog)
|
| - : EditorViewController(spec, state, dialog) {}
|
| + PaymentRequestDialogView* dialog,
|
| + autofill::CreditCard* credit_card)
|
| + : EditorViewController(spec, state, dialog),
|
| + credit_card_to_edit_(credit_card) {}
|
|
|
| CreditCardEditorViewController::~CreditCardEditorViewController() {}
|
|
|
| @@ -160,9 +162,21 @@ std::vector<EditorField> CreditCardEditorViewController::GetFieldDefinitions() {
|
| EditorField::ControlType::COMBOBOX}};
|
| }
|
|
|
| +base::string16 CreditCardEditorViewController::GetInitialValueForType(
|
| + autofill::ServerFieldType type) {
|
| + if (!credit_card_to_edit_)
|
| + return base::string16();
|
| +
|
| + // It is fine to use GetRawInfo here because credit card types are not
|
| + // complex/compound.
|
| + return credit_card_to_edit_->GetRawInfo(type);
|
| +}
|
| +
|
| bool CreditCardEditorViewController::ValidateModelAndSave() {
|
| + // Use a temporary object for validation.
|
| autofill::CreditCard credit_card;
|
| credit_card.set_origin(autofill::kSettingsOrigin);
|
| +
|
| for (const auto& field : text_fields()) {
|
| // ValidatingTextfield* is the key, EditorField is the value.
|
| DCHECK_EQ(autofill::CREDIT_CARD,
|
| @@ -188,8 +202,22 @@ bool CreditCardEditorViewController::ValidateModelAndSave() {
|
| if (!credit_card.IsValid())
|
| return false;
|
|
|
| - // Add the card (will not add a duplicate).
|
| - state()->GetPersonalDataManager()->AddCreditCard(credit_card);
|
| + if (!credit_card_to_edit_) {
|
| + // Add the card (will not add a duplicate).
|
| + state()->GetPersonalDataManager()->AddCreditCard(credit_card);
|
| + } else {
|
| + // We were in edit mode. Copy the data from the temporary object to retain
|
| + // the edited object's other properties (use count, use date, guid, etc.).
|
| + for (const auto& field : text_fields()) {
|
| + credit_card_to_edit_->SetRawInfo(
|
| + field.second.type, credit_card.GetRawInfo(field.second.type));
|
| + }
|
| + for (const auto& field : comboboxes()) {
|
| + credit_card_to_edit_->SetRawInfo(
|
| + field.second.type, credit_card.GetRawInfo(field.second.type));
|
| + }
|
| + state()->GetPersonalDataManager()->UpdateCreditCard(*credit_card_to_edit_);
|
| + }
|
|
|
| return true;
|
| }
|
|
|