| 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 "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
| 10 #include "components/payments/content/payment_request.mojom.h" | 10 #include "components/payments/content/payment_request.mojom.h" |
| 11 #include "components/payments/core/payment_instrument.h" | 11 #include "components/payments/core/payment_instrument.h" |
| 12 | 12 |
| 13 namespace autofill { | 13 namespace autofill { |
| 14 class AutofillProfile; | 14 class AutofillProfile; |
| 15 class CreditCard; | |
| 16 class PersonalDataManager; | 15 class PersonalDataManager; |
| 17 } // namespace autofill | 16 } // namespace autofill |
| 18 | 17 |
| 19 namespace payments { | 18 namespace payments { |
| 20 | 19 |
| 21 class PaymentRequestSpec; | 20 class PaymentRequestSpec; |
| 22 | 21 |
| 23 // Keeps track of the information currently selected by the user and whether the | 22 // Keeps track of the information currently selected by the user and whether the |
| 24 // user is ready to pay. Uses information from the PaymentRequestSpec, which is | 23 // user is ready to pay. Uses information from the PaymentRequestSpec, which is |
| 25 // what the merchant has specified, as input into the "is ready to pay" | 24 // what the merchant has specified, as input into the "is ready to pay" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 68 |
| 70 // Gets the Autofill Profile representing the shipping address or contact | 69 // Gets the Autofill Profile representing the shipping address or contact |
| 71 // information currently selected for this PaymentRequest flow. Can return | 70 // information currently selected for this PaymentRequest flow. Can return |
| 72 // null. | 71 // null. |
| 73 autofill::AutofillProfile* selected_shipping_profile() const { | 72 autofill::AutofillProfile* selected_shipping_profile() const { |
| 74 return selected_shipping_profile_; | 73 return selected_shipping_profile_; |
| 75 } | 74 } |
| 76 autofill::AutofillProfile* selected_contact_profile() const { | 75 autofill::AutofillProfile* selected_contact_profile() const { |
| 77 return selected_contact_profile_; | 76 return selected_contact_profile_; |
| 78 } | 77 } |
| 79 // Returns the currently selected credit card for this PaymentRequest flow. | 78 // Returns the currently selected instrument for this PaymentRequest flow. |
| 80 // It's not guaranteed to be complete. Returns nullptr if there is no selected | 79 // It's not guaranteed to be complete. Returns nullptr if there is no selected |
| 81 // card. | 80 // instrument. |
| 82 autofill::CreditCard* selected_credit_card() const { | 81 PaymentInstrument* selected_instrument() const { |
| 83 return selected_credit_card_; | 82 return selected_instrument_; |
| 84 } | 83 } |
| 85 mojom::PaymentShippingOption* selected_shipping_option() { | 84 mojom::PaymentShippingOption* selected_shipping_option() { |
| 86 return selected_shipping_option_; | 85 return selected_shipping_option_; |
| 87 } | 86 } |
| 88 | 87 |
| 89 // Returns the appropriate Autofill Profiles for this user. The profiles | 88 // Returns the appropriate Autofill Profiles for this user. The profiles |
| 90 // returned are owned by the PaymentRequestState. | 89 // returned are owned by the PaymentRequestState. |
| 91 const std::vector<autofill::AutofillProfile*>& shipping_profiles() { | 90 const std::vector<autofill::AutofillProfile*>& shipping_profiles() { |
| 92 return shipping_profiles_; | 91 return shipping_profiles_; |
| 93 } | 92 } |
| 94 const std::vector<autofill::AutofillProfile*>& contact_profiles() { | 93 const std::vector<autofill::AutofillProfile*>& contact_profiles() { |
| 95 return contact_profiles_; | 94 return contact_profiles_; |
| 96 } | 95 } |
| 97 const std::vector<autofill::CreditCard*>& credit_cards() { | 96 const std::vector<std::unique_ptr<PaymentInstrument>>& |
| 98 return credit_cards_; | 97 available_instruments() { |
| 98 return available_instruments_; |
| 99 } | 99 } |
| 100 | 100 |
| 101 // Setters to change the selected information. Will have the side effect of | 101 // Setters to change the selected information. Will have the side effect of |
| 102 // recomputing "is ready to pay" and notify observers. | 102 // recomputing "is ready to pay" and notify observers. |
| 103 void SetSelectedShippingProfile(autofill::AutofillProfile* profile); | 103 void SetSelectedShippingProfile(autofill::AutofillProfile* profile); |
| 104 void SetSelectedContactProfile(autofill::AutofillProfile* profile); | 104 void SetSelectedContactProfile(autofill::AutofillProfile* profile); |
| 105 void SetSelectedCreditCard(autofill::CreditCard* card); | 105 void SetSelectedInstrument(PaymentInstrument* instrument); |
| 106 | 106 |
| 107 bool is_ready_to_pay() { return is_ready_to_pay_; } | 107 bool is_ready_to_pay() { return is_ready_to_pay_; } |
| 108 | 108 |
| 109 const std::string& GetApplicationLocale(); | 109 const std::string& GetApplicationLocale(); |
| 110 autofill::PersonalDataManager* GetPersonalDataManager(); | 110 autofill::PersonalDataManager* GetPersonalDataManager(); |
| 111 | 111 |
| 112 private: | 112 private: |
| 113 // Fetches the Autofill Profiles for this user from the PersonalDataManager, | 113 // Fetches the Autofill Profiles for this user from the PersonalDataManager, |
| 114 // and stores copies of them, owned by this PaymentRequestState, in | 114 // and stores copies of them, owned by this PaymentRequestState, in |
| 115 // profile_cache_. | 115 // profile_cache_. |
| 116 void PopulateProfileCache(); | 116 void PopulateProfileCache(); |
| 117 | 117 |
| 118 // Sets the initial selections for credit card and profiles, and notifies | 118 // Sets the initial selections for instruments and profiles, and notifies |
| 119 // observers. | 119 // observers. |
| 120 void SetDefaultProfileSelections(); | 120 void SetDefaultProfileSelections(); |
| 121 | 121 |
| 122 // Uses the user-selected information as well as the merchant spec to update | 122 // Uses the user-selected information as well as the merchant spec to update |
| 123 // |is_ready_to_pay_| with the current state, by validating that all the | 123 // |is_ready_to_pay_| with the current state, by validating that all the |
| 124 // required information is available. Will notify observers. | 124 // required information is available. Will notify observers. |
| 125 void UpdateIsReadyToPayAndNotifyObservers(); | 125 void UpdateIsReadyToPayAndNotifyObservers(); |
| 126 | 126 |
| 127 // Notifies all observers that selected information has changed. | 127 // Notifies all observers that selected information has changed. |
| 128 void NotifyOnSelectedInformationChanged(); | 128 void NotifyOnSelectedInformationChanged(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 143 | 143 |
| 144 const std::string app_locale_; | 144 const std::string app_locale_; |
| 145 | 145 |
| 146 // Not owned. Never null. Both outlive this object. | 146 // Not owned. Never null. Both outlive this object. |
| 147 PaymentRequestSpec* spec_; | 147 PaymentRequestSpec* spec_; |
| 148 Delegate* delegate_; | 148 Delegate* delegate_; |
| 149 autofill::PersonalDataManager* personal_data_manager_; | 149 autofill::PersonalDataManager* personal_data_manager_; |
| 150 | 150 |
| 151 autofill::AutofillProfile* selected_shipping_profile_; | 151 autofill::AutofillProfile* selected_shipping_profile_; |
| 152 autofill::AutofillProfile* selected_contact_profile_; | 152 autofill::AutofillProfile* selected_contact_profile_; |
| 153 autofill::CreditCard* selected_credit_card_; | 153 PaymentInstrument* selected_instrument_; |
| 154 // The shipping options (and thus this pointer) are owned by |spec_| which | 154 // The shipping options (and thus this pointer) are owned by |spec_| which |
| 155 // outlives this object. | 155 // outlives this object. |
| 156 mojom::PaymentShippingOption* selected_shipping_option_; | 156 mojom::PaymentShippingOption* selected_shipping_option_; |
| 157 | 157 |
| 158 std::unique_ptr<PaymentInstrument> selected_payment_instrument_; | |
| 159 | |
| 160 // Profiles may change due to (e.g.) sync events, so profiles are cached after | 158 // Profiles may change due to (e.g.) sync events, so profiles are cached after |
| 161 // loading and owned here. They are populated once only, and ordered by | 159 // loading and owned here. They are populated once only, and ordered by |
| 162 // frecency. | 160 // frecency. |
| 163 std::vector<std::unique_ptr<autofill::AutofillProfile>> profile_cache_; | 161 std::vector<std::unique_ptr<autofill::AutofillProfile>> profile_cache_; |
| 164 std::vector<autofill::AutofillProfile*> shipping_profiles_; | 162 std::vector<autofill::AutofillProfile*> shipping_profiles_; |
| 165 std::vector<autofill::AutofillProfile*> contact_profiles_; | 163 std::vector<autofill::AutofillProfile*> contact_profiles_; |
| 166 std::vector<std::unique_ptr<autofill::CreditCard>> card_cache_; | 164 // Credit cards are directly owned by the instruments in this list. |
| 167 std::vector<autofill::CreditCard*> credit_cards_; | 165 std::vector<std::unique_ptr<PaymentInstrument>> available_instruments_; |
| 168 | 166 |
| 169 base::ObserverList<Observer> observers_; | 167 base::ObserverList<Observer> observers_; |
| 170 | 168 |
| 171 DISALLOW_COPY_AND_ASSIGN(PaymentRequestState); | 169 DISALLOW_COPY_AND_ASSIGN(PaymentRequestState); |
| 172 }; | 170 }; |
| 173 | 171 |
| 174 } // namespace payments | 172 } // namespace payments |
| 175 | 173 |
| 176 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ | 174 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ |
| OLD | NEW |