| 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 #ifndef COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ | 5 #ifndef COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ |
| 6 #define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ | 6 #define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
| 13 #include "components/payments/content/payment_request.mojom.h" | 13 #include "components/payments/content/payment_request.mojom.h" |
| 14 #include "components/payments/content/payment_response_helper.h" |
| 14 #include "components/payments/core/autofill_payment_instrument.h" | 15 #include "components/payments/core/autofill_payment_instrument.h" |
| 15 #include "components/payments/core/payment_instrument.h" | 16 #include "components/payments/core/payment_instrument.h" |
| 16 | 17 |
| 17 namespace autofill { | 18 namespace autofill { |
| 18 class AutofillProfile; | 19 class AutofillProfile; |
| 19 class PersonalDataManager; | 20 class PersonalDataManager; |
| 20 } // namespace autofill | 21 } // namespace autofill |
| 21 | 22 |
| 22 namespace payments { | 23 namespace payments { |
| 23 | 24 |
| 24 class PaymentRequestDelegate; | 25 class PaymentRequestDelegate; |
| 25 class PaymentRequestSpec; | 26 class PaymentRequestSpec; |
| 26 | 27 |
| 27 // Keeps track of the information currently selected by the user and whether the | 28 // Keeps track of the information currently selected by the user and whether the |
| 28 // user is ready to pay. Uses information from the PaymentRequestSpec, which is | 29 // user is ready to pay. Uses information from the PaymentRequestSpec, which is |
| 29 // what the merchant has specified, as input into the "is ready to pay" | 30 // what the merchant has specified, as input into the "is ready to pay" |
| 30 // computation. | 31 // computation. |
| 31 class PaymentRequestState : public PaymentInstrument::Delegate { | 32 class PaymentRequestState : public PaymentResponseHelper::Delegate { |
| 32 public: | 33 public: |
| 33 // Any class call add itself as Observer via AddObserver() and receive | 34 // Any class call add itself as Observer via AddObserver() and receive |
| 34 // notification about the state changing. | 35 // notification about the state changing. |
| 35 class Observer { | 36 class Observer { |
| 36 public: | 37 public: |
| 37 // Called when the information (payment method, address/contact info, | 38 // Called when the information (payment method, address/contact info, |
| 38 // shipping option) changes. | 39 // shipping option) changes. |
| 39 virtual void OnSelectedInformationChanged() = 0; | 40 virtual void OnSelectedInformationChanged() = 0; |
| 40 | 41 |
| 41 protected: | 42 protected: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 59 virtual ~Delegate() {} | 60 virtual ~Delegate() {} |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 PaymentRequestState(PaymentRequestSpec* spec, | 63 PaymentRequestState(PaymentRequestSpec* spec, |
| 63 Delegate* delegate, | 64 Delegate* delegate, |
| 64 const std::string& app_locale, | 65 const std::string& app_locale, |
| 65 autofill::PersonalDataManager* personal_data_manager, | 66 autofill::PersonalDataManager* personal_data_manager, |
| 66 PaymentRequestDelegate* payment_request_delegate); | 67 PaymentRequestDelegate* payment_request_delegate); |
| 67 ~PaymentRequestState() override; | 68 ~PaymentRequestState() override; |
| 68 | 69 |
| 70 // PaymentResponseHelper::Delegate |
| 71 void OnPaymentResponseReady( |
| 72 mojom::PaymentResponsePtr payment_response) override; |
| 73 |
| 69 // Returns whether the user has at least one instrument that satisfies the | 74 // Returns whether the user has at least one instrument that satisfies the |
| 70 // specified supported payment methods. | 75 // specified supported payment methods. |
| 71 bool CanMakePayment() const; | 76 bool CanMakePayment() const; |
| 72 void AddObserver(Observer* observer); | 77 void AddObserver(Observer* observer); |
| 73 void RemoveObserver(Observer* observer); | 78 void RemoveObserver(Observer* observer); |
| 74 | 79 |
| 75 // PaymentInstrument::Delegate: | |
| 76 void OnInstrumentDetailsReady( | |
| 77 const std::string& method_name, | |
| 78 const std::string& stringified_details) override; | |
| 79 void OnInstrumentDetailsError() override {} | |
| 80 | |
| 81 // Initiates the generation of the PaymentResponse. Callers should check | 80 // Initiates the generation of the PaymentResponse. Callers should check |
| 82 // |is_ready_to_pay|, which is inexpensive. | 81 // |is_ready_to_pay|, which is inexpensive. |
| 83 void GeneratePaymentResponse(); | 82 void GeneratePaymentResponse(); |
| 84 | 83 |
| 85 // Gets the Autofill Profile representing the shipping address or contact | 84 // Gets the Autofill Profile representing the shipping address or contact |
| 86 // information currently selected for this PaymentRequest flow. Can return | 85 // information currently selected for this PaymentRequest flow. Can return |
| 87 // null. | 86 // null. |
| 88 autofill::AutofillProfile* selected_shipping_profile() const { | 87 autofill::AutofillProfile* selected_shipping_profile() const { |
| 89 return selected_shipping_profile_; | 88 return selected_shipping_profile_; |
| 90 } | 89 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 // loading and owned here. They are populated once only, and ordered by | 166 // loading and owned here. They are populated once only, and ordered by |
| 168 // frecency. | 167 // frecency. |
| 169 std::vector<std::unique_ptr<autofill::AutofillProfile>> profile_cache_; | 168 std::vector<std::unique_ptr<autofill::AutofillProfile>> profile_cache_; |
| 170 std::vector<autofill::AutofillProfile*> shipping_profiles_; | 169 std::vector<autofill::AutofillProfile*> shipping_profiles_; |
| 171 std::vector<autofill::AutofillProfile*> contact_profiles_; | 170 std::vector<autofill::AutofillProfile*> contact_profiles_; |
| 172 // Credit cards are directly owned by the instruments in this list. | 171 // Credit cards are directly owned by the instruments in this list. |
| 173 std::vector<std::unique_ptr<PaymentInstrument>> available_instruments_; | 172 std::vector<std::unique_ptr<PaymentInstrument>> available_instruments_; |
| 174 | 173 |
| 175 PaymentRequestDelegate* payment_request_delegate_; | 174 PaymentRequestDelegate* payment_request_delegate_; |
| 176 | 175 |
| 176 std::unique_ptr<PaymentResponseHelper> response_helper_; |
| 177 |
| 177 base::ObserverList<Observer> observers_; | 178 base::ObserverList<Observer> observers_; |
| 178 | 179 |
| 179 DISALLOW_COPY_AND_ASSIGN(PaymentRequestState); | 180 DISALLOW_COPY_AND_ASSIGN(PaymentRequestState); |
| 180 }; | 181 }; |
| 181 | 182 |
| 182 } // namespace payments | 183 } // namespace payments |
| 183 | 184 |
| 184 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ | 185 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ |
| OLD | NEW |