| 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/core/payment_instrument.h" | 15 #include "components/payments/core/payment_instrument.h" |
| 15 | 16 |
| 16 namespace autofill { | 17 namespace autofill { |
| 17 class AutofillProfile; | 18 class AutofillProfile; |
| 18 class PersonalDataManager; | 19 class PersonalDataManager; |
| 19 } // namespace autofill | 20 } // namespace autofill |
| 20 | 21 |
| 21 namespace payments { | 22 namespace payments { |
| 22 | 23 |
| 24 class PaymentRequestDelegate; |
| 23 class PaymentRequestSpec; | 25 class PaymentRequestSpec; |
| 24 | 26 |
| 25 // 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 |
| 26 // 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 |
| 27 // 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" |
| 28 // computation. | 30 // computation. |
| 29 class PaymentRequestState : public PaymentInstrument::Delegate { | 31 class PaymentRequestState : public PaymentInstrument::Delegate { |
| 30 public: | 32 public: |
| 31 // Any class call add itself as Observer via AddObserver() and receive | 33 // Any class call add itself as Observer via AddObserver() and receive |
| 32 // notification about the state changing. | 34 // notification about the state changing. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 53 virtual void OnShippingAddressSelected( | 55 virtual void OnShippingAddressSelected( |
| 54 mojom::PaymentAddressPtr address) = 0; | 56 mojom::PaymentAddressPtr address) = 0; |
| 55 | 57 |
| 56 protected: | 58 protected: |
| 57 virtual ~Delegate() {} | 59 virtual ~Delegate() {} |
| 58 }; | 60 }; |
| 59 | 61 |
| 60 PaymentRequestState(PaymentRequestSpec* spec, | 62 PaymentRequestState(PaymentRequestSpec* spec, |
| 61 Delegate* delegate, | 63 Delegate* delegate, |
| 62 const std::string& app_locale, | 64 const std::string& app_locale, |
| 63 autofill::PersonalDataManager* personal_data_manager); | 65 autofill::PersonalDataManager* personal_data_manager, |
| 66 PaymentRequestDelegate* payment_request_delegate); |
| 64 ~PaymentRequestState() override; | 67 ~PaymentRequestState() override; |
| 65 | 68 |
| 66 // Returns whether the user has at least one instrument that satisfies the | 69 // Returns whether the user has at least one instrument that satisfies the |
| 67 // specified supported payment methods. | 70 // specified supported payment methods. |
| 68 bool CanMakePayment() const; | 71 bool CanMakePayment() const; |
| 69 void AddObserver(Observer* observer); | 72 void AddObserver(Observer* observer); |
| 70 void RemoveObserver(Observer* observer); | 73 void RemoveObserver(Observer* observer); |
| 71 | 74 |
| 72 // PaymentInstrument::Delegate: | 75 // PaymentInstrument::Delegate: |
| 73 void OnInstrumentDetailsReady( | 76 void OnInstrumentDetailsReady( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 void SetSelectedShippingOption(const std::string& shipping_option_id); | 116 void SetSelectedShippingOption(const std::string& shipping_option_id); |
| 114 void SetSelectedShippingProfile(autofill::AutofillProfile* profile); | 117 void SetSelectedShippingProfile(autofill::AutofillProfile* profile); |
| 115 void SetSelectedContactProfile(autofill::AutofillProfile* profile); | 118 void SetSelectedContactProfile(autofill::AutofillProfile* profile); |
| 116 void SetSelectedInstrument(PaymentInstrument* instrument); | 119 void SetSelectedInstrument(PaymentInstrument* instrument); |
| 117 | 120 |
| 118 bool is_ready_to_pay() { return is_ready_to_pay_; } | 121 bool is_ready_to_pay() { return is_ready_to_pay_; } |
| 119 | 122 |
| 120 const std::string& GetApplicationLocale(); | 123 const std::string& GetApplicationLocale(); |
| 121 autofill::PersonalDataManager* GetPersonalDataManager(); | 124 autofill::PersonalDataManager* GetPersonalDataManager(); |
| 122 | 125 |
| 126 Delegate* delegate() { return delegate_; } |
| 127 |
| 123 private: | 128 private: |
| 124 // Fetches the Autofill Profiles for this user from the PersonalDataManager, | 129 // Fetches the Autofill Profiles for this user from the PersonalDataManager, |
| 125 // and stores copies of them, owned by this PaymentRequestState, in | 130 // and stores copies of them, owned by this PaymentRequestState, in |
| 126 // profile_cache_. | 131 // profile_cache_. |
| 127 void PopulateProfileCache(); | 132 void PopulateProfileCache(); |
| 128 | 133 |
| 129 // Sets the initial selections for instruments and profiles, and notifies | 134 // Sets the initial selections for instruments and profiles, and notifies |
| 130 // observers. | 135 // observers. |
| 131 void SetDefaultProfileSelections(); | 136 void SetDefaultProfileSelections(); |
| 132 | 137 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 160 | 165 |
| 161 // Profiles may change due to (e.g.) sync events, so profiles are cached after | 166 // Profiles may change due to (e.g.) sync events, so profiles are cached after |
| 162 // loading and owned here. They are populated once only, and ordered by | 167 // loading and owned here. They are populated once only, and ordered by |
| 163 // frecency. | 168 // frecency. |
| 164 std::vector<std::unique_ptr<autofill::AutofillProfile>> profile_cache_; | 169 std::vector<std::unique_ptr<autofill::AutofillProfile>> profile_cache_; |
| 165 std::vector<autofill::AutofillProfile*> shipping_profiles_; | 170 std::vector<autofill::AutofillProfile*> shipping_profiles_; |
| 166 std::vector<autofill::AutofillProfile*> contact_profiles_; | 171 std::vector<autofill::AutofillProfile*> contact_profiles_; |
| 167 // Credit cards are directly owned by the instruments in this list. | 172 // Credit cards are directly owned by the instruments in this list. |
| 168 std::vector<std::unique_ptr<PaymentInstrument>> available_instruments_; | 173 std::vector<std::unique_ptr<PaymentInstrument>> available_instruments_; |
| 169 | 174 |
| 175 PaymentRequestDelegate* payment_request_delegate_; |
| 176 |
| 170 base::ObserverList<Observer> observers_; | 177 base::ObserverList<Observer> observers_; |
| 171 | 178 |
| 172 DISALLOW_COPY_AND_ASSIGN(PaymentRequestState); | 179 DISALLOW_COPY_AND_ASSIGN(PaymentRequestState); |
| 173 }; | 180 }; |
| 174 | 181 |
| 175 } // namespace payments | 182 } // namespace payments |
| 176 | 183 |
| 177 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ | 184 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ |
| OLD | NEW |