| 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/payment_instrument.h" | 14 #include "components/payments/core/payment_instrument.h" |
| 15 | 15 |
| 16 namespace autofill { | 16 namespace autofill { |
| 17 class AutofillProfile; | 17 class AutofillProfile; |
| 18 class PersonalDataManager; | 18 class PersonalDataManager; |
| 19 } // namespace autofill | 19 } // namespace autofill |
| 20 | 20 |
| 21 namespace payments { | 21 namespace payments { |
| 22 | 22 |
| 23 class PaymentRequestSpec; | 23 class PaymentRequestSpec; |
| 24 class PaymentRequestDelegate; |
| 24 | 25 |
| 25 // Keeps track of the information currently selected by the user and whether the | 26 // Keeps track of the information currently selected by the user and whether the |
| 26 // user is ready to pay. Uses information from the PaymentRequestSpec, which is | 27 // user is ready to pay. Uses information from the PaymentRequestSpec, which is |
| 27 // what the merchant has specified, as input into the "is ready to pay" | 28 // what the merchant has specified, as input into the "is ready to pay" |
| 28 // computation. | 29 // computation. |
| 29 class PaymentRequestState : public PaymentInstrument::Delegate { | 30 class PaymentRequestState : public PaymentInstrument::Delegate { |
| 30 public: | 31 public: |
| 31 // Any class call add itself as Observer via AddObserver() and receive | 32 // Any class call add itself as Observer via AddObserver() and receive |
| 32 // notification about the state changing. | 33 // notification about the state changing. |
| 33 class Observer { | 34 class Observer { |
| 34 public: | 35 public: |
| 35 // Called when the information (payment method, address/contact info, | 36 // Called when the information (payment method, address/contact info, |
| 36 // shipping option) changes. | 37 // shipping option) changes. |
| 37 virtual void OnSelectedInformationChanged() = 0; | 38 virtual void OnSelectedInformationChanged() = 0; |
| 38 | 39 |
| 39 protected: | 40 protected: |
| 40 virtual ~Observer() {} | 41 virtual ~Observer() {} |
| 41 }; | 42 }; |
| 42 | 43 |
| 43 class Delegate { | 44 class Delegate { |
| 44 public: | 45 public: |
| 45 // Called when the PaymentResponse is available. | 46 // Called when the PaymentResponse is available. |
| 46 virtual void OnPaymentResponseAvailable( | 47 virtual void OnPaymentResponseAvailable( |
| 47 mojom::PaymentResponsePtr response) = 0; | 48 mojom::PaymentResponsePtr response) = 0; |
| 49 virtual PaymentRequestDelegate* GetPaymentRequestDelegate() = 0; |
| 48 | 50 |
| 49 protected: | 51 protected: |
| 50 virtual ~Delegate() {} | 52 virtual ~Delegate() {} |
| 51 }; | 53 }; |
| 52 | 54 |
| 53 PaymentRequestState(PaymentRequestSpec* spec, | 55 PaymentRequestState(PaymentRequestSpec* spec, |
| 54 Delegate* delegate, | 56 Delegate* delegate, |
| 55 const std::string& app_locale, | 57 const std::string& app_locale, |
| 56 autofill::PersonalDataManager* personal_data_manager); | 58 autofill::PersonalDataManager* personal_data_manager); |
| 57 ~PaymentRequestState() override; | 59 ~PaymentRequestState() override; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 void SetSelectedShippingOption(mojom::PaymentShippingOption* option); | 111 void SetSelectedShippingOption(mojom::PaymentShippingOption* option); |
| 110 void SetSelectedShippingProfile(autofill::AutofillProfile* profile); | 112 void SetSelectedShippingProfile(autofill::AutofillProfile* profile); |
| 111 void SetSelectedContactProfile(autofill::AutofillProfile* profile); | 113 void SetSelectedContactProfile(autofill::AutofillProfile* profile); |
| 112 void SetSelectedInstrument(PaymentInstrument* instrument); | 114 void SetSelectedInstrument(PaymentInstrument* instrument); |
| 113 | 115 |
| 114 bool is_ready_to_pay() { return is_ready_to_pay_; } | 116 bool is_ready_to_pay() { return is_ready_to_pay_; } |
| 115 | 117 |
| 116 const std::string& GetApplicationLocale(); | 118 const std::string& GetApplicationLocale(); |
| 117 autofill::PersonalDataManager* GetPersonalDataManager(); | 119 autofill::PersonalDataManager* GetPersonalDataManager(); |
| 118 | 120 |
| 121 Delegate* delegate() { return delegate_; } |
| 122 |
| 119 private: | 123 private: |
| 120 // Fetches the Autofill Profiles for this user from the PersonalDataManager, | 124 // Fetches the Autofill Profiles for this user from the PersonalDataManager, |
| 121 // and stores copies of them, owned by this PaymentRequestState, in | 125 // and stores copies of them, owned by this PaymentRequestState, in |
| 122 // profile_cache_. | 126 // profile_cache_. |
| 123 void PopulateProfileCache(); | 127 void PopulateProfileCache(); |
| 124 | 128 |
| 125 // Sets the initial selections for instruments and profiles, and notifies | 129 // Sets the initial selections for instruments and profiles, and notifies |
| 126 // observers. | 130 // observers. |
| 127 void SetDefaultProfileSelections(); | 131 void SetDefaultProfileSelections(); |
| 128 | 132 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 std::vector<std::unique_ptr<PaymentInstrument>> available_instruments_; | 176 std::vector<std::unique_ptr<PaymentInstrument>> available_instruments_; |
| 173 | 177 |
| 174 base::ObserverList<Observer> observers_; | 178 base::ObserverList<Observer> observers_; |
| 175 | 179 |
| 176 DISALLOW_COPY_AND_ASSIGN(PaymentRequestState); | 180 DISALLOW_COPY_AND_ASSIGN(PaymentRequestState); |
| 177 }; | 181 }; |
| 178 | 182 |
| 179 } // namespace payments | 183 } // namespace payments |
| 180 | 184 |
| 181 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ | 185 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ |
| OLD | NEW |