| 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 |
| 23 class PaymentRequestSpec; | 24 class PaymentRequestSpec; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 53 virtual void OnShippingAddressSelected( | 54 virtual void OnShippingAddressSelected( |
| 54 mojom::PaymentAddressPtr address) = 0; | 55 mojom::PaymentAddressPtr address) = 0; |
| 55 | 56 |
| 56 protected: | 57 protected: |
| 57 virtual ~Delegate() {} | 58 virtual ~Delegate() {} |
| 58 }; | 59 }; |
| 59 | 60 |
| 60 PaymentRequestState(PaymentRequestSpec* spec, | 61 PaymentRequestState(PaymentRequestSpec* spec, |
| 61 Delegate* delegate, | 62 Delegate* delegate, |
| 62 const std::string& app_locale, | 63 const std::string& app_locale, |
| 63 autofill::PersonalDataManager* personal_data_manager); | 64 autofill::PersonalDataManager* personal_data_manager, |
| 65 AutofillPaymentInstrument::FullCardRequestDelegate* |
| 66 full_card_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 AutofillPaymentInstrument::FullCardRequestDelegate* |
| 176 full_card_request_delegate_; |
| 177 |
| 170 base::ObserverList<Observer> observers_; | 178 base::ObserverList<Observer> observers_; |
| 171 | 179 |
| 172 DISALLOW_COPY_AND_ASSIGN(PaymentRequestState); | 180 DISALLOW_COPY_AND_ASSIGN(PaymentRequestState); |
| 173 }; | 181 }; |
| 174 | 182 |
| 175 } // namespace payments | 183 } // namespace payments |
| 176 | 184 |
| 177 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ | 185 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ |
| OLD | NEW |