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

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

Issue 2878763002: [Payments] Better default selections on iOS (Closed)
Patch Set: fix test, really Created 3 years, 7 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 | « no previous file | ios/chrome/browser/payments/payment_request.h » ('j') | 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 8a6b7304452eb3ac890b056130cb62e0050e32a2..d32e4a55d00a582ae6247f99f41b9b62694efc13 100644
--- a/components/payments/content/payment_request_state.cc
+++ b/components/payments/content/payment_request_state.cc
@@ -199,13 +199,11 @@ void PaymentRequestState::PopulateProfileCache() {
// PaymentRequest may outlive the Profiles returned by the Data Manager.
// Thus, we store copies, and return a vector of pointers to these copies
- // whenever Profiles are requested. The same is true for credit cards.
+ // whenever Profiles are requested.
for (size_t i = 0; i < profiles.size(); i++) {
profile_cache_.push_back(
base::MakeUnique<autofill::AutofillProfile>(*profiles[i]));
- // TODO(tmartino): Implement deduplication rules specific to shipping
- // profiles.
shipping_profiles_.push_back(profile_cache_[i].get());
}
@@ -220,7 +218,8 @@ void PaymentRequestState::PopulateProfileCache() {
contact_profiles_ = profile_comparator()->FilterProfilesForContact(
raw_profiles_for_filtering);
- // Create the list of available instruments.
+ // Create the list of available instruments. A copy of each card will be made
+ // by their respective AutofillPaymentInstrument.
const std::vector<autofill::CreditCard*>& cards =
personal_data_manager_->GetCreditCardsToSuggest();
for (autofill::CreditCard* card : cards)
@@ -230,9 +229,20 @@ void PaymentRequestState::PopulateProfileCache() {
void PaymentRequestState::SetDefaultProfileSelections() {
// Only pre-select an address if the merchant provided at least one selected
// shipping option.
- if (!shipping_profiles().empty() && spec_->selected_shipping_option())
- selected_shipping_profile_ = shipping_profiles()[0];
+ if (!shipping_profiles().empty() && spec_->selected_shipping_option()) {
+ // Choose any complete shipping profile, or default to the most frecent
+ // address if no complete address could be found.
+ selected_shipping_profile_ = shipping_profiles_[0];
+ for (autofill::AutofillProfile* profile : shipping_profiles_) {
+ if (profile_comparator_.IsShippingComplete(profile)) {
+ selected_shipping_profile_ = profile;
+ break;
+ }
+ }
+ }
+ // Contact profiles were ordered by completeness in addition to frecency;
+ // the first one is the best default selection.
if (!contact_profiles().empty())
selected_contact_profile_ = contact_profiles()[0];
« no previous file with comments | « no previous file | ios/chrome/browser/payments/payment_request.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698