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

Side by Side Diff: ios/chrome/browser/payments/payment_request.mm

Issue 2884393002: [WebPayments] Adding FilterProfilesForShipping to profile comparator (Closed)
Patch Set: rebase 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 unified diff | Download patch
« no previous file with comments | « components/payments/core/payments_profile_comparator_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ios/chrome/browser/payments/payment_request.h" 5 #include "ios/chrome/browser/payments/payment_request.h"
6 6
7 #include "base/containers/adapters.h" 7 #include "base/containers/adapters.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "components/autofill/core/browser/autofill_data_util.h" 9 #include "components/autofill/core/browser/autofill_data_util.h"
10 #include "components/autofill/core/browser/autofill_profile.h" 10 #include "components/autofill/core/browser/autofill_profile.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } 121 }
122 122
123 void PaymentRequest::PopulateProfileCache() { 123 void PaymentRequest::PopulateProfileCache() {
124 const std::vector<autofill::AutofillProfile*>& profiles_to_suggest = 124 const std::vector<autofill::AutofillProfile*>& profiles_to_suggest =
125 personal_data_manager_->GetProfilesToSuggest(); 125 personal_data_manager_->GetProfilesToSuggest();
126 // Return early if the user has no stored Autofill profiles. 126 // Return early if the user has no stored Autofill profiles.
127 if (profiles_to_suggest.empty()) 127 if (profiles_to_suggest.empty())
128 return; 128 return;
129 129
130 profile_cache_.reserve(profiles_to_suggest.size()); 130 profile_cache_.reserve(profiles_to_suggest.size());
131
132 std::vector<autofill::AutofillProfile*> raw_profiles_for_filtering;
133 raw_profiles_for_filtering.reserve(profiles_to_suggest.size());
134
131 for (const auto* profile : profiles_to_suggest) { 135 for (const auto* profile : profiles_to_suggest) {
132 profile_cache_.push_back(*profile); 136 profile_cache_.push_back(*profile);
133 shipping_profiles_.push_back(&profile_cache_.back()); 137 raw_profiles_for_filtering.push_back(&profile_cache_.back());
134 }
135
136 // If the merchant provided a shipping option, select a suitable default
137 // shipping profile. We pick the profile that is most complete, going down
138 // the list in Frecency order.
139 // TODO(crbug.com/719652): Have a proper ordering of shipping addresses by
140 // completeness.
141 if (selected_shipping_option_) {
142 selected_shipping_profile_ = shipping_profiles_[0];
143 for (autofill::AutofillProfile* profile : shipping_profiles_) {
144 if (profile_comparator_.IsShippingComplete(profile)) {
145 selected_shipping_profile_ = profile;
146 break;
147 }
148 }
149 } 138 }
150 139
151 // Contact profiles are deduped and ordered in completeness. 140 // Contact profiles are deduped and ordered in completeness.
152 contact_profiles_ = 141 contact_profiles_ =
153 profile_comparator_.FilterProfilesForContact(shipping_profiles_); 142 profile_comparator_.FilterProfilesForContact(raw_profiles_for_filtering);
143
144 // Shipping profiles are ordered by completeness.
145 shipping_profiles_ =
146 profile_comparator_.FilterProfilesForShipping(raw_profiles_for_filtering);
147
148 // If the merchant provided a shipping option, and the highest-ranking
149 // shipping profile is usable, select it.
150 if (selected_shipping_option_ && !shipping_profiles_.empty() &&
151 profile_comparator_.IsShippingComplete(shipping_profiles_[0])) {
152 selected_shipping_profile_ = shipping_profiles_[0];
153 }
154 154
155 // If the highest-ranking contact profile is usable, select it. Otherwise, 155 // If the highest-ranking contact profile is usable, select it. Otherwise,
156 // select none. 156 // select none.
157 if (!contact_profiles_.empty() && 157 if (!contact_profiles_.empty() &&
158 profile_comparator_.IsContactInfoComplete(contact_profiles_[0])) { 158 profile_comparator_.IsContactInfoComplete(contact_profiles_[0])) {
159 selected_contact_profile_ = contact_profiles_[0]; 159 selected_contact_profile_ = contact_profiles_[0];
160 } 160 }
161 } 161 }
162 162
163 void PaymentRequest::PopulateCreditCardCache() { 163 void PaymentRequest::PopulateCreditCardCache() {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 203
204 for (auto* shipping_option : base::Reversed(shipping_options_)) { 204 for (auto* shipping_option : base::Reversed(shipping_options_)) {
205 if (shipping_option->selected) { 205 if (shipping_option->selected) {
206 // If more than one option has |selected| set, the last one in the 206 // If more than one option has |selected| set, the last one in the
207 // sequence should be treated as the selected item. 207 // sequence should be treated as the selected item.
208 selected_shipping_option_ = shipping_option; 208 selected_shipping_option_ = shipping_option;
209 break; 209 break;
210 } 210 }
211 } 211 }
212 } 212 }
OLDNEW
« no previous file with comments | « components/payments/core/payments_profile_comparator_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698