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

Side by Side Diff: components/autofill/content/browser/wallet/wallet_client.h

Issue 17970003: New encryption/escrow endpoints for Wallet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Dane's review Created 7 years, 5 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_AUTOFILL_CONTENT_BROWSER_WALLET_WALLET_CLIENT_H_ 5 #ifndef COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_WALLET_CLIENT_H_
6 #define COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_WALLET_CLIENT_H_ 6 #define COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_WALLET_CLIENT_H_
7 7
8 #include <queue> 8 #include <queue>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/callback.h" // For base::Closure. 12 #include "base/callback.h" // For base::Closure.
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "components/autofill/content/browser/autocheckout_statistic.h" 16 #include "components/autofill/content/browser/autocheckout_statistic.h"
17 #include "components/autofill/content/browser/wallet/encryption_escrow_client.h"
18 #include "components/autofill/content/browser/wallet/encryption_escrow_client_ob server.h"
19 #include "components/autofill/content/browser/wallet/full_wallet.h" 17 #include "components/autofill/content/browser/wallet/full_wallet.h"
20 #include "components/autofill/content/browser/wallet/wallet_items.h" 18 #include "components/autofill/content/browser/wallet/wallet_items.h"
21 #include "components/autofill/core/browser/autofill_manager_delegate.h" 19 #include "components/autofill/core/browser/autofill_manager_delegate.h"
22 #include "components/autofill/core/browser/autofill_metrics.h" 20 #include "components/autofill/core/browser/autofill_metrics.h"
23 #include "components/autofill/core/common/autocheckout_status.h" 21 #include "components/autofill/core/common/autocheckout_status.h"
24 #include "googleurl/src/gurl.h" 22 #include "googleurl/src/gurl.h"
25 #include "net/url_request/url_fetcher_delegate.h" 23 #include "net/url_request/url_fetcher_delegate.h"
26 #include "testing/gtest/include/gtest/gtest_prod.h" 24 #include "testing/gtest/include/gtest/gtest_prod.h"
27 25
28 namespace net { 26 namespace net {
(...skipping 29 matching lines...) Expand all
58 // the user will need to verify who they are by authenticating their 56 // the user will need to verify who they are by authenticating their
59 // chosen backing instrument through AuthenticateInstrument 57 // chosen backing instrument through AuthenticateInstrument
60 // 4) If the user initiated Autocheckout, SendAutocheckoutStatus to notify 58 // 4) If the user initiated Autocheckout, SendAutocheckoutStatus to notify
61 // Online Wallet of the status flow to record various metrics. 59 // Online Wallet of the status flow to record various metrics.
62 // 60 //
63 // WalletClient is designed so only one request to Online Wallet can be outgoing 61 // WalletClient is designed so only one request to Online Wallet can be outgoing
64 // at any one time. If |HasRequestInProgress()| is true while calling e.g. 62 // at any one time. If |HasRequestInProgress()| is true while calling e.g.
65 // GetWalletItems(), the request will be queued and started later. Queued 63 // GetWalletItems(), the request will be queued and started later. Queued
66 // requests start in the order they were received. 64 // requests start in the order they were received.
67 65
68 class WalletClient 66 class WalletClient : public net::URLFetcherDelegate {
69 : public net::URLFetcherDelegate,
70 public EncryptionEscrowClientObserver {
71 public: 67 public:
72 // The Risk challenges supported by users of WalletClient. 68 // The Risk challenges supported by users of WalletClient.
73 enum RiskCapability { 69 enum RiskCapability {
74 RELOGIN, 70 RELOGIN,
75 VERIFY_CVC, 71 VERIFY_CVC,
76 }; 72 };
77 73
78 // The type of error returned by Online Wallet. 74 // The type of error returned by Online Wallet.
79 enum ErrorType { 75 enum ErrorType {
80 // Errors to display to users. 76 // Errors to display to users.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 // The transaction ID from GetWalletItems. 119 // The transaction ID from GetWalletItems.
124 std::string google_transaction_id; 120 std::string google_transaction_id;
125 121
126 // The Risk challenges supported by the user of WalletClient 122 // The Risk challenges supported by the user of WalletClient
127 std::vector<RiskCapability> risk_capabilities; 123 std::vector<RiskCapability> risk_capabilities;
128 124
129 private: 125 private:
130 DISALLOW_ASSIGN(FullWalletRequest); 126 DISALLOW_ASSIGN(FullWalletRequest);
131 }; 127 };
132 128
133 struct UpdateInstrumentRequest {
134 public:
135 UpdateInstrumentRequest(const std::string& instrument_id,
136 const GURL& source_url);
137 ~UpdateInstrumentRequest();
138
139 // The id of the instrument being modified.
140 std::string instrument_id;
141
142 // The new expiration date. If these are set, |card_verification_number| and
143 // |obfuscated_gaia_id| must be provided.
144 int expiration_month;
145 int expiration_year;
146
147 // Used to authenticate the card the user is modifying.
148 std::string card_verification_number;
149
150 // Used to key the escrow of |card_verification_number|.
151 std::string obfuscated_gaia_id;
152
153 // The url this call is initiated from.
154 GURL source_url;
155
156 private:
157 DISALLOW_ASSIGN(UpdateInstrumentRequest);
158 };
159
160 // |context_getter| is reference counted so it has no lifetime or ownership 129 // |context_getter| is reference counted so it has no lifetime or ownership
161 // requirements. |delegate| must outlive |this|. 130 // requirements. |delegate| must outlive |this|.
162 WalletClient(net::URLRequestContextGetter* context_getter, 131 WalletClient(net::URLRequestContextGetter* context_getter,
163 WalletClientDelegate* delegate); 132 WalletClientDelegate* delegate);
164 133
165 virtual ~WalletClient(); 134 virtual ~WalletClient();
166 135
167 // GetWalletItems retrieves the user's online wallet. The WalletItems 136 // GetWalletItems retrieves the user's online wallet. The WalletItems
168 // returned may require additional action such as presenting legal documents 137 // returned may require additional action such as presenting legal documents
169 // to the user to be accepted. 138 // to the user to be accepted.
170 virtual void GetWalletItems(const GURL& source_url); 139 virtual void GetWalletItems(const GURL& source_url);
171 140
172 // The GetWalletItems call to the Online Wallet backend may require the user 141 // The GetWalletItems call to the Online Wallet backend may require the user
173 // to accept various legal documents before a FullWallet can be generated. 142 // to accept various legal documents before a FullWallet can be generated.
174 // The |google_transaction_id| is provided in the response to the 143 // The |google_transaction_id| is provided in the response to the
175 // GetWalletItems call. If |documents| are empty, |delegate_| will not receive 144 // GetWalletItems call. If |documents| are empty, |delegate_| will not receive
176 // a corresponding |OnDidAcceptLegalDocuments()| call. 145 // a corresponding |OnDidAcceptLegalDocuments()| call.
177 virtual void AcceptLegalDocuments( 146 virtual void AcceptLegalDocuments(
178 const std::vector<WalletItems::LegalDocument*>& documents, 147 const std::vector<WalletItems::LegalDocument*>& documents,
179 const std::string& google_transaction_id, 148 const std::string& google_transaction_id,
180 const GURL& source_url); 149 const GURL& source_url);
181 150
182 // Authenticates that |card_verification_number| is for the backing instrument 151 // Authenticates that |card_verification_number| is for the backing instrument
183 // with |instrument_id|. |obfuscated_gaia_id| is used as a key when escrowing 152 // with |instrument_id|. |obfuscated_gaia_id| is used as a key when escrowing
184 // |card_verification_number|. |delegate_| is notified when the request is 153 // |card_verification_number|. |delegate_| is notified when the request is
185 // complete. Used to respond to Risk challenges. 154 // complete. Used to respond to Risk challenges.
186 virtual void AuthenticateInstrument( 155 virtual void AuthenticateInstrument(
187 const std::string& instrument_id, 156 const std::string& instrument_id,
188 const std::string& card_verification_number, 157 const std::string& card_verification_number);
189 const std::string& obfuscated_gaia_id);
190 158
191 // GetFullWallet retrieves the a FullWallet for the user. 159 // GetFullWallet retrieves the a FullWallet for the user.
192 virtual void GetFullWallet(const FullWalletRequest& full_wallet_request); 160 virtual void GetFullWallet(const FullWalletRequest& full_wallet_request);
193 161
194 // SaveAddress saves a new shipping address. 162 // Saves the data in |instrument| and/or |address| to Wallet.
Raman Kakilate 2013/07/02 01:41:24 Also commenting on instrument state will be useful
ahutter 2013/07/02 15:44:23 Done.
195 virtual void SaveAddress(const Address& address, const GURL& source_url); 163 virtual void SaveToWallet(scoped_ptr<Instrument> instrument,
196 164 scoped_ptr<Address> address,
197 // SaveInstrument saves a new instrument. 165 const GURL& source_url);
198 virtual void SaveInstrument(const Instrument& instrument,
199 const std::string& obfuscated_gaia_id,
200 const GURL& source_url);
201
202 // SaveInstrumentAndAddress saves a new instrument and address.
203 virtual void SaveInstrumentAndAddress(const Instrument& instrument,
204 const Address& shipping_address,
205 const std::string& obfuscated_gaia_id,
206 const GURL& source_url);
207 166
208 // SendAutocheckoutStatus is used for tracking the success of Autocheckout 167 // SendAutocheckoutStatus is used for tracking the success of Autocheckout
209 // flows. |status| is the result of the flow, |source_url| is the domain 168 // flows. |status| is the result of the flow, |source_url| is the domain
210 // where the purchase occured, and |google_transaction_id| is the same as the 169 // where the purchase occured, and |google_transaction_id| is the same as the
211 // one provided by GetWalletItems. |latency_statistics| contain statistics 170 // one provided by GetWalletItems. |latency_statistics| contain statistics
212 // required to measure Autocheckout process. 171 // required to measure Autocheckout process.
213 void SendAutocheckoutStatus( 172 void SendAutocheckoutStatus(
214 autofill::AutocheckoutStatus status, 173 autofill::AutocheckoutStatus status,
215 const GURL& source_url, 174 const GURL& source_url,
216 const std::vector<AutocheckoutStatistic>& latency_statistics, 175 const std::vector<AutocheckoutStatistic>& latency_statistics,
217 const std::string& google_transaction_id); 176 const std::string& google_transaction_id);
218 177
219 // UpdateAddress updates Online Wallet with the data in |address|.
220 virtual void UpdateAddress(const Address& address, const GURL& source_url);
221
222 // Updates Online Wallet with the data in |update_instrument_request| and, if
223 // it's provided, |billing_address|.
224 virtual void UpdateInstrument(
225 const UpdateInstrumentRequest& update_instrument_request,
226 scoped_ptr<Address> billing_address);
227
228 bool HasRequestInProgress() const; 178 bool HasRequestInProgress() const;
229 179
230 // Cancels and clears the current |request_| and |pending_requests_| (if any). 180 // Cancels and clears the current |request_| and |pending_requests_| (if any).
231 void CancelRequests(); 181 void CancelRequests();
232 182
233 private: 183 private:
234 FRIEND_TEST_ALL_PREFIXES(WalletClientTest, PendingRequest); 184 FRIEND_TEST_ALL_PREFIXES(WalletClientTest, PendingRequest);
235 FRIEND_TEST_ALL_PREFIXES(WalletClientTest, CancelRequests); 185 FRIEND_TEST_ALL_PREFIXES(WalletClientTest, CancelRequests);
236 186
237 enum RequestType { 187 enum RequestType {
238 NO_PENDING_REQUEST, 188 NO_PENDING_REQUEST,
239 ACCEPT_LEGAL_DOCUMENTS, 189 ACCEPT_LEGAL_DOCUMENTS,
240 AUTHENTICATE_INSTRUMENT, 190 AUTHENTICATE_INSTRUMENT,
241 GET_FULL_WALLET, 191 GET_FULL_WALLET,
242 GET_WALLET_ITEMS, 192 GET_WALLET_ITEMS,
243 SAVE_ADDRESS, 193 SAVE_TO_WALLET,
244 SAVE_INSTRUMENT,
245 SAVE_INSTRUMENT_AND_ADDRESS,
246 SEND_STATUS, 194 SEND_STATUS,
247 UPDATE_ADDRESS,
248 UPDATE_INSTRUMENT,
249 }; 195 };
250 196
251 // Like AcceptLegalDocuments, but takes a vector of document ids. 197 // Like AcceptLegalDocuments, but takes a vector of document ids.
252 void DoAcceptLegalDocuments( 198 void DoAcceptLegalDocuments(
253 const std::vector<std::string>& document_ids, 199 const std::vector<std::string>& document_ids,
254 const std::string& google_transaction_id, 200 const std::string& google_transaction_id,
255 const GURL& source_url); 201 const GURL& source_url);
256 202
257 // Posts |post_body| to |url| and notifies |delegate_| when the request is 203 // Posts |post_body| to |url| with content type |mime_type| and notifies
258 // complete. 204 // |delegate_| when the request is complete.
259 void MakeWalletRequest(const GURL& url, const std::string& post_body); 205 void MakeWalletRequest(const GURL& url,
206 const std::string& post_body,
207 const std::string& mime_type);
260 208
261 // Performs bookkeeping tasks for any invalid requests. 209 // Performs bookkeeping tasks for any invalid requests.
262 void HandleMalformedResponse(); 210 void HandleMalformedResponse();
263 void HandleNetworkError(int response_code); 211 void HandleNetworkError(int response_code);
264 void HandleWalletError(ErrorType error_type); 212 void HandleWalletError(ErrorType error_type);
265 213
266 // Start the next pending request (if any). 214 // Start the next pending request (if any).
267 void StartNextPendingRequest(); 215 void StartNextPendingRequest();
268 216
269 // net::URLFetcherDelegate: 217 // net::URLFetcherDelegate:
270 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 218 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
271 219
272 // EncryptionEscrowClientObserver:
273 virtual void OnDidEncryptOneTimePad(
274 const std::string& encrypted_one_time_pad,
275 const std::string& session_material) OVERRIDE;
276 virtual void OnDidEscrowInstrumentInformation(
277 const std::string& escrow_handle) OVERRIDE;
278 virtual void OnDidEscrowCardVerificationNumber(
279 const std::string& escrow_handle) OVERRIDE;
280 virtual void OnDidMakeRequest() OVERRIDE;
281 virtual void OnNetworkError() OVERRIDE;
282 virtual void OnMalformedResponse() OVERRIDE;
283
284 // Logs an UMA metric for each of the |required_actions|. 220 // Logs an UMA metric for each of the |required_actions|.
285 void LogRequiredActions( 221 void LogRequiredActions(
286 const std::vector<RequiredAction>& required_actions) const; 222 const std::vector<RequiredAction>& required_actions) const;
287 223
288 // Converts |request_type| to an UMA metric. 224 // Converts |request_type| to an UMA metric.
289 AutofillMetrics::WalletApiCallMetric RequestTypeToUmaMetric( 225 AutofillMetrics::WalletApiCallMetric RequestTypeToUmaMetric(
290 RequestType request_type) const; 226 RequestType request_type) const;
291 227
292 // The context for the request. Ensures the gdToken cookie is set as a header 228 // The context for the request. Ensures the gdToken cookie is set as a header
293 // in the requests to Online Wallet if it is present. 229 // in the requests to Online Wallet if it is present.
294 scoped_refptr<net::URLRequestContextGetter> context_getter_; 230 scoped_refptr<net::URLRequestContextGetter> context_getter_;
295 231
296 // Observer class that has its various On* methods called based on the results 232 // Observer class that has its various On* methods called based on the results
297 // of a request to Online Wallet. 233 // of a request to Online Wallet.
298 WalletClientDelegate* const delegate_; // must outlive |this|. 234 WalletClientDelegate* const delegate_; // must outlive |this|.
299 235
300 // The current request object. 236 // The current request object.
301 scoped_ptr<net::URLFetcher> request_; 237 scoped_ptr<net::URLFetcher> request_;
302 238
303 // The type of the current request. Must be NO_PENDING_REQUEST for a request 239 // The type of the current request. Must be NO_PENDING_REQUEST for a request
304 // to be initiated as only one request may be running at a given time. 240 // to be initiated as only one request may be running at a given time.
305 RequestType request_type_; 241 RequestType request_type_;
306 242
307 // The one time pad used for GetFullWallet encryption. 243 // The one time pad used for GetFullWallet encryption.
308 std::vector<uint8> one_time_pad_; 244 std::vector<uint8> one_time_pad_;
309 245
310 // GetFullWallet requests and requests that alter instruments rely on requests
311 // made through the |encryption_escrow_client_| finishing first. The request
312 // body is saved here while that those requests are in flight.
313 base::DictionaryValue pending_request_body_;
314
315 // Requests that are waiting to be run. 246 // Requests that are waiting to be run.
316 std::queue<base::Closure> pending_requests_; 247 std::queue<base::Closure> pending_requests_;
317 248
318 // This client is repsonsible for making encryption and escrow calls to Online
319 // Wallet.
320 EncryptionEscrowClient encryption_escrow_client_;
321
322 // When the current request started. Used to track client side latency. 249 // When the current request started. Used to track client side latency.
323 base::Time request_started_timestamp_; 250 base::Time request_started_timestamp_;
324 251
325 DISALLOW_COPY_AND_ASSIGN(WalletClient); 252 DISALLOW_COPY_AND_ASSIGN(WalletClient);
326 }; 253 };
327 254
328 } // namespace wallet 255 } // namespace wallet
329 } // namespace autofill 256 } // namespace autofill
330 257
331 #endif // COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_WALLET_CLIENT_H_ 258 #endif // COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_WALLET_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698