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

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

Issue 11293078: Integrating Online Wallet into Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing HexStringToInt Created 8 years 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 "net/url_request/url_fetcher_delegate.h"
13
14 class GURL;
15
16 namespace net {
17 class URLRequestContextGetter;
18 class URLFetcher;
19 }
20
21 namespace wallet {
22
23 class Address;
24 class Cart;
25 class FullWallet;
26 class WalletItems;
27
28 // WalletClient is responsible for making calls to the Online Wallet backend on
29 // the user's behalf.
30 class WalletClient : public net::URLFetcherDelegate {
31 public:
32 // WalletClientObserver is to be implemented any classes making calls with
33 // WalletClient. The appropriate callback method will be called on
34 // WalletClientObserver with the response from the Online Wallet backend.
35 class WalletClientObserver {
36 public:
37 // Called when an AcceptLegalDocuments request finishes successfully.
38 virtual void OnAcceptLegalDocuments() = 0;
39
40 // Called when an EncryptOtp request finishes successfully.
41 virtual void OnEncryptOtp(const std::string& encrypted_otp,
42 const std::string& session_material) = 0;
43
44 // Called when a GetFullWallet request finishes successfully. Caller owns
45 // the input pointer.
46 virtual void OnGetFullWallet(FullWallet* full_wallet) = 0;
47
48 // Called when a GetWalletItems request finishes successfully. Caller owns
49 // the input pointer.
50 virtual void OnGetWalletItems(WalletItems* wallet_items) = 0;
51
52 // Called when a SendExtendedAutofillStatus request finishes successfully.
53 virtual void OnSendExtendedAutofillStatus() = 0;
54
55 // TODO(ahutter): This is going to need more arguments, probably an error
56 // code and a message for the user.
57 // Called when a request fails due to an Online Wallet error.
58 virtual void OnWalletError() = 0;
59
60 // Called when a request fails due to a network error or if the response was
61 // invalid.
62 virtual void OnNetworkError(int response_code) = 0;
63
64 protected:
65 virtual ~WalletClientObserver() {}
66 };
67 explicit WalletClient(net::URLRequestContextGetter* context_getter);
68 virtual ~WalletClient();
69
70 // GetWalletItems retrieves the user's online wallet. The WalletItems
71 // returned may require additional action such as presenting legal documents
72 // to the user to be accepted.
73 void GetWalletItems(WalletClientObserver* observer);
74
75 // The GetWalletItems call to the Online Wallet backend may require the user
76 // to accept various legal documents before a FullWallet can be generated.
77 // The |document_ids| and |google_transaction_id| are provided in the response
78 // to the GetWalletItems call.
79 void AcceptLegalDocuments(const std::vector<std::string>& document_ids,
80 const std::string& google_transaction_id,
81 WalletClientObserver* observer);
82
83 // Before calling GetFullWallet, the client must encrypt a one time pad,
84 // |otp|, of crytographically secure random bytes. These bytes must be
85 // generated using crypto/random.h.
86 void EncryptOtp(const void* otp,
87 size_t length,
88 WalletClientObserver* observer);
89
90 // GetFullWallet retrieves the a FullWallet for the user. |instrument_id| and
91 // |adddress_id| should have been selected by the user in some UI,
92 // |merchant_domain| should come from the BrowserContext, the |cart|
93 // information will have been provided by the browser, |google_transaction_id|
94 // is the same one that GetWalletItems returns, and |encrypted_otp| and
95 // |session_material| are the results of the EncryptOtp call.
96 void GetFullWallet(const std::string& instrument_id,
97 const std::string& address_id,
98 const std::string& merchant_domain,
99 const Cart& cart,
100 const std::string& google_transaction_id,
101 const std::string& encrypted_otp,
102 const std::string& session_material,
103 WalletClientObserver* observer);
104
105 // SendExtendedAutofillStatus is used for tracking the success of
106 // WalletClient. |success| is a flag for success, |merchant_domain| is the
107 // domain where the purchase occured, if the purchase was not successful
108 // |reason| is populated, and |google_transaction_id| is the same as the one
109 // provided by GetWalletItems.
110 void SendExtendedAutofillStatus(bool success,
111 const std::string& merchant_domain,
112 const std::string& reason,
113 const std::string& google_transaction_id,
114 WalletClientObserver* observer);
115
116 private:
117 // TODO(ahutter): Implement this.
118 std::string GetRiskParams() { return ""; }
119
120 enum RequestType {
121 NO_PENDING_REQUEST,
122 ACCEPT_LEGAL_DOCUMENTS,
123 ENCRYPT_OTP,
124 GET_FULL_WALLET,
125 GET_WALLET_ITEMS,
126 SEND_STATUS,
127 };
128
129 void MakeWalletRequest(const GURL& url,
130 const std::string& post_body,
131 WalletClient::WalletClientObserver* observer,
132 const std::string& content_type);
133 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
134
135 // The context for the request. Ensures the gdToken cookie is set as a header
136 // in the requests to Online Wallet if it is present.
137 scoped_refptr<net::URLRequestContextGetter> context_getter_;
138 // Observer class that has its various On* methods called based on the results
139 // of a request to Online Wallet.
140 WalletClientObserver* observer_;
141 // The current request object.
142 scoped_ptr<net::URLFetcher> request_;
143 // The type of the current request. Must be NO_PENDING_REQUEST for a request
144 // to be initiated as only one request may be running at a given time.
145 RequestType request_type_;
146 DISALLOW_COPY_AND_ASSIGN(WalletClient);
147 };
148
149 } // namespace wallet
150
151 #endif // CHROME_BROWSER_AUTOFILL_WALLET_WALLET_CLIENT_H_
152
OLDNEW
« no previous file with comments | « chrome/browser/autofill/wallet/wallet_address_unittest.cc ('k') | chrome/browser/autofill/wallet/wallet_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698