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

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

Issue 2884393002: [WebPayments] Adding FilterProfilesForShipping to profile comparator (Closed)
Patch Set: adding browsertest 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
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 1236b700cb0d08cbbf7c991f1c6999a366bb1458..fef97f945629b3e817d10538f475b2c851571731 100644
--- a/components/payments/content/payment_request_state.cc
+++ b/components/payments/content/payment_request_state.cc
@@ -234,26 +234,22 @@ void PaymentRequestState::PopulateProfileCache() {
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]));
-
- shipping_profiles_.push_back(profile_cache_[i].get());
+ raw_profiles_for_filtering.push_back(profile_cache_.back().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
// by their respective AutofillPaymentInstrument.
@@ -265,22 +261,17 @@ 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()) {
- // 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;
- }
- }
+ // shipping option, and the top profile is complete. Assumes that profiles
Mathieu 2017/05/19 01:10:41 Did we check with Zach/UX? Perhaps we should selec
tmartino 2017/05/19 18:11:27 Just checked. This is preferred, so that the "prev
+ // 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];
}
// Contact profiles were ordered by completeness in addition to frecency;
// the first one is the best default selection.
- if (!contact_profiles().empty())
+ if (!contact_profiles().empty() &&
+ profile_comparator()->IsContactInfoComplete(contact_profiles_[0]))
Mathieu 2017/05/19 01:10:41 same question here
tmartino 2017/05/19 18:11:27 ack
selected_contact_profile_ = contact_profiles()[0];
// TODO(crbug.com/702063): Change this code to prioritize instruments by use

Powered by Google App Engine
This is Rietveld 408576698