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