Chromium Code Reviews| 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_API_FLOW_H_ | 5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_GCD_API_FLOW_H_ |
| 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_GCD_API_FLOW_H_ | 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_GCD_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" |
| 11 #include "chrome/browser/local_discovery/privet_http.h" | 11 #include "chrome/browser/local_discovery/privet_http.h" |
| 12 #include "google_apis/gaia/oauth2_token_service.h" | 12 #include "google_apis/gaia/oauth2_token_service.h" |
| 13 #include "net/url_request/url_fetcher.h" | 13 #include "net/url_request/url_fetcher.h" |
| 14 #include "net/url_request/url_fetcher_delegate.h" | 14 #include "net/url_request/url_fetcher_delegate.h" |
| 15 #include "net/url_request/url_request_context_getter.h" | 15 #include "net/url_request/url_request_context_getter.h" |
| 16 | 16 |
| 17 namespace local_discovery { | 17 namespace local_discovery { |
| 18 | 18 |
| 19 // API flow for communicating with cloud print and cloud devices. | 19 // API flow for communicating with cloud print and cloud devices. |
| 20 class GCDApiFlow : public net::URLFetcherDelegate, | 20 class GCDApiFlowInterface { |
|
Noam Samuel
2014/06/09 17:53:22
Isn't it more common to write GCDApiFlow and GCDAp
| |
| 21 public OAuth2TokenService::Consumer { | |
| 22 public: | 21 public: |
| 23 // TODO(noamsml): Better error model for this class. | 22 // TODO(noamsml): Better error model for this class. |
| 24 enum Status { | 23 enum Status { |
| 25 SUCCESS, | 24 SUCCESS, |
| 26 ERROR_TOKEN, | 25 ERROR_TOKEN, |
| 27 ERROR_NETWORK, | 26 ERROR_NETWORK, |
| 28 ERROR_HTTP_CODE, | 27 ERROR_HTTP_CODE, |
| 29 ERROR_FROM_SERVER, | 28 ERROR_FROM_SERVER, |
| 30 ERROR_MALFORMED_RESPONSE | 29 ERROR_MALFORMED_RESPONSE |
| 31 }; | 30 }; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 50 virtual std::vector<std::string> GetExtraRequestHeaders() = 0; | 49 virtual std::vector<std::string> GetExtraRequestHeaders() = 0; |
| 51 | 50 |
| 52 // If there is no data, set upload_type and upload_data to "" | 51 // If there is no data, set upload_type and upload_data to "" |
| 53 virtual void GetUploadData(std::string* upload_type, | 52 virtual void GetUploadData(std::string* upload_type, |
| 54 std::string* upload_data); | 53 std::string* upload_data); |
| 55 | 54 |
| 56 private: | 55 private: |
| 57 DISALLOW_COPY_AND_ASSIGN(Request); | 56 DISALLOW_COPY_AND_ASSIGN(Request); |
| 58 }; | 57 }; |
| 59 | 58 |
| 59 GCDApiFlowInterface(); | |
| 60 virtual ~GCDApiFlowInterface(); | |
| 61 | |
| 62 virtual void Start(scoped_ptr<Request> request) = 0; | |
| 63 | |
| 64 private: | |
| 65 DISALLOW_COPY_AND_ASSIGN(GCDApiFlowInterface); | |
| 66 }; | |
| 67 | |
| 68 class GCDApiFlow : public GCDApiFlowInterface, | |
| 69 public net::URLFetcherDelegate, | |
| 70 public OAuth2TokenService::Consumer { | |
| 71 public: | |
| 60 // Create an OAuth2-based confirmation. | 72 // Create an OAuth2-based confirmation. |
| 61 GCDApiFlow(net::URLRequestContextGetter* request_context, | 73 GCDApiFlow(net::URLRequestContextGetter* request_context, |
| 62 OAuth2TokenService* token_service, | 74 OAuth2TokenService* token_service, |
| 63 const std::string& account_id, | 75 const std::string& account_id); |
| 64 scoped_ptr<Request> request); | |
| 65 | 76 |
| 66 virtual ~GCDApiFlow(); | 77 virtual ~GCDApiFlow(); |
| 67 | 78 |
| 68 void Start(); | 79 virtual void Start(scoped_ptr<Request> request) OVERRIDE; |
| 69 | 80 |
| 70 // net::URLFetcherDelegate implementation: | 81 // net::URLFetcherDelegate implementation: |
| 71 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 82 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 72 | 83 |
| 73 // OAuth2TokenService::Consumer implementation: | 84 // OAuth2TokenService::Consumer implementation: |
| 74 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 85 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 75 const std::string& access_token, | 86 const std::string& access_token, |
| 76 const base::Time& expiration_time) OVERRIDE; | 87 const base::Time& expiration_time) OVERRIDE; |
| 77 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, | 88 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 78 const GoogleServiceAuthError& error) OVERRIDE; | 89 const GoogleServiceAuthError& error) OVERRIDE; |
| 79 | 90 |
| 80 private: | 91 private: |
| 81 void CreateRequest(const GURL& url); | 92 void CreateRequest(const GURL& url); |
| 82 | 93 |
| 83 scoped_ptr<net::URLFetcher> url_fetcher_; | 94 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 84 scoped_ptr<OAuth2TokenService::Request> oauth_request_; | 95 scoped_ptr<OAuth2TokenService::Request> oauth_request_; |
| 85 scoped_refptr<net::URLRequestContextGetter> request_context_; | 96 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 86 OAuth2TokenService* token_service_; | 97 OAuth2TokenService* token_service_; |
| 87 std::string account_id_; | 98 std::string account_id_; |
| 88 scoped_ptr<Request> request_; | 99 scoped_ptr<Request> request_; |
| 100 | |
| 89 DISALLOW_COPY_AND_ASSIGN(GCDApiFlow); | 101 DISALLOW_COPY_AND_ASSIGN(GCDApiFlow); |
| 90 }; | 102 }; |
| 91 | 103 |
| 92 class GCDApiFlowRequest : public GCDApiFlow::Request { | 104 class GCDApiFlowRequest : public GCDApiFlowInterface::Request { |
| 93 public: | 105 public: |
| 94 GCDApiFlowRequest(); | 106 GCDApiFlowRequest(); |
| 95 virtual ~GCDApiFlowRequest(); | 107 virtual ~GCDApiFlowRequest(); |
| 96 | 108 |
| 97 // GCDApiFlowRequest implementation | 109 // GCDApiFlowRequest implementation |
| 98 virtual std::string GetOAuthScope() OVERRIDE; | 110 virtual std::string GetOAuthScope() OVERRIDE; |
| 99 virtual std::vector<std::string> GetExtraRequestHeaders() OVERRIDE; | 111 virtual std::vector<std::string> GetExtraRequestHeaders() OVERRIDE; |
| 100 | 112 |
| 101 private: | 113 private: |
| 102 DISALLOW_COPY_AND_ASSIGN(GCDApiFlowRequest); | 114 DISALLOW_COPY_AND_ASSIGN(GCDApiFlowRequest); |
| 103 }; | 115 }; |
| 104 | 116 |
| 105 class CloudPrintApiFlowRequest : public GCDApiFlow::Request { | 117 class CloudPrintApiFlowRequest : public GCDApiFlowInterface::Request { |
| 106 public: | 118 public: |
| 107 CloudPrintApiFlowRequest(); | 119 CloudPrintApiFlowRequest(); |
| 108 virtual ~CloudPrintApiFlowRequest(); | 120 virtual ~CloudPrintApiFlowRequest(); |
| 109 | 121 |
| 110 // GCDApiFlowRequest implementation | 122 // GCDApiFlowRequest implementation |
| 111 virtual std::string GetOAuthScope() OVERRIDE; | 123 virtual std::string GetOAuthScope() OVERRIDE; |
| 112 virtual std::vector<std::string> GetExtraRequestHeaders() OVERRIDE; | 124 virtual std::vector<std::string> GetExtraRequestHeaders() OVERRIDE; |
| 113 | 125 |
| 114 private: | 126 private: |
| 115 DISALLOW_COPY_AND_ASSIGN(CloudPrintApiFlowRequest); | 127 DISALLOW_COPY_AND_ASSIGN(CloudPrintApiFlowRequest); |
| 116 }; | 128 }; |
| 117 | 129 |
| 118 } // namespace local_discovery | 130 } // namespace local_discovery |
| 119 | 131 |
| 120 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_GCD_API_FLOW_H_ | 132 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_GCD_API_FLOW_H_ |
| OLD | NEW |