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/containers/adapters.h" | 7 #include "base/containers/adapters.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/stl_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
10 #include "components/autofill/core/browser/autofill_data_util.h" | 11 #include "components/autofill/core/browser/autofill_data_util.h" |
11 #include "components/autofill/core/browser/autofill_profile.h" | 12 #include "components/autofill/core/browser/autofill_profile.h" |
12 #include "components/autofill/core/browser/credit_card.h" | 13 #include "components/autofill/core/browser/credit_card.h" |
13 #include "components/autofill/core/browser/personal_data_manager.h" | 14 #include "components/autofill/core/browser/personal_data_manager.h" |
14 #include "components/autofill/core/browser/region_data_loader_impl.h" | 15 #include "components/autofill/core/browser/region_data_loader_impl.h" |
15 #include "components/payments/core/currency_formatter.h" | 16 #include "components/payments/core/currency_formatter.h" |
16 #include "components/payments/core/payment_request_data_util.h" | 17 #include "components/payments/core/payment_request_data_util.h" |
17 #include "ios/chrome/browser/application_context.h" | 18 #include "ios/chrome/browser/application_context.h" |
18 #include "ios/chrome/browser/autofill/validation_rules_storage_factory.h" | 19 #include "ios/chrome/browser/autofill/validation_rules_storage_factory.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 // Return early if the user has no stored credit cards. | 201 // Return early if the user has no stored credit cards. |
201 if (credit_cards_to_suggest.empty()) | 202 if (credit_cards_to_suggest.empty()) |
202 return; | 203 return; |
203 | 204 |
204 credit_card_cache_.reserve(credit_cards_to_suggest.size()); | 205 credit_card_cache_.reserve(credit_cards_to_suggest.size()); |
205 | 206 |
206 for (const auto* credit_card : credit_cards_to_suggest) { | 207 for (const auto* credit_card : credit_cards_to_suggest) { |
207 std::string spec_issuer_network = | 208 std::string spec_issuer_network = |
208 autofill::data_util::GetPaymentRequestData(credit_card->network()) | 209 autofill::data_util::GetPaymentRequestData(credit_card->network()) |
209 .basic_card_issuer_network; | 210 .basic_card_issuer_network; |
210 if (std::find(supported_card_networks_.begin(), | 211 if (base::ContainsValue(supported_cards_networks_, spec_issuer_network)) { |
211 supported_card_networks_.end(), | |
212 spec_issuer_network) != supported_card_networks_.end()) { | |
213 credit_card_cache_.push_back( | 212 credit_card_cache_.push_back( |
214 base::MakeUnique<autofill::CreditCard>(*credit_card)); | 213 base::MakeUnique<autofill::CreditCard>(*credit_card)); |
215 } | 214 } |
216 } | 215 } |
217 } | 216 } |
218 | 217 |
219 void PaymentRequest::PopulateAvailableCreditCards() { | 218 void PaymentRequest::PopulateAvailableCreditCards() { |
220 if (credit_card_cache_.empty()) | 219 if (credit_card_cache_.empty()) |
221 return; | 220 return; |
222 | 221 |
(...skipping 23 matching lines...) Expand all Loading... |
246 void PaymentRequest::SetSelectedShippingOption() { | 245 void PaymentRequest::SetSelectedShippingOption() { |
247 // If more than one option has |selected| set, the last one in the sequence | 246 // If more than one option has |selected| set, the last one in the sequence |
248 // should be treated as the selected item. | 247 // should be treated as the selected item. |
249 for (auto* shipping_option : base::Reversed(shipping_options_)) { | 248 for (auto* shipping_option : base::Reversed(shipping_options_)) { |
250 if (shipping_option->selected) { | 249 if (shipping_option->selected) { |
251 selected_shipping_option_ = shipping_option; | 250 selected_shipping_option_ = shipping_option; |
252 break; | 251 break; |
253 } | 252 } |
254 } | 253 } |
255 } | 254 } |
OLD | NEW |