Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/payments/content/payment_request_state.h" | 5 #include "components/payments/content/payment_request_state.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 void PaymentRequestState::PopulateProfileCache() { | 221 void PaymentRequestState::PopulateProfileCache() { |
| 222 std::vector<autofill::AutofillProfile*> profiles = | 222 std::vector<autofill::AutofillProfile*> profiles = |
| 223 personal_data_manager_->GetProfilesToSuggest(); | 223 personal_data_manager_->GetProfilesToSuggest(); |
| 224 | 224 |
| 225 // PaymentRequest may outlive the Profiles returned by the Data Manager. | 225 // PaymentRequest may outlive the Profiles returned by the Data Manager. |
| 226 // Thus, we store copies, and return a vector of pointers to these copies | 226 // Thus, we store copies, and return a vector of pointers to these copies |
| 227 // whenever Profiles are requested. | 227 // whenever Profiles are requested. |
| 228 for (size_t i = 0; i < profiles.size(); i++) { | 228 for (size_t i = 0; i < profiles.size(); i++) { |
| 229 profile_cache_.push_back( | 229 profile_cache_.push_back( |
| 230 base::MakeUnique<autofill::AutofillProfile>(*profiles[i])); | 230 base::MakeUnique<autofill::AutofillProfile>(*profiles[i])); |
| 231 | |
| 232 shipping_profiles_.push_back(profile_cache_[i].get()); | |
| 233 } | 231 } |
| 234 | 232 |
| 235 std::vector<autofill::AutofillProfile*> raw_profiles_for_filtering( | 233 std::vector<autofill::AutofillProfile*> raw_profiles_for_filtering( |
| 236 profile_cache_.size()); | 234 profile_cache_.size()); |
| 237 std::transform(profile_cache_.begin(), profile_cache_.end(), | 235 std::transform(profile_cache_.begin(), profile_cache_.end(), |
| 238 raw_profiles_for_filtering.begin(), | 236 raw_profiles_for_filtering.begin(), |
| 239 [](const std::unique_ptr<autofill::AutofillProfile>& p) { | 237 [](const std::unique_ptr<autofill::AutofillProfile>& p) { |
| 240 return p.get(); | 238 return p.get(); |
| 241 }); | 239 }); |
| 242 | 240 |
| 243 contact_profiles_ = profile_comparator()->FilterProfilesForContact( | 241 contact_profiles_ = profile_comparator()->FilterProfilesForContact( |
| 244 raw_profiles_for_filtering); | 242 raw_profiles_for_filtering); |
| 243 shipping_profiles_ = profile_comparator()->FilterProfilesForShipping( | |
|
Mathieu
2017/05/16 20:16:51
can you also call this in payment_request.mm (http
tmartino
2017/05/18 20:49:36
Done
| |
| 244 raw_profiles_for_filtering); | |
| 245 | 245 |
| 246 // Create the list of available instruments. A copy of each card will be made | 246 // Create the list of available instruments. A copy of each card will be made |
| 247 // by their respective AutofillPaymentInstrument. | 247 // by their respective AutofillPaymentInstrument. |
| 248 const std::vector<autofill::CreditCard*>& cards = | 248 const std::vector<autofill::CreditCard*>& cards = |
| 249 personal_data_manager_->GetCreditCardsToSuggest(); | 249 personal_data_manager_->GetCreditCardsToSuggest(); |
| 250 for (autofill::CreditCard* card : cards) | 250 for (autofill::CreditCard* card : cards) |
| 251 AddAutofillPaymentInstrument(/*selected=*/false, *card); | 251 AddAutofillPaymentInstrument(/*selected=*/false, *card); |
| 252 } | 252 } |
| 253 | 253 |
| 254 void PaymentRequestState::SetDefaultProfileSelections() { | 254 void PaymentRequestState::SetDefaultProfileSelections() { |
| 255 // Only pre-select an address if the merchant provided at least one selected | 255 // Only pre-select an address if the merchant provided at least one selected |
| 256 // shipping option. | 256 // shipping option. |
| 257 if (!shipping_profiles().empty() && spec_->selected_shipping_option()) { | 257 if (!shipping_profiles().empty() && spec_->selected_shipping_option()) { |
| 258 // Choose any complete shipping profile, or default to the most frecent | 258 // Choose any complete shipping profile, or default to the most frecent |
| 259 // address if no complete address could be found. | 259 // address if no complete address could be found. |
| 260 selected_shipping_profile_ = shipping_profiles_[0]; | 260 selected_shipping_profile_ = shipping_profiles_[0]; |
| 261 for (autofill::AutofillProfile* profile : shipping_profiles_) { | 261 for (autofill::AutofillProfile* profile : shipping_profiles_) { |
|
Mathieu
2017/05/16 20:16:51
can you remove this code? I think we should be goo
tmartino
2017/05/18 20:49:37
Done
| |
| 262 if (profile_comparator_.IsShippingComplete(profile)) { | 262 if (profile_comparator_.IsShippingComplete(profile)) { |
| 263 selected_shipping_profile_ = profile; | 263 selected_shipping_profile_ = profile; |
| 264 break; | 264 break; |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 } | 267 } |
| 268 | 268 |
| 269 // Contact profiles were ordered by completeness in addition to frecency; | 269 // Contact profiles were ordered by completeness in addition to frecency; |
| 270 // the first one is the best default selection. | 270 // the first one is the best default selection. |
| 271 if (!contact_profiles().empty()) | 271 if (!contact_profiles().empty()) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 if (is_waiting_for_merchant_validation_) | 309 if (is_waiting_for_merchant_validation_) |
| 310 return false; | 310 return false; |
| 311 | 311 |
| 312 if (!profile_comparator()->IsShippingComplete(selected_shipping_profile_)) | 312 if (!profile_comparator()->IsShippingComplete(selected_shipping_profile_)) |
| 313 return false; | 313 return false; |
| 314 | 314 |
| 315 return profile_comparator()->IsContactInfoComplete(selected_contact_profile_); | 315 return profile_comparator()->IsContactInfoComplete(selected_contact_profile_); |
| 316 } | 316 } |
| 317 | 317 |
| 318 } // namespace payments | 318 } // namespace payments |
| OLD | NEW |