| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_CHROMEOS_GDATA_OPERATIONS_BASE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_OPERATIONS_BASE_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_GDATA_OPERATIONS_BASE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_OPERATIONS_BASE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" | 12 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" |
| 13 #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h" | 13 #include "chrome/browser/chromeos/gdata/operation_registry.h" |
| 14 #include "chrome/common/net/gaia/oauth2_access_token_consumer.h" | 14 #include "chrome/common/net/gaia/oauth2_access_token_consumer.h" |
| 15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 16 #include "net/http/http_response_headers.h" | 16 #include "net/http/http_response_headers.h" |
| 17 #include "net/url_request/url_fetcher.h" | 17 #include "net/url_request/url_fetcher.h" |
| 18 #include "net/url_request/url_fetcher_delegate.h" | 18 #include "net/url_request/url_fetcher_delegate.h" |
| 19 | 19 |
| 20 class OAuth2AccessTokenFetcher; | 20 class OAuth2AccessTokenFetcher; |
| 21 | 21 |
| 22 namespace gdata { | 22 namespace gdata { |
| 23 | 23 |
| 24 //================================ AuthOperation =============================== | 24 //================================ AuthOperation =============================== |
| 25 | 25 |
| 26 // Callback type for authentication related DriveServiceInterface calls. | 26 // Callback type for authentication related DriveServiceInterface calls. |
| 27 typedef base::Callback<void(GDataErrorCode error, | 27 typedef base::Callback<void(GDataErrorCode error, |
| 28 const std::string& token)> AuthStatusCallback; | 28 const std::string& token)> AuthStatusCallback; |
| 29 | 29 |
| 30 // OAuth2 authorization token retrieval operation. | 30 // OAuth2 authorization token retrieval operation. |
| 31 class AuthOperation : public GDataOperationRegistry::Operation, | 31 class AuthOperation : public OperationRegistry::Operation, |
| 32 public OAuth2AccessTokenConsumer { | 32 public OAuth2AccessTokenConsumer { |
| 33 public: | 33 public: |
| 34 AuthOperation(GDataOperationRegistry* registry, | 34 AuthOperation(OperationRegistry* registry, |
| 35 const AuthStatusCallback& callback, | 35 const AuthStatusCallback& callback, |
| 36 const std::string& refresh_token); | 36 const std::string& refresh_token); |
| 37 virtual ~AuthOperation(); | 37 virtual ~AuthOperation(); |
| 38 void Start(); | 38 void Start(); |
| 39 | 39 |
| 40 // Overridden from OAuth2AccessTokenConsumer: | 40 // Overridden from OAuth2AccessTokenConsumer: |
| 41 virtual void OnGetTokenSuccess(const std::string& access_token, | 41 virtual void OnGetTokenSuccess(const std::string& access_token, |
| 42 const base::Time& expiration_time) OVERRIDE; | 42 const base::Time& expiration_time) OVERRIDE; |
| 43 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; | 43 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; |
| 44 | 44 |
| 45 // Overridden from GDataOpertionRegistry::Operation | 45 // Overridden from OperationRegistry::Operation |
| 46 virtual void DoCancel() OVERRIDE; | 46 virtual void DoCancel() OVERRIDE; |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 std::string refresh_token_; | 49 std::string refresh_token_; |
| 50 AuthStatusCallback callback_; | 50 AuthStatusCallback callback_; |
| 51 scoped_ptr<OAuth2AccessTokenFetcher> oauth2_access_token_fetcher_; | 51 scoped_ptr<OAuth2AccessTokenFetcher> oauth2_access_token_fetcher_; |
| 52 | 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(AuthOperation); | 53 DISALLOW_COPY_AND_ASSIGN(AuthOperation); |
| 54 }; | 54 }; |
| 55 | 55 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 79 | 79 |
| 80 //============================ UrlFetchOperationBase =========================== | 80 //============================ UrlFetchOperationBase =========================== |
| 81 | 81 |
| 82 // Callback type for getting the content from URLFetcher::GetResponseAsString(). | 82 // Callback type for getting the content from URLFetcher::GetResponseAsString(). |
| 83 typedef base::Callback<void( | 83 typedef base::Callback<void( |
| 84 GDataErrorCode error, | 84 GDataErrorCode error, |
| 85 scoped_ptr<std::string> content)> GetContentCallback; | 85 scoped_ptr<std::string> content)> GetContentCallback; |
| 86 | 86 |
| 87 // Base class for operations that are fetching URLs. | 87 // Base class for operations that are fetching URLs. |
| 88 class UrlFetchOperationBase : public GDataOperationInterface, | 88 class UrlFetchOperationBase : public GDataOperationInterface, |
| 89 public GDataOperationRegistry::Operation, | 89 public OperationRegistry::Operation, |
| 90 public net::URLFetcherDelegate { | 90 public net::URLFetcherDelegate { |
| 91 public: | 91 public: |
| 92 // Overridden from GDataOperationInterface. | 92 // Overridden from GDataOperationInterface. |
| 93 virtual void Start(const std::string& auth_token) OVERRIDE; | 93 virtual void Start(const std::string& auth_token) OVERRIDE; |
| 94 | 94 |
| 95 // Overridden from GDataOperationInterface. | 95 // Overridden from GDataOperationInterface. |
| 96 virtual void SetReAuthenticateCallback( | 96 virtual void SetReAuthenticateCallback( |
| 97 const ReAuthenticateCallback& callback) OVERRIDE; | 97 const ReAuthenticateCallback& callback) OVERRIDE; |
| 98 | 98 |
| 99 protected: | 99 protected: |
| 100 explicit UrlFetchOperationBase(GDataOperationRegistry* registry); | 100 UrlFetchOperationBase(OperationRegistry* registry); |
| 101 UrlFetchOperationBase(GDataOperationRegistry* registry, | 101 UrlFetchOperationBase(OperationRegistry* registry, |
| 102 GDataOperationRegistry::OperationType type, | 102 OperationRegistry::OperationType type, |
| 103 const FilePath& path); | 103 const FilePath& path); |
| 104 virtual ~UrlFetchOperationBase(); | 104 virtual ~UrlFetchOperationBase(); |
| 105 | 105 |
| 106 // Gets URL for the request. | 106 // Gets URL for the request. |
| 107 virtual GURL GetURL() const = 0; | 107 virtual GURL GetURL() const = 0; |
| 108 // Returns the request type. A derived class should override this method | 108 // Returns the request type. A derived class should override this method |
| 109 // for a request type other than HTTP GET. | 109 // for a request type other than HTTP GET. |
| 110 virtual net::URLFetcher::RequestType GetRequestType() const; | 110 virtual net::URLFetcher::RequestType GetRequestType() const; |
| 111 // Returns the extra HTTP headers for the request. A derived class should | 111 // Returns the extra HTTP headers for the request. A derived class should |
| 112 // override this method to specify any extra headers needed for the request. | 112 // override this method to specify any extra headers needed for the request. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 124 // Invoked when it needs to notify the status. Chunked operations that | 124 // Invoked when it needs to notify the status. Chunked operations that |
| 125 // constructs a logically single operation from multiple physical operations | 125 // constructs a logically single operation from multiple physical operations |
| 126 // should notify resume/suspend instead of start/finish. | 126 // should notify resume/suspend instead of start/finish. |
| 127 virtual void NotifyStartToOperationRegistry(); | 127 virtual void NotifyStartToOperationRegistry(); |
| 128 virtual void NotifySuccessToOperationRegistry(); | 128 virtual void NotifySuccessToOperationRegistry(); |
| 129 | 129 |
| 130 // Invoked by this base class upon an authentication error or cancel by | 130 // Invoked by this base class upon an authentication error or cancel by |
| 131 // an user operation. Must be implemented by a derived class. | 131 // an user operation. Must be implemented by a derived class. |
| 132 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) = 0; | 132 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) = 0; |
| 133 | 133 |
| 134 // Implement GDataOperationRegistry::Operation | 134 // Implement OperationRegistry::Operation |
| 135 virtual void DoCancel() OVERRIDE; | 135 virtual void DoCancel() OVERRIDE; |
| 136 | 136 |
| 137 // Overridden from URLFetcherDelegate. | 137 // Overridden from URLFetcherDelegate. |
| 138 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 138 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 139 | 139 |
| 140 // Overridden from GDataOperationInterface. | 140 // Overridden from GDataOperationInterface. |
| 141 virtual void OnAuthFailed(GDataErrorCode code) OVERRIDE; | 141 virtual void OnAuthFailed(GDataErrorCode code) OVERRIDE; |
| 142 | 142 |
| 143 // Invoked when ProcessURLFetchResults() is completed. | 143 // Invoked when ProcessURLFetchResults() is completed. |
| 144 void OnProcessURLFetchResultsComplete(bool result); | 144 void OnProcessURLFetchResultsComplete(bool result); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 161 //============================ EntryActionOperation ============================ | 161 //============================ EntryActionOperation ============================ |
| 162 | 162 |
| 163 // Callback type for Delete/Move DocumentServiceInterface calls. | 163 // Callback type for Delete/Move DocumentServiceInterface calls. |
| 164 typedef base::Callback<void(GDataErrorCode error, | 164 typedef base::Callback<void(GDataErrorCode error, |
| 165 const GURL& document_url)> EntryActionCallback; | 165 const GURL& document_url)> EntryActionCallback; |
| 166 | 166 |
| 167 // This class performs a simple action over a given entry (document/file). | 167 // This class performs a simple action over a given entry (document/file). |
| 168 // It is meant to be used for operations that return no JSON blobs. | 168 // It is meant to be used for operations that return no JSON blobs. |
| 169 class EntryActionOperation : public UrlFetchOperationBase { | 169 class EntryActionOperation : public UrlFetchOperationBase { |
| 170 public: | 170 public: |
| 171 EntryActionOperation(GDataOperationRegistry* registry, | 171 EntryActionOperation(OperationRegistry* registry, |
| 172 const EntryActionCallback& callback, | 172 const EntryActionCallback& callback, |
| 173 const GURL& document_url); | 173 const GURL& document_url); |
| 174 virtual ~EntryActionOperation(); | 174 virtual ~EntryActionOperation(); |
| 175 | 175 |
| 176 protected: | 176 protected: |
| 177 // Overridden from UrlFetchOperationBase. | 177 // Overridden from UrlFetchOperationBase. |
| 178 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; | 178 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; |
| 179 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; | 179 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; |
| 180 | 180 |
| 181 const GURL& document_url() const { return document_url_; } | 181 const GURL& document_url() const { return document_url_; } |
| 182 | 182 |
| 183 private: | 183 private: |
| 184 EntryActionCallback callback_; | 184 EntryActionCallback callback_; |
| 185 GURL document_url_; | 185 GURL document_url_; |
| 186 | 186 |
| 187 DISALLOW_COPY_AND_ASSIGN(EntryActionOperation); | 187 DISALLOW_COPY_AND_ASSIGN(EntryActionOperation); |
| 188 }; | 188 }; |
| 189 | 189 |
| 190 //============================== GetDataOperation ============================== | 190 //============================== GetDataOperation ============================== |
| 191 | 191 |
| 192 // Callback type for DocumentServiceInterface::GetDocuments. | 192 // Callback type for DocumentServiceInterface::GetDocuments. |
| 193 // Note: feed_data argument should be passed using base::Passed(&feed_data), not | 193 // Note: feed_data argument should be passed using base::Passed(&feed_data), not |
| 194 // feed_data.Pass(). | 194 // feed_data.Pass(). |
| 195 typedef base::Callback<void(GDataErrorCode error, | 195 typedef base::Callback<void(GDataErrorCode error, |
| 196 scoped_ptr<base::Value> feed_data)> GetDataCallback; | 196 scoped_ptr<base::Value> feed_data)> GetDataCallback; |
| 197 | 197 |
| 198 // This class performs the operation for fetching and parsing JSON data content. | 198 // This class performs the operation for fetching and parsing JSON data content. |
| 199 class GetDataOperation : public UrlFetchOperationBase { | 199 class GetDataOperation : public UrlFetchOperationBase { |
| 200 public: | 200 public: |
| 201 GetDataOperation(GDataOperationRegistry* registry, | 201 GetDataOperation(OperationRegistry* registry, |
| 202 const GetDataCallback& callback); | 202 const GetDataCallback& callback); |
| 203 virtual ~GetDataOperation(); | 203 virtual ~GetDataOperation(); |
| 204 | 204 |
| 205 // Parse GData JSON response. | 205 // Parse GData JSON response. |
| 206 virtual void ParseResponse(GDataErrorCode fetch_error_code, | 206 virtual void ParseResponse(GDataErrorCode fetch_error_code, |
| 207 const std::string& data); | 207 const std::string& data); |
| 208 | 208 |
| 209 protected: | 209 protected: |
| 210 // Overridden from UrlFetchOperationBase. | 210 // Overridden from UrlFetchOperationBase. |
| 211 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; | 211 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 223 | 223 |
| 224 // Note: This should remain the last member so it'll be destroyed and | 224 // Note: This should remain the last member so it'll be destroyed and |
| 225 // invalidate its weak pointers before any other members are destroyed. | 225 // invalidate its weak pointers before any other members are destroyed. |
| 226 base::WeakPtrFactory<GetDataOperation> weak_ptr_factory_; | 226 base::WeakPtrFactory<GetDataOperation> weak_ptr_factory_; |
| 227 DISALLOW_COPY_AND_ASSIGN(GetDataOperation); | 227 DISALLOW_COPY_AND_ASSIGN(GetDataOperation); |
| 228 }; | 228 }; |
| 229 | 229 |
| 230 } // namespace gdata | 230 } // namespace gdata |
| 231 | 231 |
| 232 #endif // CHROME_BROWSER_CHROMEOS_GDATA_OPERATIONS_BASE_H_ | 232 #endif // CHROME_BROWSER_CHROMEOS_GDATA_OPERATIONS_BASE_H_ |
| OLD | NEW |