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

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

Powered by Google App Engine
This is Rietveld 408576698