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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autofill/wallet/wallet_client.h
diff --git a/chrome/browser/autofill/wallet/wallet_client.h b/chrome/browser/autofill/wallet/wallet_client.h
new file mode 100644
index 0000000000000000000000000000000000000000..130499c2870365ac6b195d1e841ba3df45c16b51
--- /dev/null
+++ b/chrome/browser/autofill/wallet/wallet_client.h
@@ -0,0 +1,152 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_AUTOFILL_WALLET_WALLET_CLIENT_H_
+#define CHROME_BROWSER_AUTOFILL_WALLET_WALLET_CLIENT_H_
+
+#include <string>
+#include <vector>
+
+#include "base/memory/ref_counted.h"
+#include "net/url_request/url_fetcher_delegate.h"
+
+class GURL;
+
+namespace net {
+class URLRequestContextGetter;
+class URLFetcher;
+}
+
+namespace wallet {
+
+class Address;
+class Cart;
+class FullWallet;
+class WalletItems;
+
+// WalletClient is responsible for making calls to the Online Wallet backend on
+// the user's behalf.
+class WalletClient : public net::URLFetcherDelegate {
+ public:
+ // WalletClientObserver is to be implemented any classes making calls with
+ // WalletClient. The appropriate callback method will be called on
+ // WalletClientObserver with the response from the Online Wallet backend.
+ class WalletClientObserver {
+ public:
+ // Called when an AcceptLegalDocuments request finishes successfully.
+ virtual void OnAcceptLegalDocuments() = 0;
+
+ // Called when an EncryptOtp request finishes successfully.
+ virtual void OnEncryptOtp(const std::string& encrypted_otp,
+ const std::string& session_material) = 0;
+
+ // Called when a GetFullWallet request finishes successfully. Caller owns
+ // the input pointer.
+ virtual void OnGetFullWallet(FullWallet* full_wallet) = 0;
+
+ // Called when a GetWalletItems request finishes successfully. Caller owns
+ // the input pointer.
+ virtual void OnGetWalletItems(WalletItems* wallet_items) = 0;
+
+ // Called when a SendExtendedAutofillStatus request finishes successfully.
+ virtual void OnSendExtendedAutofillStatus() = 0;
+
+ // TODO(ahutter): This is going to need more arguments, probably an error
+ // code and a message for the user.
+ // Called when a request fails due to an Online Wallet error.
+ virtual void OnWalletError() = 0;
+
+ // Called when a request fails due to a network error or if the response was
+ // invalid.
+ virtual void OnNetworkError(int response_code) = 0;
+
+ protected:
+ virtual ~WalletClientObserver() {}
+ };
+ explicit WalletClient(net::URLRequestContextGetter* context_getter);
+ virtual ~WalletClient();
+
+ // GetWalletItems retrieves the user's online wallet. The WalletItems
+ // returned may require additional action such as presenting legal documents
+ // to the user to be accepted.
+ void GetWalletItems(WalletClientObserver* observer);
+
+ // The GetWalletItems call to the Online Wallet backend may require the user
+ // to accept various legal documents before a FullWallet can be generated.
+ // The |document_ids| and |google_transaction_id| are provided in the response
+ // to the GetWalletItems call.
+ void AcceptLegalDocuments(const std::vector<std::string>& document_ids,
+ const std::string& google_transaction_id,
+ WalletClientObserver* observer);
+
+ // Before calling GetFullWallet, the client must encrypt a one time pad,
+ // |otp|, of crytographically secure random bytes. These bytes must be
+ // generated using crypto/random.h.
+ void EncryptOtp(const void* otp,
+ size_t length,
+ WalletClientObserver* observer);
+
+ // GetFullWallet retrieves the a FullWallet for the user. |instrument_id| and
+ // |adddress_id| should have been selected by the user in some UI,
+ // |merchant_domain| should come from the BrowserContext, the |cart|
+ // information will have been provided by the browser, |google_transaction_id|
+ // is the same one that GetWalletItems returns, and |encrypted_otp| and
+ // |session_material| are the results of the EncryptOtp call.
+ void GetFullWallet(const std::string& instrument_id,
+ const std::string& address_id,
+ const std::string& merchant_domain,
+ const Cart& cart,
+ const std::string& google_transaction_id,
+ const std::string& encrypted_otp,
+ const std::string& session_material,
+ WalletClientObserver* observer);
+
+ // SendExtendedAutofillStatus is used for tracking the success of
+ // WalletClient. |success| is a flag for success, |merchant_domain| is the
+ // domain where the purchase occured, if the purchase was not successful
+ // |reason| is populated, and |google_transaction_id| is the same as the one
+ // provided by GetWalletItems.
+ void SendExtendedAutofillStatus(bool success,
+ const std::string& merchant_domain,
+ const std::string& reason,
+ const std::string& google_transaction_id,
+ WalletClientObserver* observer);
+
+ private:
+ // TODO(ahutter): Implement this.
+ std::string GetRiskParams() { return ""; }
+
+ enum RequestType {
+ NO_PENDING_REQUEST,
+ ACCEPT_LEGAL_DOCUMENTS,
+ ENCRYPT_OTP,
+ GET_FULL_WALLET,
+ GET_WALLET_ITEMS,
+ SEND_STATUS,
+ };
+
+ void MakeWalletRequest(const GURL& url,
+ const std::string& post_body,
+ WalletClient::WalletClientObserver* observer,
+ const std::string& content_type);
+ virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
+
+ // The context for the request. Ensures the gdToken cookie is set as a header
+ // in the requests to Online Wallet if it is present.
+ scoped_refptr<net::URLRequestContextGetter> context_getter_;
+ // Observer class that has its various On* methods called based on the results
+ // of a request to Online Wallet.
+ WalletClientObserver* observer_;
+ // The current request object.
+ scoped_ptr<net::URLFetcher> request_;
+ // The type of the current request. Must be NO_PENDING_REQUEST for a request
+ // to be initiated as only one request may be running at a given time.
+ RequestType request_type_;
+ DISALLOW_COPY_AND_ASSIGN(WalletClient);
+};
+
+} // namespace wallet
+
+#endif // CHROME_BROWSER_AUTOFILL_WALLET_WALLET_CLIENT_H_
+
« 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