OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_CLOUD_PRINT_BASE_API_FLOW_H_ |
| 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_CLOUD_PRINT_BASE_API_FLOW_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "chrome/browser/local_discovery/privet_http.h" |
| 11 #include "google_apis/gaia/oauth2_token_service.h" |
| 12 #include "net/url_request/url_fetcher.h" |
| 13 #include "net/url_request/url_fetcher_delegate.h" |
| 14 #include "net/url_request/url_request_context_getter.h" |
| 15 |
| 16 namespace local_discovery { |
| 17 |
| 18 // API call flow for communicating with cloud print. |
| 19 class CloudPrintBaseApiFlow : public net::URLFetcherDelegate, |
| 20 public OAuth2TokenService::Consumer { |
| 21 public: |
| 22 // TODO(noamsml): Better error model for this class. |
| 23 enum Status { |
| 24 SUCCESS, |
| 25 ERROR_TOKEN, |
| 26 ERROR_NETWORK, |
| 27 ERROR_HTTP_CODE, |
| 28 ERROR_FROM_SERVER, |
| 29 ERROR_MALFORMED_RESPONSE |
| 30 }; |
| 31 |
| 32 class Delegate { |
| 33 public: |
| 34 virtual ~Delegate() {} |
| 35 |
| 36 virtual void OnCloudPrintAPIFlowError(CloudPrintBaseApiFlow* flow, |
| 37 Status status) = 0; |
| 38 virtual void OnCloudPrintAPIFlowComplete( |
| 39 CloudPrintBaseApiFlow* flow, |
| 40 const base::DictionaryValue* value) = 0; |
| 41 }; |
| 42 |
| 43 // Create an OAuth2-based confirmation. |
| 44 CloudPrintBaseApiFlow(net::URLRequestContextGetter* request_context, |
| 45 OAuth2TokenService* token_service_, |
| 46 const GURL& automated_claim_url, |
| 47 Delegate* delegate); |
| 48 |
| 49 // Create a cookie-based confirmation. |
| 50 CloudPrintBaseApiFlow(net::URLRequestContextGetter* request_context, |
| 51 int user_index, |
| 52 const std::string& xsrf_token, |
| 53 const GURL& automated_claim_url, |
| 54 Delegate* delegate); |
| 55 |
| 56 // Create a cookie-based confirmation with no XSRF token (for requests that |
| 57 // don't need an XSRF token). |
| 58 CloudPrintBaseApiFlow(net::URLRequestContextGetter* request_context, |
| 59 int user_index, |
| 60 const GURL& automated_claim_url, |
| 61 Delegate* delegate); |
| 62 |
| 63 |
| 64 virtual ~CloudPrintBaseApiFlow(); |
| 65 |
| 66 void Start(); |
| 67 |
| 68 |
| 69 // net::URLFetcherDelegate implementation: |
| 70 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 71 |
| 72 // OAuth2TokenService::Consumer implementation: |
| 73 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 74 const std::string& access_token, |
| 75 const base::Time& expiration_time) OVERRIDE; |
| 76 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 77 const GoogleServiceAuthError& error) OVERRIDE; |
| 78 |
| 79 private: |
| 80 bool UseOAuth2() { return token_service_ != NULL; } |
| 81 |
| 82 void CreateRequest(const GURL& url); |
| 83 |
| 84 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 85 scoped_ptr<OAuth2TokenService::Request> oauth_request_; |
| 86 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 87 OAuth2TokenService* token_service_; |
| 88 int user_index_; |
| 89 std::string xsrf_token_; |
| 90 GURL url_; |
| 91 Delegate* delegate_; |
| 92 }; |
| 93 |
| 94 } // namespace local_discovery |
| 95 |
| 96 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_CLOUD_PRINT_BASE_API_FLOW_H_ |
OLD | NEW |