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

Unified Diff: ios/chrome/browser/payments/payment_request.mm

Issue 2750363002: [Payment Request] supported card networks + adding a credit card. (Closed)
Patch Set: Addressed comments Created 3 years, 9 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: ios/chrome/browser/payments/payment_request.mm
diff --git a/ios/chrome/browser/payments/payment_request.mm b/ios/chrome/browser/payments/payment_request.mm
index 68e0830fcad0470fe87cee6bf7359fdf1c2263a3..9d2109b45944c3fb128266ffa4605dc2e74f905b 100644
--- a/ios/chrome/browser/payments/payment_request.mm
+++ b/ios/chrome/browser/payments/payment_request.mm
@@ -4,8 +4,7 @@
#include "ios/chrome/browser/payments/payment_request.h"
-#include <unordered_set>
-
+#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/autofill_data_util.h"
#include "components/autofill/core/browser/autofill_profile.h"
@@ -53,6 +52,12 @@ payments::CurrencyFormatter* PaymentRequest::GetOrCreateCurrencyFormatter() {
return currency_formatter_.get();
}
+void PaymentRequest::AddCreditCard(
+ std::unique_ptr<autofill::CreditCard> credit_card) {
+ credit_card_cache_.insert(credit_card_cache_.begin(), std::move(credit_card));
+ credit_cards_.insert(credit_cards_.begin(), credit_card_cache_.front().get());
+}
+
void PaymentRequest::PopulateProfileCache() {
for (const auto* profile : personal_data_manager_->GetProfilesToSuggest()) {
profile_cache_.push_back(
@@ -73,10 +78,14 @@ void PaymentRequest::PopulateProfileCache() {
void PaymentRequest::PopulateCreditCardCache() {
DCHECK(web_payment_request_);
- std::unordered_set<base::string16> supported_method_types;
for (const auto& method_data : web_payment_request_->method_data) {
- for (const auto& supported_method : method_data.supported_methods)
- supported_method_types.insert(supported_method);
+ for (const auto& supported_method : method_data.supported_methods) {
+ // Reject non-ASCII supported methods.
+ if (base::IsStringASCII(supported_method)) {
+ supported_card_networks_.push_back(
+ base::UTF16ToASCII(supported_method));
+ }
+ }
}
std::vector<autofill::CreditCard*> credit_cards =
@@ -91,8 +100,9 @@ void PaymentRequest::PopulateCreditCardCache() {
std::string spec_card_type =
autofill::data_util::GetPaymentRequestData(credit_card->type())
.basic_card_payment_type;
- if (supported_method_types.find(base::ASCIIToUTF16(spec_card_type)) !=
- supported_method_types.end()) {
+ if (std::find(supported_card_networks_.begin(),
+ supported_card_networks_.end(),
+ spec_card_type) != supported_card_networks_.end()) {
credit_card_cache_.push_back(
base::MakeUnique<autofill::CreditCard>(*credit_card));
credit_cards_.push_back(credit_card_cache_.back().get());
« no previous file with comments | « ios/chrome/browser/payments/payment_request.h ('k') | ios/chrome/browser/payments/payment_request_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698