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

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

Issue 2897133002: Revert of [WebPayments] Adding FilterProfilesForShipping to profile comparator (Closed)
Patch Set: 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 | « chrome/test/BUILD.gn ('k') | components/payments/core/payments_profile_comparator.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 fef97f945629b3e817d10538f475b2c851571731..1236b700cb0d08cbbf7c991f1c6999a366bb1458 100644
--- a/components/payments/content/payment_request_state.cc
+++ b/components/payments/content/payment_request_state.cc
@@ -234,21 +234,25 @@
std::vector<autofill::AutofillProfile*> profiles =
personal_data_manager_->GetProfilesToSuggest();
- std::vector<autofill::AutofillProfile*> raw_profiles_for_filtering;
- raw_profiles_for_filtering.reserve(profiles.size());
-
// 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.
for (size_t i = 0; i < profiles.size(); i++) {
profile_cache_.push_back(
base::MakeUnique<autofill::AutofillProfile>(*profiles[i]));
- raw_profiles_for_filtering.push_back(profile_cache_.back().get());
- }
+
+ shipping_profiles_.push_back(profile_cache_[i].get());
+ }
+
+ std::vector<autofill::AutofillProfile*> raw_profiles_for_filtering(
+ profile_cache_.size());
+ std::transform(profile_cache_.begin(), profile_cache_.end(),
+ raw_profiles_for_filtering.begin(),
+ [](const std::unique_ptr<autofill::AutofillProfile>& p) {
+ return p.get();
+ });
contact_profiles_ = profile_comparator()->FilterProfilesForContact(
- raw_profiles_for_filtering);
- shipping_profiles_ = profile_comparator()->FilterProfilesForShipping(
raw_profiles_for_filtering);
// Create the list of available instruments. A copy of each card will be made
@@ -261,17 +265,22 @@
void PaymentRequestState::SetDefaultProfileSelections() {
// Only pre-select an address if the merchant provided at least one selected
- // shipping option, and the top profile is complete. Assumes that profiles
- // have already been sorted for completeness and frecency.
- if (!shipping_profiles().empty() && spec_->selected_shipping_option() &&
- profile_comparator()->IsShippingComplete(shipping_profiles_[0])) {
- selected_shipping_profile_ = shipping_profiles()[0];
+ // shipping option.
+ 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() &&
- profile_comparator()->IsContactInfoComplete(contact_profiles_[0]))
+ if (!contact_profiles().empty())
selected_contact_profile_ = contact_profiles()[0];
// TODO(crbug.com/702063): Change this code to prioritize instruments by use
« no previous file with comments | « chrome/test/BUILD.gn ('k') | components/payments/core/payments_profile_comparator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698