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

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

Issue 2741343011: [Payments] Move PersonalDataManager and locale to PaymentRequestState (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/autofill/core/browser/personal_data_manager.h"
11 #include "components/payments/content/payment_request.mojom.h" 10 #include "components/payments/content/payment_request.mojom.h"
12 #include "components/payments/core/payment_instrument.h" 11 #include "components/payments/core/payment_instrument.h"
13 12
14 namespace autofill { 13 namespace autofill {
15 class AutofillProfile; 14 class AutofillProfile;
16 class CreditCard; 15 class CreditCard;
16 class PersonalDataManager;
17 } // namespace autofill 17 } // namespace autofill
18 18
19 namespace payments { 19 namespace payments {
20 20
21 class PaymentRequestSpec; 21 class PaymentRequestSpec;
22 22
23 // Keeps track of the information currently selected by the user and whether the 23 // 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 24 // 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" 25 // what the merchant has specified, as input into the "is ready to pay"
26 // computation. 26 // computation.
27 class PaymentRequestState : public PaymentInstrument::Delegate { 27 class PaymentRequestState : public PaymentInstrument::Delegate {
28 public: 28 public:
29 // Any class call add itself as Observer via AddObserver() and receive 29 // Any class call add itself as Observer via AddObserver() and receive
30 // notification about the state changing. 30 // notification about the state changing.
31 class Observer { 31 class Observer {
32 public: 32 public:
33 // Called when the information (payment method, address/contact info, 33 // Called when the information (payment method, address/contact info,
34 // shipping option) changes. 34 // shipping option) changes.
35 virtual void OnSelectedInformationChanged() = 0; 35 virtual void OnSelectedInformationChanged() = 0;
36 36
37 protected: 37 protected:
38 virtual ~Observer() {} 38 virtual ~Observer() {}
39 }; 39 };
40 40
41 class Delegate { 41 class Delegate {
42 public: 42 public:
43 virtual const std::string& GetApplicationLocale() = 0;
44 // Used to get the user's data.
45 virtual autofill::PersonalDataManager* GetPersonalDataManager() = 0;
46 // Called when the PaymentResponse is available. 43 // Called when the PaymentResponse is available.
47 virtual void OnPaymentResponseAvailable( 44 virtual void OnPaymentResponseAvailable(
48 mojom::PaymentResponsePtr response) = 0; 45 mojom::PaymentResponsePtr response) = 0;
49 46
50 protected: 47 protected:
51 virtual ~Delegate() {} 48 virtual ~Delegate() {}
52 }; 49 };
53 50
54 PaymentRequestState(PaymentRequestSpec* spec, Delegate* delegate); 51 PaymentRequestState(PaymentRequestSpec* spec,
52 Delegate* delegate,
53 const std::string& app_locale,
54 autofill::PersonalDataManager* personal_data_manager);
55 ~PaymentRequestState() override; 55 ~PaymentRequestState() override;
56 56
57 void AddObserver(Observer* observer); 57 void AddObserver(Observer* observer);
58 void RemoveObserver(Observer* observer); 58 void RemoveObserver(Observer* observer);
59 59
60 // PaymentInstrument::Delegate: 60 // PaymentInstrument::Delegate:
61 void OnInstrumentDetailsReady( 61 void OnInstrumentDetailsReady(
62 const std::string& method_name, 62 const std::string& method_name,
63 const std::string& stringified_details) override; 63 const std::string& stringified_details) override;
64 void OnInstrumentDetailsError() override {} 64 void OnInstrumentDetailsError() override {}
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 SetSelectedCreditCard(autofill::CreditCard* card);
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();
110 autofill::PersonalDataManager* GetPersonalDataManager();
111
109 private: 112 private:
110 // Fetches the Autofill Profiles for this user from the PersonalDataManager, 113 // Fetches the Autofill Profiles for this user from the PersonalDataManager,
111 // and stores copies of them, owned by this PaymentRequestState, in 114 // and stores copies of them, owned by this PaymentRequestState, in
112 // profile_cache_. 115 // profile_cache_.
113 void PopulateProfileCache(); 116 void PopulateProfileCache();
114 117
115 // Sets the initial selections for credit card and profiles, and notifies 118 // Sets the initial selections for credit card and profiles, and notifies
116 // observers. 119 // observers.
117 void SetDefaultProfileSelections(); 120 void SetDefaultProfileSelections();
118 121
(...skipping 12 matching lines...) Expand all
131 // (contact info, shipping address). 134 // (contact info, shipping address).
132 bool ArePaymentOptionsSatisfied(); 135 bool ArePaymentOptionsSatisfied();
133 136
134 // Updates the selected_shipping_option based on the data passed to this 137 // Updates the selected_shipping_option based on the data passed to this
135 // payment request by the website. This will set selected_shipping_option_ to 138 // payment request by the website. This will set selected_shipping_option_ to
136 // the last option marked selected in the options array. 139 // the last option marked selected in the options array.
137 void UpdateSelectedShippingOption(); 140 void UpdateSelectedShippingOption();
138 141
139 bool is_ready_to_pay_; 142 bool is_ready_to_pay_;
140 143
144 const std::string app_locale_;
145
141 // Not owned. Never null. Both outlive this object. 146 // Not owned. Never null. Both outlive this object.
142 PaymentRequestSpec* spec_; 147 PaymentRequestSpec* spec_;
143 Delegate* delegate_; 148 Delegate* delegate_;
149 autofill::PersonalDataManager* personal_data_manager_;
144 150
145 autofill::AutofillProfile* selected_shipping_profile_; 151 autofill::AutofillProfile* selected_shipping_profile_;
146 autofill::AutofillProfile* selected_contact_profile_; 152 autofill::AutofillProfile* selected_contact_profile_;
147 autofill::CreditCard* selected_credit_card_; 153 autofill::CreditCard* selected_credit_card_;
148 // 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
149 // outlives this object. 155 // outlives this object.
150 mojom::PaymentShippingOption* selected_shipping_option_; 156 mojom::PaymentShippingOption* selected_shipping_option_;
151 157
152 std::unique_ptr<PaymentInstrument> selected_payment_instrument_; 158 std::unique_ptr<PaymentInstrument> selected_payment_instrument_;
153 159
154 // Profiles may change due to (e.g.) sync events, so profiles are cached after 160 // Profiles may change due to (e.g.) sync events, so profiles are cached after
155 // loading and owned here. They are populated once only, and ordered by 161 // loading and owned here. They are populated once only, and ordered by
156 // frecency. 162 // frecency.
157 std::vector<std::unique_ptr<autofill::AutofillProfile>> profile_cache_; 163 std::vector<std::unique_ptr<autofill::AutofillProfile>> profile_cache_;
158 std::vector<autofill::AutofillProfile*> shipping_profiles_; 164 std::vector<autofill::AutofillProfile*> shipping_profiles_;
159 std::vector<autofill::AutofillProfile*> contact_profiles_; 165 std::vector<autofill::AutofillProfile*> contact_profiles_;
160 std::vector<std::unique_ptr<autofill::CreditCard>> card_cache_; 166 std::vector<std::unique_ptr<autofill::CreditCard>> card_cache_;
161 std::vector<autofill::CreditCard*> credit_cards_; 167 std::vector<autofill::CreditCard*> credit_cards_;
162 168
163 base::ObserverList<Observer> observers_; 169 base::ObserverList<Observer> observers_;
164 170
165 DISALLOW_COPY_AND_ASSIGN(PaymentRequestState); 171 DISALLOW_COPY_AND_ASSIGN(PaymentRequestState);
166 }; 172 };
167 173
168 } // namespace payments 174 } // namespace payments
169 175
170 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_ 176 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_STATE_H_
OLDNEW
« no previous file with comments | « components/payments/content/payment_request_spec_unittest.cc ('k') | components/payments/content/payment_request_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698