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

Unified Diff: components/payments/content/payment_request_state.cc

Issue 2807363003: [Payments] After adding/editing a credit card, instrument is selected. (Closed)
Patch Set: include fix 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/payments/content/payment_request_state.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/payments/content/payment_request_state.cc
diff --git a/components/payments/content/payment_request_state.cc b/components/payments/content/payment_request_state.cc
index 81d254594aa7b94c7b9c86e890082c23337ac9b3..158ef27eaed71f879d967cbaa93072b36e41b2de 100644
--- a/components/payments/content/payment_request_state.cc
+++ b/components/payments/content/payment_request_state.cc
@@ -116,6 +116,27 @@ void PaymentRequestState::GeneratePaymentResponse() {
selected_instrument_->InvokePaymentApp(this);
}
+void PaymentRequestState::AddAutofillPaymentInstrument(
+ bool selected,
+ const autofill::CreditCard& card) {
+ std::string basic_card_network =
+ autofill::data_util::GetPaymentRequestData(card.type())
+ .basic_card_payment_type;
+ if (!spec_->supported_card_networks_set().count(basic_card_network))
+ return;
+
+ // AutofillPaymentInstrument makes a copy of |card| so it is effectively
+ // owned by this object.
+ std::unique_ptr<PaymentInstrument> instrument =
+ base::MakeUnique<AutofillPaymentInstrument>(
+ basic_card_network, card, shipping_profiles_, app_locale_,
+ payment_request_delegate_);
+ available_instruments_.push_back(std::move(instrument));
+
+ if (selected)
+ SetSelectedInstrument(available_instruments_.back().get());
+}
+
void PaymentRequestState::SetSelectedShippingOption(
const std::string& shipping_option_id) {
// This will inform the merchant and will lead to them calling updateWith with
@@ -181,23 +202,8 @@ void PaymentRequestState::PopulateProfileCache() {
// Create the list of available instruments.
const std::vector<autofill::CreditCard*>& cards =
personal_data_manager_->GetCreditCardsToSuggest();
- const std::set<std::string>& supported_card_networks =
- spec_->supported_card_networks_set();
- for (autofill::CreditCard* card : cards) {
- std::string basic_card_network =
- autofill::data_util::GetPaymentRequestData(card->type())
- .basic_card_payment_type;
- if (!supported_card_networks.count(basic_card_network))
- continue;
-
- // Copy the credit cards as part of AutofillPaymentInstrument so they are
- // indirectly owned by this object.
- std::unique_ptr<PaymentInstrument> instrument =
- base::MakeUnique<AutofillPaymentInstrument>(
- basic_card_network, *card, shipping_profiles_, app_locale_,
- payment_request_delegate_);
- available_instruments_.push_back(std::move(instrument));
- }
+ for (autofill::CreditCard* card : cards)
+ AddAutofillPaymentInstrument(/*selected=*/false, *card);
}
void PaymentRequestState::SetDefaultProfileSelections() {
« no previous file with comments | « components/payments/content/payment_request_state.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698