| 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 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 protected: | 39 protected: |
| 40 virtual ~Observer() {} | 40 virtual ~Observer() {} |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 class Delegate { | 43 class Delegate { |
| 44 public: | 44 public: |
| 45 // Called when the PaymentResponse is available. | 45 // Called when the PaymentResponse is available. |
| 46 virtual void OnPaymentResponseAvailable( | 46 virtual void OnPaymentResponseAvailable( |
| 47 mojom::PaymentResponsePtr response) = 0; | 47 mojom::PaymentResponsePtr response) = 0; |
| 48 | 48 |
| 49 // Called when the shipping option has changed to |shipping_option_id|. |
| 50 virtual void OnShippingOptionIdSelected( |
| 51 const std::string& shipping_option_id) = 0; |
| 52 |
| 53 // Called when the shipping address has changed to |address|. |
| 54 virtual void OnShippingAddressSelected( |
| 55 mojom::PaymentAddressPtr address) = 0; |
| 56 |
| 49 protected: | 57 protected: |
| 50 virtual ~Delegate() {} | 58 virtual ~Delegate() {} |
| 51 }; | 59 }; |
| 52 | 60 |
| 53 PaymentRequestState(PaymentRequestSpec* spec, | 61 PaymentRequestState(PaymentRequestSpec* spec, |
| 54 Delegate* delegate, | 62 Delegate* delegate, |
| 55 const std::string& app_locale, | 63 const std::string& app_locale, |
| 56 autofill::PersonalDataManager* personal_data_manager); | 64 autofill::PersonalDataManager* personal_data_manager); |
| 57 ~PaymentRequestState() override; | 65 ~PaymentRequestState() override; |
| 58 | 66 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 80 } | 88 } |
| 81 autofill::AutofillProfile* selected_contact_profile() const { | 89 autofill::AutofillProfile* selected_contact_profile() const { |
| 82 return selected_contact_profile_; | 90 return selected_contact_profile_; |
| 83 } | 91 } |
| 84 // Returns the currently selected instrument for this PaymentRequest flow. | 92 // Returns the currently selected instrument for this PaymentRequest flow. |
| 85 // It's not guaranteed to be complete. Returns nullptr if there is no selected | 93 // It's not guaranteed to be complete. Returns nullptr if there is no selected |
| 86 // instrument. | 94 // instrument. |
| 87 PaymentInstrument* selected_instrument() const { | 95 PaymentInstrument* selected_instrument() const { |
| 88 return selected_instrument_; | 96 return selected_instrument_; |
| 89 } | 97 } |
| 90 mojom::PaymentShippingOption* selected_shipping_option() { | |
| 91 return selected_shipping_option_; | |
| 92 } | |
| 93 | 98 |
| 94 // Returns the appropriate Autofill Profiles for this user. The profiles | 99 // Returns the appropriate Autofill Profiles for this user. The profiles |
| 95 // returned are owned by the PaymentRequestState. | 100 // returned are owned by the PaymentRequestState. |
| 96 const std::vector<autofill::AutofillProfile*>& shipping_profiles() { | 101 const std::vector<autofill::AutofillProfile*>& shipping_profiles() { |
| 97 return shipping_profiles_; | 102 return shipping_profiles_; |
| 98 } | 103 } |
| 99 const std::vector<autofill::AutofillProfile*>& contact_profiles() { | 104 const std::vector<autofill::AutofillProfile*>& contact_profiles() { |
| 100 return contact_profiles_; | 105 return contact_profiles_; |
| 101 } | 106 } |
| 102 const std::vector<std::unique_ptr<PaymentInstrument>>& | 107 const std::vector<std::unique_ptr<PaymentInstrument>>& |
| 103 available_instruments() { | 108 available_instruments() { |
| 104 return available_instruments_; | 109 return available_instruments_; |
| 105 } | 110 } |
| 106 | 111 |
| 107 // Setters to change the selected information. Will have the side effect of | 112 // Setters to change the selected information. Will have the side effect of |
| 108 // recomputing "is ready to pay" and notify observers. | 113 // recomputing "is ready to pay" and notify observers. |
| 109 void SetSelectedShippingOption(mojom::PaymentShippingOption* option); | 114 void SetSelectedShippingOption(const std::string& shipping_option_id); |
| 110 void SetSelectedShippingProfile(autofill::AutofillProfile* profile); | 115 void SetSelectedShippingProfile(autofill::AutofillProfile* profile); |
| 111 void SetSelectedContactProfile(autofill::AutofillProfile* profile); | 116 void SetSelectedContactProfile(autofill::AutofillProfile* profile); |
| 112 void SetSelectedInstrument(PaymentInstrument* instrument); | 117 void SetSelectedInstrument(PaymentInstrument* instrument); |
| 113 | 118 |
| 114 bool is_ready_to_pay() { return is_ready_to_pay_; } | 119 bool is_ready_to_pay() { return is_ready_to_pay_; } |
| 115 | 120 |
| 116 const std::string& GetApplicationLocale(); | 121 const std::string& GetApplicationLocale(); |
| 117 autofill::PersonalDataManager* GetPersonalDataManager(); | 122 autofill::PersonalDataManager* GetPersonalDataManager(); |
| 118 | 123 |
| 119 private: | 124 private: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 134 // Notifies all observers that selected information has changed. | 139 // Notifies all observers that selected information has changed. |
| 135 void NotifyOnSelectedInformationChanged(); | 140 void NotifyOnSelectedInformationChanged(); |
| 136 | 141 |
| 137 // Returns whether the selected data satisfies the PaymentDetails requirements | 142 // Returns whether the selected data satisfies the PaymentDetails requirements |
| 138 // (payment methods). | 143 // (payment methods). |
| 139 bool ArePaymentDetailsSatisfied(); | 144 bool ArePaymentDetailsSatisfied(); |
| 140 // Returns whether the selected data satisfies the PaymentOptions requirements | 145 // Returns whether the selected data satisfies the PaymentOptions requirements |
| 141 // (contact info, shipping address). | 146 // (contact info, shipping address). |
| 142 bool ArePaymentOptionsSatisfied(); | 147 bool ArePaymentOptionsSatisfied(); |
| 143 | 148 |
| 144 // Updates the selected_shipping_option based on the data passed to this | |
| 145 // payment request by the website. This will set selected_shipping_option_ to | |
| 146 // the last option marked selected in the options array. | |
| 147 void UpdateSelectedShippingOption(); | |
| 148 | |
| 149 bool is_ready_to_pay_; | 149 bool is_ready_to_pay_; |
| 150 | 150 |
| 151 const std::string app_locale_; | 151 const std::string app_locale_; |
| 152 | 152 |
| 153 // Not owned. Never null. Both outlive this object. | 153 // Not owned. Never null. Both outlive this object. |
| 154 PaymentRequestSpec* spec_; | 154 PaymentRequestSpec* spec_; |
| 155 Delegate* delegate_; | 155 Delegate* delegate_; |
| 156 autofill::PersonalDataManager* personal_data_manager_; | 156 autofill::PersonalDataManager* personal_data_manager_; |
| 157 | 157 |
| 158 autofill::AutofillProfile* selected_shipping_profile_; | 158 autofill::AutofillProfile* selected_shipping_profile_; |
| 159 autofill::AutofillProfile* selected_contact_profile_; | 159 autofill::AutofillProfile* selected_contact_profile_; |
| 160 PaymentInstrument* selected_instrument_; | 160 PaymentInstrument* selected_instrument_; |
| 161 // The shipping options (and thus this pointer) are owned by |spec_| which | |
| 162 // outlives this object. | |
| 163 mojom::PaymentShippingOption* selected_shipping_option_; | |
| 164 | 161 |
| 165 // Profiles may change due to (e.g.) sync events, so profiles are cached after | 162 // Profiles may change due to (e.g.) sync events, so profiles are cached after |
| 166 // loading and owned here. They are populated once only, and ordered by | 163 // loading and owned here. They are populated once only, and ordered by |
| 167 // frecency. | 164 // frecency. |
| 168 std::vector<std::unique_ptr<autofill::AutofillProfile>> profile_cache_; | 165 std::vector<std::unique_ptr<autofill::AutofillProfile>> profile_cache_; |
| 169 std::vector<autofill::AutofillProfile*> shipping_profiles_; | 166 std::vector<autofill::AutofillProfile*> shipping_profiles_; |
| 170 std::vector<autofill::AutofillProfile*> contact_profiles_; | 167 std::vector<autofill::AutofillProfile*> contact_profiles_; |
| 171 // Credit cards are directly owned by the instruments in this list. | 168 // Credit cards are directly owned by the instruments in this list. |
| 172 std::vector<std::unique_ptr<PaymentInstrument>> available_instruments_; | 169 std::vector<std::unique_ptr<PaymentInstrument>> available_instruments_; |
| 173 | 170 |
| 174 base::ObserverList<Observer> observers_; | 171 base::ObserverList<Observer> observers_; |
| 175 | 172 |
| 176 DISALLOW_COPY_AND_ASSIGN(PaymentRequestState); | 173 DISALLOW_COPY_AND_ASSIGN(PaymentRequestState); |
| 177 }; | 174 }; |
| 178 | 175 |
| 179 } // namespace payments | 176 } // namespace payments |
| 180 | 177 |
| 181 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ | 178 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ |
| OLD | NEW |