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

Side by Side Diff: components/payments/content/payment_request_state.cc

Issue 2766353004: [Payments] Support canMakePayment on Desktop (Closed)
Patch Set: only support valid instruments, added test 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 unified diff | Download patch
OLDNEW
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 <set> 7 #include <set>
8 8
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 16 matching lines...) Expand all
27 personal_data_manager_(personal_data_manager), 27 personal_data_manager_(personal_data_manager),
28 selected_shipping_profile_(nullptr), 28 selected_shipping_profile_(nullptr),
29 selected_contact_profile_(nullptr), 29 selected_contact_profile_(nullptr),
30 selected_instrument_(nullptr), 30 selected_instrument_(nullptr),
31 selected_shipping_option_(nullptr) { 31 selected_shipping_option_(nullptr) {
32 PopulateProfileCache(); 32 PopulateProfileCache();
33 UpdateSelectedShippingOption(); 33 UpdateSelectedShippingOption();
34 SetDefaultProfileSelections(); 34 SetDefaultProfileSelections();
35 } 35 }
36 36
37 bool PaymentRequestState::CanMakePayment() const {
38 // TODO(crbug.com/704675): Handle incognito mode when replying to this method.
39 for (const std::unique_ptr<PaymentInstrument>& instrument :
40 available_instruments_) {
41 if (instrument.get()->IsValid() &&
42 spec_->supported_card_networks_set().count(
43 instrument.get()->method_name())) {
44 return true;
45 }
46 }
47 return false;
48 }
49
37 void PaymentRequestState::AddObserver(Observer* observer) { 50 void PaymentRequestState::AddObserver(Observer* observer) {
38 CHECK(observer); 51 CHECK(observer);
39 observers_.AddObserver(observer); 52 observers_.AddObserver(observer);
40 } 53 }
41 PaymentRequestState::~PaymentRequestState() {} 54 PaymentRequestState::~PaymentRequestState() {}
42 55
43 void PaymentRequestState::RemoveObserver(Observer* observer) { 56 void PaymentRequestState::RemoveObserver(Observer* observer) {
44 observers_.RemoveObserver(observer); 57 observers_.RemoveObserver(observer);
45 } 58 }
46 59
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 spec_->details().shipping_options.rend(), 233 spec_->details().shipping_options.rend(),
221 [](const payments::mojom::PaymentShippingOptionPtr& element) { 234 [](const payments::mojom::PaymentShippingOptionPtr& element) {
222 return element->selected; 235 return element->selected;
223 }); 236 });
224 if (selected_shipping_option_it != spec_->details().shipping_options.rend()) { 237 if (selected_shipping_option_it != spec_->details().shipping_options.rend()) {
225 selected_shipping_option_ = selected_shipping_option_it->get(); 238 selected_shipping_option_ = selected_shipping_option_it->get();
226 } 239 }
227 } 240 }
228 241
229 } // namespace payments 242 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/content/payment_request_state.h ('k') | components/payments/content/payment_request_state_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698