| OLD | NEW |
| 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> |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 // and address to be updated on the server (and should be NULL if |instrument| | 171 // and address to be updated on the server (and should be NULL if |instrument| |
| 172 // or |address| are new data). | 172 // or |address| are new data). |
| 173 virtual void SaveToWallet( | 173 virtual void SaveToWallet( |
| 174 scoped_ptr<Instrument> instrument, | 174 scoped_ptr<Instrument> instrument, |
| 175 scoped_ptr<Address> address, | 175 scoped_ptr<Address> address, |
| 176 const WalletItems::MaskedInstrument* reference_instrument, | 176 const WalletItems::MaskedInstrument* reference_instrument, |
| 177 const Address* reference_address); | 177 const Address* reference_address); |
| 178 | 178 |
| 179 bool HasRequestInProgress() const; | 179 bool HasRequestInProgress() const; |
| 180 | 180 |
| 181 // Cancels and clears the current |request_| and |pending_requests_| (if any). | 181 // Cancels and clears the current |request_|. |
| 182 void CancelRequests(); | 182 void CancelRequest(); |
| 183 | 183 |
| 184 // Sets the user index and cancels any pending requests. | 184 // Sets the user index and cancels any pending requests. |
| 185 void SetUserIndex(size_t user_index); | 185 void SetUserIndex(size_t user_index); |
| 186 size_t user_index() const { return user_index_; } | 186 size_t user_index() const { return user_index_; } |
| 187 | 187 |
| 188 private: | 188 private: |
| 189 FRIEND_TEST_ALL_PREFIXES(WalletClientTest, PendingRequest); | 189 FRIEND_TEST_ALL_PREFIXES(WalletClientTest, PendingRequest); |
| 190 FRIEND_TEST_ALL_PREFIXES(WalletClientTest, CancelRequests); | 190 FRIEND_TEST_ALL_PREFIXES(WalletClientTest, CancelRequests); |
| 191 | 191 |
| 192 enum RequestType { | 192 enum RequestType { |
| 193 NO_PENDING_REQUEST, | 193 NO_REQUEST, |
| 194 ACCEPT_LEGAL_DOCUMENTS, | 194 ACCEPT_LEGAL_DOCUMENTS, |
| 195 AUTHENTICATE_INSTRUMENT, | 195 AUTHENTICATE_INSTRUMENT, |
| 196 GET_FULL_WALLET, | 196 GET_FULL_WALLET, |
| 197 GET_WALLET_ITEMS, | 197 GET_WALLET_ITEMS, |
| 198 SAVE_TO_WALLET, | 198 SAVE_TO_WALLET, |
| 199 }; | 199 }; |
| 200 | 200 |
| 201 // Like AcceptLegalDocuments, but takes a vector of document ids. | 201 // Like AcceptLegalDocuments, but takes a vector of document ids. |
| 202 void DoAcceptLegalDocuments( | 202 void DoAcceptLegalDocuments( |
| 203 const std::vector<std::string>& document_ids, | 203 const std::vector<std::string>& document_ids, |
| 204 const std::string& google_transaction_id); | 204 const std::string& google_transaction_id); |
| 205 | 205 |
| 206 // Posts |post_body| to |url| with content type |mime_type| and notifies | 206 // Posts |post_body| to |url| with content type |mime_type| and notifies |
| 207 // |delegate_| when the request is complete. | 207 // |delegate_| when the request is complete. |
| 208 void MakeWalletRequest(const GURL& url, | 208 void MakeWalletRequest(const GURL& url, |
| 209 const std::string& post_body, | 209 const std::string& post_body, |
| 210 const std::string& mime_type, | 210 const std::string& mime_type, |
| 211 RequestType request_type); | 211 RequestType request_type); |
| 212 | 212 |
| 213 // Performs bookkeeping tasks for any invalid requests. | 213 // Performs bookkeeping tasks for any invalid requests. |
| 214 void HandleMalformedResponse(RequestType request_type, | 214 void HandleMalformedResponse(RequestType request_type, |
| 215 net::URLFetcher* request); | 215 net::URLFetcher* request); |
| 216 void HandleNetworkError(int response_code); | 216 void HandleNetworkError(int response_code); |
| 217 void HandleWalletError(ErrorType error_type); | 217 void HandleWalletError(ErrorType error_type); |
| 218 | 218 |
| 219 // Start the next pending request (if any). | |
| 220 void StartNextPendingRequest(); | |
| 221 | |
| 222 // net::URLFetcherDelegate: | 219 // net::URLFetcherDelegate: |
| 223 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 220 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 224 | 221 |
| 225 // Logs an UMA metric for each of the |required_actions|. | 222 // Logs an UMA metric for each of the |required_actions|. |
| 226 void LogRequiredActions( | 223 void LogRequiredActions( |
| 227 const std::vector<RequiredAction>& required_actions) const; | 224 const std::vector<RequiredAction>& required_actions) const; |
| 228 | 225 |
| 229 // Converts |request_type| to an UMA metric. | 226 // Converts |request_type| to an UMA metric. |
| 230 AutofillMetrics::WalletApiCallMetric RequestTypeToUmaMetric( | 227 AutofillMetrics::WalletApiCallMetric RequestTypeToUmaMetric( |
| 231 RequestType request_type) const; | 228 RequestType request_type) const; |
| 232 | 229 |
| 233 // The context for the request. Ensures the gdToken cookie is set as a header | 230 // The context for the request. Ensures the gdToken cookie is set as a header |
| 234 // in the requests to Online Wallet if it is present. | 231 // in the requests to Online Wallet if it is present. |
| 235 scoped_refptr<net::URLRequestContextGetter> context_getter_; | 232 scoped_refptr<net::URLRequestContextGetter> context_getter_; |
| 236 | 233 |
| 237 // Observer class that has its various On* methods called based on the results | 234 // Observer class that has its various On* methods called based on the results |
| 238 // of a request to Online Wallet. | 235 // of a request to Online Wallet. |
| 239 WalletClientDelegate* const delegate_; // must outlive |this|. | 236 WalletClientDelegate* const delegate_; // must outlive |this|. |
| 240 | 237 |
| 241 // The index of the user account we're making requests for. The index is into | 238 // The index of the user account we're making requests for. The index is into |
| 242 // GAIA's list of signed in users. | 239 // GAIA's list of signed in users. |
| 243 size_t user_index_; | 240 size_t user_index_; |
| 244 | 241 |
| 245 // The URL of the page we're making requests on behalf of. | 242 // The URL of the page we're making requests on behalf of. |
| 246 GURL source_url_; | 243 GURL source_url_; |
| 247 | 244 |
| 248 // The current request object. | 245 // The current request object. |
| 249 scoped_ptr<net::URLFetcher> request_; | 246 scoped_ptr<net::URLFetcher> request_; |
| 250 | 247 |
| 251 // The type of the current request. Must be NO_PENDING_REQUEST for a request | 248 // The type of the current request. Must be NO_REQUEST for a request |
| 252 // to be initiated as only one request may be running at a given time. | 249 // to be initiated as only one request may be running at a given time. |
| 253 RequestType request_type_; | 250 RequestType request_type_; |
| 254 | 251 |
| 255 // The one time pad used for GetFullWallet encryption. | 252 // The one time pad used for GetFullWallet encryption. |
| 256 std::vector<uint8> one_time_pad_; | 253 std::vector<uint8> one_time_pad_; |
| 257 | 254 |
| 258 // Requests that are waiting to be run. | |
| 259 std::queue<base::Closure> pending_requests_; | |
| 260 | |
| 261 // When the current request started. Used to track client side latency. | 255 // When the current request started. Used to track client side latency. |
| 262 base::Time request_started_timestamp_; | 256 base::Time request_started_timestamp_; |
| 263 | 257 |
| 264 base::WeakPtrFactory<WalletClient> weak_ptr_factory_; | 258 base::WeakPtrFactory<WalletClient> weak_ptr_factory_; |
| 265 | 259 |
| 266 DISALLOW_COPY_AND_ASSIGN(WalletClient); | 260 DISALLOW_COPY_AND_ASSIGN(WalletClient); |
| 267 }; | 261 }; |
| 268 | 262 |
| 269 } // namespace wallet | 263 } // namespace wallet |
| 270 } // namespace autofill | 264 } // namespace autofill |
| 271 | 265 |
| 272 #endif // COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_WALLET_CLIENT_H_ | 266 #endif // COMPONENTS_AUTOFILL_CONTENT_BROWSER_WALLET_WALLET_CLIENT_H_ |
| OLD | NEW |