Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: components/payments/content/payment_request_state.h

Issue 2757523002: [Payments] Use PaymentInstrument/AutofillPaymentInstrument throughout. (Closed)
Patch Set: Initial Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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<PaymentInstrument*>& available_instruments() {
98 return credit_cards_; 97 return available_instruments_;
99 } 98 }
100 99
101 // Setters to change the selected information. Will have the side effect of 100 // Setters to change the selected information. Will have the side effect of
102 // recomputing "is ready to pay" and notify observers. 101 // recomputing "is ready to pay" and notify observers.
103 void SetSelectedShippingProfile(autofill::AutofillProfile* profile); 102 void SetSelectedShippingProfile(autofill::AutofillProfile* profile);
104 void SetSelectedContactProfile(autofill::AutofillProfile* profile); 103 void SetSelectedContactProfile(autofill::AutofillProfile* profile);
105 void SetSelectedCreditCard(autofill::CreditCard* card); 104 void SetSelectedInstrument(PaymentInstrument* instrument);
106 105
107 bool is_ready_to_pay() { return is_ready_to_pay_; } 106 bool is_ready_to_pay() { return is_ready_to_pay_; }
108 107
109 const std::string& GetApplicationLocale(); 108 const std::string& GetApplicationLocale();
110 autofill::PersonalDataManager* GetPersonalDataManager(); 109 autofill::PersonalDataManager* GetPersonalDataManager();
111 110
112 private: 111 private:
113 // Fetches the Autofill Profiles for this user from the PersonalDataManager, 112 // Fetches the Autofill Profiles for this user from the PersonalDataManager,
114 // and stores copies of them, owned by this PaymentRequestState, in 113 // and stores copies of them, owned by this PaymentRequestState, in
115 // profile_cache_. 114 // profile_cache_.
116 void PopulateProfileCache(); 115 void PopulateProfileCache();
117 116
118 // Sets the initial selections for credit card and profiles, and notifies 117 // Sets the initial selections for instruments and profiles, and notifies
119 // observers. 118 // observers.
120 void SetDefaultProfileSelections(); 119 void SetDefaultProfileSelections();
121 120
122 // Uses the user-selected information as well as the merchant spec to update 121 // 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 122 // |is_ready_to_pay_| with the current state, by validating that all the
124 // required information is available. Will notify observers. 123 // required information is available. Will notify observers.
125 void UpdateIsReadyToPayAndNotifyObservers(); 124 void UpdateIsReadyToPayAndNotifyObservers();
126 125
127 // Notifies all observers that selected information has changed. 126 // Notifies all observers that selected information has changed.
128 void NotifyOnSelectedInformationChanged(); 127 void NotifyOnSelectedInformationChanged();
(...skipping 14 matching lines...) Expand all
143 142
144 const std::string app_locale_; 143 const std::string app_locale_;
145 144
146 // Not owned. Never null. Both outlive this object. 145 // Not owned. Never null. Both outlive this object.
147 PaymentRequestSpec* spec_; 146 PaymentRequestSpec* spec_;
148 Delegate* delegate_; 147 Delegate* delegate_;
149 autofill::PersonalDataManager* personal_data_manager_; 148 autofill::PersonalDataManager* personal_data_manager_;
150 149
151 autofill::AutofillProfile* selected_shipping_profile_; 150 autofill::AutofillProfile* selected_shipping_profile_;
152 autofill::AutofillProfile* selected_contact_profile_; 151 autofill::AutofillProfile* selected_contact_profile_;
153 autofill::CreditCard* selected_credit_card_; 152 PaymentInstrument* selected_instrument_;
154 // The shipping options (and thus this pointer) are owned by |spec_| which 153 // The shipping options (and thus this pointer) are owned by |spec_| which
155 // outlives this object. 154 // outlives this object.
156 mojom::PaymentShippingOption* selected_shipping_option_; 155 mojom::PaymentShippingOption* selected_shipping_option_;
157 156
158 std::unique_ptr<PaymentInstrument> selected_payment_instrument_;
159
160 // Profiles may change due to (e.g.) sync events, so profiles are cached after 157 // 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 158 // loading and owned here. They are populated once only, and ordered by
162 // frecency. 159 // frecency.
163 std::vector<std::unique_ptr<autofill::AutofillProfile>> profile_cache_; 160 std::vector<std::unique_ptr<autofill::AutofillProfile>> profile_cache_;
164 std::vector<autofill::AutofillProfile*> shipping_profiles_; 161 std::vector<autofill::AutofillProfile*> shipping_profiles_;
165 std::vector<autofill::AutofillProfile*> contact_profiles_; 162 std::vector<autofill::AutofillProfile*> contact_profiles_;
166 std::vector<std::unique_ptr<autofill::CreditCard>> card_cache_; 163 std::vector<std::unique_ptr<PaymentInstrument>> instrument_cache_;
167 std::vector<autofill::CreditCard*> credit_cards_; 164 std::vector<PaymentInstrument*> available_instruments_;
168 165
169 base::ObserverList<Observer> observers_; 166 base::ObserverList<Observer> observers_;
170 167
171 DISALLOW_COPY_AND_ASSIGN(PaymentRequestState); 168 DISALLOW_COPY_AND_ASSIGN(PaymentRequestState);
172 }; 169 };
173 170
174 } // namespace payments 171 } // namespace payments
175 172
176 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ 173 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698