| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CHROME_BROWSER_LOCAL_DISCOVERY_GCD_BASE_API_FLOW_H_ | 5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_GCD_BASE_API_FLOW_H_ |
| 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_GCD_BASE_API_FLOW_H_ | 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_GCD_BASE_API_FLOW_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "chrome/browser/local_discovery/privet_constants.h" | 10 #include "chrome/browser/local_discovery/privet_constants.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 class Delegate { | 33 class Delegate { |
| 34 public: | 34 public: |
| 35 virtual ~Delegate() {} | 35 virtual ~Delegate() {} |
| 36 | 36 |
| 37 virtual void OnGCDAPIFlowError(GCDBaseApiFlow* flow, Status status) = 0; | 37 virtual void OnGCDAPIFlowError(GCDBaseApiFlow* flow, Status status) = 0; |
| 38 | 38 |
| 39 virtual void OnGCDAPIFlowComplete(GCDBaseApiFlow* flow, | 39 virtual void OnGCDAPIFlowComplete(GCDBaseApiFlow* flow, |
| 40 const base::DictionaryValue* value) = 0; | 40 const base::DictionaryValue* value) = 0; |
| 41 | 41 |
| 42 // Return 1 if flow is for a Cloud Print device | 42 virtual GURL GetURL() = 0; |
| 43 virtual bool GCDIsCloudPrint() = 0; | 43 |
| 44 virtual std::string GetOAuthScope(); |
| 44 | 45 |
| 45 virtual net::URLFetcher::RequestType GetRequestType(); | 46 virtual net::URLFetcher::RequestType GetRequestType(); |
| 46 | 47 |
| 48 virtual std::vector<std::string> GetExtraRequestHeaders(); |
| 49 |
| 47 // If there is no data, set upload_type and upload_data to "" | 50 // If there is no data, set upload_type and upload_data to "" |
| 48 virtual void GetUploadData(std::string* upload_type, | 51 virtual void GetUploadData(std::string* upload_type, |
| 49 std::string* upload_data); | 52 std::string* upload_data); |
| 50 }; | 53 }; |
| 51 | 54 |
| 52 // Create an OAuth2-based confirmation. | 55 // Create an OAuth2-based confirmation. |
| 53 GCDBaseApiFlow(net::URLRequestContextGetter* request_context, | 56 GCDBaseApiFlow(net::URLRequestContextGetter* request_context, |
| 54 OAuth2TokenService* token_service, | 57 OAuth2TokenService* token_service, |
| 55 const std::string& account_id, | 58 const std::string& account_id, |
| 56 const GURL& url, | |
| 57 Delegate* delegate); | |
| 58 | |
| 59 // Create a cookie-based confirmation. | |
| 60 GCDBaseApiFlow(net::URLRequestContextGetter* request_context, | |
| 61 int user_index, | |
| 62 const std::string& xsrf_token, | |
| 63 const GURL& url, | |
| 64 Delegate* delegate); | |
| 65 | |
| 66 // Create a cookie-based confirmation with no XSRF token (for requests that | |
| 67 // don't need an XSRF token). | |
| 68 GCDBaseApiFlow(net::URLRequestContextGetter* request_context, | |
| 69 int user_index, | |
| 70 const GURL& url, | |
| 71 Delegate* delegate); | 59 Delegate* delegate); |
| 72 | 60 |
| 73 virtual ~GCDBaseApiFlow(); | 61 virtual ~GCDBaseApiFlow(); |
| 74 | 62 |
| 75 void Start(); | 63 void Start(); |
| 76 | 64 |
| 77 // net::URLFetcherDelegate implementation: | 65 // net::URLFetcherDelegate implementation: |
| 78 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 66 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 79 | 67 |
| 80 // OAuth2TokenService::Consumer implementation: | 68 // OAuth2TokenService::Consumer implementation: |
| 81 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 69 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 82 const std::string& access_token, | 70 const std::string& access_token, |
| 83 const base::Time& expiration_time) OVERRIDE; | 71 const base::Time& expiration_time) OVERRIDE; |
| 84 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, | 72 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 85 const GoogleServiceAuthError& error) OVERRIDE; | 73 const GoogleServiceAuthError& error) OVERRIDE; |
| 86 | 74 |
| 87 private: | 75 private: |
| 88 void CreateRequest(const GURL& url); | 76 void CreateRequest(const GURL& url); |
| 89 | 77 |
| 90 scoped_ptr<net::URLFetcher> url_fetcher_; | 78 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 91 scoped_ptr<OAuth2TokenService::Request> oauth_request_; | 79 scoped_ptr<OAuth2TokenService::Request> oauth_request_; |
| 92 scoped_refptr<net::URLRequestContextGetter> request_context_; | 80 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 93 OAuth2TokenService* token_service_; | 81 OAuth2TokenService* token_service_; |
| 94 std::string account_id_; | 82 std::string account_id_; |
| 95 GURL url_; | |
| 96 Delegate* delegate_; | 83 Delegate* delegate_; |
| 84 DISALLOW_COPY_AND_ASSIGN(GCDBaseApiFlow); |
| 85 }; |
| 86 |
| 87 class CloudPrintApiFlowDelegate : public GCDBaseApiFlow::Delegate { |
| 88 public: |
| 89 CloudPrintApiFlowDelegate(); |
| 90 virtual ~CloudPrintApiFlowDelegate(); |
| 91 |
| 92 // GCDBaseApiFlow::Delegate implementation |
| 93 virtual std::string GetOAuthScope() OVERRIDE; |
| 94 virtual std::vector<std::string> GetExtraRequestHeaders() OVERRIDE; |
| 95 |
| 96 private: |
| 97 DISALLOW_COPY_AND_ASSIGN(CloudPrintApiFlowDelegate); |
| 97 }; | 98 }; |
| 98 | 99 |
| 99 } // namespace local_discovery | 100 } // namespace local_discovery |
| 100 | 101 |
| 101 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_GCD_BASE_API_FLOW_H_ | 102 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_GCD_BASE_API_FLOW_H_ |
| OLD | NEW |