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

Side by Side Diff: chrome/browser/autofill/wallet/wallet_client.h

Issue 12434004: Move remaining Autofill code to //components/autofill. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_AUTOFILL_WALLET_WALLET_CLIENT_H_
6 #define CHROME_BROWSER_AUTOFILL_WALLET_WALLET_CLIENT_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/values.h"
14 #include "chrome/browser/autofill/wallet/encryption_escrow_client.h"
15 #include "chrome/browser/autofill/wallet/encryption_escrow_client_observer.h"
16 #include "chrome/browser/autofill/wallet/full_wallet.h"
17 #include "components/autofill/common/autocheckout_status.h"
18 #include "net/url_request/url_fetcher_delegate.h"
19
20 class GURL;
21
22 namespace net {
23 class URLFetcher;
24 class URLRequestContextGetter;
25 }
26
27 namespace autofill {
28 namespace wallet {
29
30 class Address;
31 class Cart;
32 class FullWallet;
33 class Instrument;
34 class WalletClientObserver;
35 class WalletItems;
36
37 // WalletClient is responsible for making calls to the Online Wallet backend on
38 // the user's behalf. The normal flow for using this class is as follows:
39 // 1) GetWalletItems should be called to retrieve the user's Wallet.
40 // a) If the user does not have a Wallet, they must AcceptLegalDocuments and
41 // SaveInstrumentAndAddress before continuing.
42 // b) If the user has not acccepte the most recent legal documents for
43 // Wallet, they must AcceptLegalDocuments.
44 // 2) The user then chooses what instrument and shipping address to use for the
45 // current transaction.
46 // a) If they choose an instrument with a zip code only address, the billing
47 // address will need to be updated using UpdateInstrument.
48 // b) The user may also choose to add a new instrument or address using
49 // SaveAddress, SaveInstrument, or SaveInstrumentAndAddress.
50 // 3) Once the user has selected the backing instrument and shipping address
51 // for this transaction, a FullWallet with the fronting card is generated
52 // using GetFullWallet.
53 // a) GetFullWallet may return a Risk challenge for the user. In that case,
54 // the user will need to verify who they are by authenticating their
55 // chosen backing instrument through AuthenticateInstrument
56 // 4) If the user initiated Autocheckout, SendAutocheckoutStatus to notify
57 // Online Wallet of the status flow to record various metrics.
58 //
59 // WalletClient is designed so only one request to Online Wallet can be
60 // outgoing at any one time. Implementors of WalletClientObserver should wait
61 // for a callback to be called for an outgoing request before making another.
62 class WalletClient
63 : public net::URLFetcherDelegate,
64 public EncryptionEscrowClientObserver {
65 public:
66 // |context_getter| is reference counted so it has no lifetime or ownership
67 // requirements.
68 explicit WalletClient(net::URLRequestContextGetter* context_getter);
69
70 virtual ~WalletClient();
71
72 // GetWalletItems retrieves the user's online wallet. The WalletItems
73 // returned may require additional action such as presenting legal documents
74 // to the user to be accepted.
75 void GetWalletItems(const GURL& source_url,
76 base::WeakPtr<WalletClientObserver> observer);
77
78 // The GetWalletItems call to the Online Wallet backend may require the user
79 // to accept various legal documents before a FullWallet can be generated.
80 // The |document_ids| and |google_transaction_id| are provided in the response
81 // to the GetWalletItems call.
82 void AcceptLegalDocuments(const std::vector<std::string>& document_ids,
83 const std::string& google_transaction_id,
84 const GURL& source_url,
85 base::WeakPtr<WalletClientObserver> observer);
86
87 // Authenticates that |card_verification_number| is for the backing instrument
88 // with |instrument_id|. |obfuscated_gaia_id| is used as a key when escrowing
89 // |card_verification_number|. |observer| is notified when the request is
90 // complete. Used to respond to Risk challenges.
91 void AuthenticateInstrument(const std::string& instrument_id,
92 const std::string& card_verification_number,
93 const std::string& obfuscated_gaia_id,
94 base::WeakPtr<WalletClientObserver> observer);
95
96 // GetFullWallet retrieves the a FullWallet for the user. |instrument_id| and
97 // |adddress_id| should have been selected by the user in some UI,
98 // |merchant_domain| should come from the BrowserContext, the |cart|
99 // information will have been provided by the browser, and
100 // |google_transaction_id| is the same one that GetWalletItems returns.
101 void GetFullWallet(const std::string& instrument_id,
102 const std::string& address_id,
103 const GURL& source_url,
104 const Cart& cart,
105 const std::string& google_transaction_id,
106 base::WeakPtr<WalletClientObserver> observer);
107
108 // SaveAddress saves a new shipping address.
109 void SaveAddress(const Address& address,
110 const GURL& source_url,
111 base::WeakPtr<WalletClientObserver> observer);
112
113 // SaveInstrument saves a new instrument.
114 void SaveInstrument(const Instrument& instrument,
115 const std::string& obfuscated_gaia_id,
116 const GURL& source_url,
117 base::WeakPtr<WalletClientObserver> observer);
118
119 // SaveInstrumentAndAddress saves a new instrument and address.
120 void SaveInstrumentAndAddress(const Instrument& instrument,
121 const Address& shipping_address,
122 const std::string& obfuscated_gaia_id,
123 const GURL& source_url,
124 base::WeakPtr<WalletClientObserver> observer);
125
126 // SendAutocheckoutStatus is used for tracking the success of Autocheckout
127 // flows. |status| is the result of the flow, |merchant_domain| is the domain
128 // where the purchase occured, and |google_transaction_id| is the same as the
129 // one provided by GetWalletItems.
130 void SendAutocheckoutStatus(autofill::AutocheckoutStatus status,
131 const GURL& source_url,
132 const std::string& google_transaction_id,
133 base::WeakPtr<WalletClientObserver> observer);
134
135 // UpdateInstrument changes the instrument with id |instrument_id| with the
136 // information in |billing_address|. Its primary use is for upgrading ZIP code
137 // only addresses or those missing phone numbers. DO NOT change the name on
138 // |billing_address| from the one returned by Online Wallet or this call will
139 // fail.
140 void UpdateInstrument(const std::string& instrument_id,
141 const Address& billing_address,
142 const GURL& source_url,
143 base::WeakPtr<WalletClientObserver> observer);
144
145 // Whether there is a currently running request (i.e. |request_| != NULL).
146 bool HasRequestInProgress() const;
147
148 private:
149 // TODO(ahutter): Implement this.
150 std::string GetRiskParams() { return ""; }
151
152 enum RequestType {
153 NO_PENDING_REQUEST,
154 ACCEPT_LEGAL_DOCUMENTS,
155 AUTHENTICATE_INSTRUMENT,
156 GET_FULL_WALLET,
157 GET_WALLET_ITEMS,
158 SAVE_ADDRESS,
159 SAVE_INSTRUMENT,
160 SAVE_INSTRUMENT_AND_ADDRESS,
161 SEND_STATUS,
162 UPDATE_INSTRUMENT,
163 };
164
165 // Posts |post_body| to |url| and notifies |observer| when the request is
166 // complete.
167 void MakeWalletRequest(const GURL& url,
168 const std::string& post_body,
169 base::WeakPtr<WalletClientObserver> observer);
170
171 // Performs bookkeeping tasks for any invalid requests.
172 void HandleMalformedResponse(net::URLFetcher* request);
173
174 // net::URLFetcherDelegate:
175 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
176
177 // EncryptionEscrowClientObserver:
178 virtual void OnDidEncryptOneTimePad(
179 const std::string& encrypted_one_time_pad,
180 const std::string& session_material) OVERRIDE;
181 virtual void OnDidEscrowInstrumentInformation(
182 const std::string& escrow_handle) OVERRIDE;
183 virtual void OnDidEscrowCardVerificationNumber(
184 const std::string& escrow_handle) OVERRIDE;
185 virtual void OnNetworkError(int response_code) OVERRIDE;
186 virtual void OnMalformedResponse() OVERRIDE;
187
188 // The context for the request. Ensures the gdToken cookie is set as a header
189 // in the requests to Online Wallet if it is present.
190 scoped_refptr<net::URLRequestContextGetter> context_getter_;
191
192 // Observer class that has its various On* methods called based on the results
193 // of a request to Online Wallet.
194 base::WeakPtr<WalletClientObserver> observer_;
195
196 // The current request object.
197 scoped_ptr<net::URLFetcher> request_;
198
199 // The type of the current request. Must be NO_PENDING_REQUEST for a request
200 // to be initiated as only one request may be running at a given time.
201 RequestType request_type_;
202
203 // The one time pad used for GetFullWallet encryption.
204 std::vector<uint8> one_time_pad_;
205
206 // GetFullWallet requests and requests that alter instruments rely on requests
207 // made through the |encryption_escrow_client_| finishing first. The request
208 // body is saved here while that those requests are in flight.
209 base::DictionaryValue pending_request_body_;
210
211 // This client is repsonsible for making encryption and escrow calls to Online
212 // Wallet.
213 EncryptionEscrowClient encryption_escrow_client_;
214
215 base::WeakPtrFactory<WalletClient> weak_ptr_factory_;
216
217 DISALLOW_COPY_AND_ASSIGN(WalletClient);
218 };
219
220 } // namespace wallet
221 } // namespace autofill
222
223 #endif // CHROME_BROWSER_AUTOFILL_WALLET_WALLET_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698