OLD | NEW |
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/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "components/autofill/core/browser/autofill_data_util.h" | 8 #include "components/autofill/core/browser/autofill_data_util.h" |
9 #include "components/autofill/core/browser/autofill_profile.h" | 9 #include "components/autofill/core/browser/autofill_profile.h" |
10 #include "components/autofill/core/browser/credit_card.h" | 10 #include "components/autofill/core/browser/credit_card.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 void PaymentRequest::PopulateProfileCache() { | 91 void PaymentRequest::PopulateProfileCache() { |
92 const std::vector<autofill::AutofillProfile*>& profiles_to_suggest = | 92 const std::vector<autofill::AutofillProfile*>& profiles_to_suggest = |
93 personal_data_manager_->GetProfilesToSuggest(); | 93 personal_data_manager_->GetProfilesToSuggest(); |
94 profile_cache_.reserve(profiles_to_suggest.size()); | 94 profile_cache_.reserve(profiles_to_suggest.size()); |
95 for (const auto* profile : profiles_to_suggest) { | 95 for (const auto* profile : profiles_to_suggest) { |
96 profile_cache_.push_back(*profile); | 96 profile_cache_.push_back(*profile); |
97 shipping_profiles_.push_back(&profile_cache_.back()); | 97 shipping_profiles_.push_back(&profile_cache_.back()); |
98 contact_profiles_.push_back(&profile_cache_.back()); | 98 contact_profiles_.push_back(&profile_cache_.back()); |
99 } | 99 } |
100 | 100 |
| 101 payments::PaymentsProfileComparator comparator( |
| 102 GetApplicationContext()->GetApplicationLocale(), *this); |
| 103 |
101 // TODO(crbug.com/602666): Implement deduplication and prioritization rules | 104 // TODO(crbug.com/602666): Implement deduplication and prioritization rules |
102 // for shipping profiles. | 105 // for shipping profiles. |
103 | 106 |
104 contact_profiles_ = payments::profile_util::FilterProfilesForContact( | 107 contact_profiles_ = comparator.FilterProfilesForContact(contact_profiles_); |
105 contact_profiles_, GetApplicationContext()->GetApplicationLocale(), | |
106 *this); | |
107 | 108 |
108 if (!shipping_profiles_.empty()) | 109 if (!shipping_profiles_.empty()) |
109 selected_shipping_profile_ = shipping_profiles_[0]; | 110 selected_shipping_profile_ = shipping_profiles_[0]; |
110 if (!contact_profiles_.empty()) | 111 if (!contact_profiles_.empty() && |
| 112 comparator.IsContactInfoComplete(contact_profiles_[0])) { |
111 selected_contact_profile_ = contact_profiles_[0]; | 113 selected_contact_profile_ = contact_profiles_[0]; |
| 114 } |
112 } | 115 } |
113 | 116 |
114 void PaymentRequest::PopulateCreditCardCache() { | 117 void PaymentRequest::PopulateCreditCardCache() { |
115 // TODO(crbug.com/709036): Validate method data. | 118 // TODO(crbug.com/709036): Validate method data. |
116 payments::data_util::ParseBasicCardSupportedNetworks( | 119 payments::data_util::ParseBasicCardSupportedNetworks( |
117 web_payment_request_.method_data, &supported_card_networks_, | 120 web_payment_request_.method_data, &supported_card_networks_, |
118 &basic_card_specified_networks_); | 121 &basic_card_specified_networks_); |
119 | 122 |
120 const std::vector<autofill::CreditCard*>& credit_cards_to_suggest = | 123 const std::vector<autofill::CreditCard*>& credit_cards_to_suggest = |
121 personal_data_manager_->GetCreditCardsToSuggest(); | 124 personal_data_manager_->GetCreditCardsToSuggest(); |
(...skipping 28 matching lines...) Expand all Loading... |
150 | 153 |
151 selected_shipping_option_ = nullptr; | 154 selected_shipping_option_ = nullptr; |
152 for (auto* shipping_option : shipping_options_) { | 155 for (auto* shipping_option : shipping_options_) { |
153 if (shipping_option->selected) { | 156 if (shipping_option->selected) { |
154 // If more than one option has |selected| set, the last one in the | 157 // If more than one option has |selected| set, the last one in the |
155 // sequence should be treated as the selected item. | 158 // sequence should be treated as the selected item. |
156 selected_shipping_option_ = shipping_option; | 159 selected_shipping_option_ = shipping_option; |
157 } | 160 } |
158 } | 161 } |
159 } | 162 } |
OLD | NEW |