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