OLD | NEW |
(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 |
| 13 namespace net { |
| 14 class URLRequestContextGetter; |
| 15 } |
| 16 |
| 17 namespace wallet { |
| 18 |
| 19 class Address; |
| 20 class Cart; |
| 21 class FullWallet; |
| 22 class WalletItems; |
| 23 |
| 24 // WalletClient is responsible for making calls to the Online Wallet backend on |
| 25 // the user's behalf. |
| 26 class WalletClient { |
| 27 public: |
| 28 // WalletClientObserver is to be implemented any classes making calls with |
| 29 // WalletClient. The appropriate callback method will be called on |
| 30 // WalletClientObserver with the response from the Online Wallet backend. |
| 31 class WalletClientObserver { |
| 32 public: |
| 33 // Called when an AcceptLegalDocuments request finishes successfully. |
| 34 virtual void OnAcceptLegalDocuments() = 0; |
| 35 |
| 36 // Called when an EncryptOtp request finishes successfully. |
| 37 virtual void OnEncryptOtp(const std::string& encrypted_otp, |
| 38 const std::string& session_material) = 0; |
| 39 |
| 40 // Called when a GetFullWallet request finishes successfully. Caller owns |
| 41 // the input pointer. |
| 42 virtual void OnGetFullWallet(FullWallet* full_wallet) = 0; |
| 43 |
| 44 // Called when a GetWalletItems request finishes successfully. Caller owns |
| 45 // the input pointer. |
| 46 virtual void OnGetWalletItems(WalletItems* wallet_items) = 0; |
| 47 |
| 48 // Called when a SendExtendedAutofillStatus request finishes successfully. |
| 49 virtual void OnSendExtendedAutofillStatus() = 0; |
| 50 |
| 51 // TODO(ahutter): This is going to need more arguments, probably an error |
| 52 // code and a message for the user. |
| 53 // Called when a request fails due to an Online Wallet error. |
| 54 virtual void OnWalletError() = 0; |
| 55 |
| 56 // Called when a request fails due to a network error or if the response was |
| 57 // invalid. |
| 58 virtual void OnNetworkError(int response_code) = 0; |
| 59 |
| 60 protected: |
| 61 virtual ~WalletClientObserver() {} |
| 62 }; |
| 63 explicit WalletClient(net::URLRequestContextGetter* context_getter); |
| 64 ~WalletClient(); |
| 65 |
| 66 // GetWalletItems retrieves the user's online wallet. The WalletItems |
| 67 // returned may require additional action such as presenting legal documents |
| 68 // to the user to be accepted. |
| 69 void GetWalletItems(WalletClientObserver* observer); |
| 70 |
| 71 // The GetWalletItems call to the Online Wallet backend may require the user |
| 72 // to accept various legal documents before a FullWallet can be generated. |
| 73 // The document_ids and google_transaction_id will be provided in the response |
| 74 // to the GetWalletItems call. |
| 75 void AcceptLegalDocuments(const std::vector<std::string>& document_ids, |
| 76 const std::string& google_transaction_id, |
| 77 WalletClientObserver* observer); |
| 78 |
| 79 // Before calling GetFullWallet, the client must encrypt a one time pad (OTP) |
| 80 // of crytographically secure random bytes. |
| 81 void EncryptOtp(const void* otp, |
| 82 size_t length, |
| 83 WalletClientObserver* observer); |
| 84 |
| 85 // GetFullWallet retrieves the a FullWallet for the user. instrument_id and |
| 86 // adddress_id should have been selected by the user in some UI, the merchant |
| 87 // domain should come from the BrowserContext, the cart information will have |
| 88 // been provided by the browser, the google_transaction_id is the same one |
| 89 // that GetWalletItems returns, and the encrypted_otp and session_material |
| 90 // are the results of the EncryptOtp call. |
| 91 void GetFullWallet(const std::string& instrument_id, |
| 92 const std::string& address_id, |
| 93 const std::string& merchant_domain, |
| 94 const Cart& cart, |
| 95 const std::string& google_transaction_id, |
| 96 const std::string& encrypted_otp, |
| 97 const std::string& session_material, |
| 98 WalletClientObserver* observer); |
| 99 |
| 100 // SendExtendedAutofillStatus is used for tracking the success of |
| 101 // WalletClient. success is a flag for success, merchant_domain is the domain |
| 102 // where the purchase occured, if the purchase was not successful reason is |
| 103 // populated, and google_transaction_id is the same as the one provided by |
| 104 // GetWalletItems. |
| 105 void SendExtendedAutofillStatus(bool success, |
| 106 const std::string& merchant_domain, |
| 107 const std::string& reason, |
| 108 const std::string& google_transaction_id, |
| 109 WalletClientObserver* observer); |
| 110 |
| 111 private: |
| 112 class Core; |
| 113 scoped_refptr<Core> core_; |
| 114 DISALLOW_COPY_AND_ASSIGN(WalletClient); |
| 115 }; |
| 116 |
| 117 } // end wallet namespace |
| 118 |
| 119 #endif // CHROME_BROWSER_AUTOFILL_WALLET_WALLET_CLIENT_H_ |
OLD | NEW |