Chromium Code Reviews| 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 // This file provides base classes used to issue HTTP requests for Google | 5 // This file provides base classes used to issue HTTP requests for Google |
| 6 // APIs. | 6 // APIs. |
| 7 | 7 |
| 8 #ifndef CHROME_BROWSER_GOOGLE_APIS_BASE_REQUESTS_H_ | 8 #ifndef CHROME_BROWSER_GOOGLE_APIS_BASE_REQUESTS_H_ |
| 9 #define CHROME_BROWSER_GOOGLE_APIS_BASE_REQUESTS_H_ | 9 #define CHROME_BROWSER_GOOGLE_APIS_BASE_REQUESTS_H_ |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 | 28 |
| 29 class RequestSender; | 29 class RequestSender; |
| 30 | 30 |
| 31 // Callback used to pass parsed JSON from ParseJson(). If parsing error occurs, | 31 // Callback used to pass parsed JSON from ParseJson(). If parsing error occurs, |
| 32 // then the passed argument is null. | 32 // then the passed argument is null. |
| 33 typedef base::Callback<void(scoped_ptr<base::Value> value)> ParseJsonCallback; | 33 typedef base::Callback<void(scoped_ptr<base::Value> value)> ParseJsonCallback; |
| 34 | 34 |
| 35 // Callback used for DownloadFileRequest and ResumeUploadRequestBase. | 35 // Callback used for DownloadFileRequest and ResumeUploadRequestBase. |
| 36 typedef base::Callback<void(int64 progress, int64 total)> ProgressCallback; | 36 typedef base::Callback<void(int64 progress, int64 total)> ProgressCallback; |
| 37 | 37 |
| 38 // Parses JSON passed in |json| on blocking pool. Runs |callback| on the calling | 38 // Parses JSON passed in |json| on |blocking_task_runner|. Runs |callback| on |
| 39 // thread when finished with either success or failure. | 39 // the calling thread when finished with either success or failure. |
| 40 // The callback must not be null. | 40 // The callback must not be null. |
| 41 void ParseJson(const std::string& json, const ParseJsonCallback& callback); | 41 void ParseJson(base::TaskRunner* blocking_task_runner, |
| 42 const std::string& json, | |
| 43 const ParseJsonCallback& callback); | |
| 42 | 44 |
| 43 //======================= AuthenticatedRequestInterface ====================== | 45 //======================= AuthenticatedRequestInterface ====================== |
| 44 | 46 |
| 45 // An interface class for implementing a request which requires OAuth2 | 47 // An interface class for implementing a request which requires OAuth2 |
| 46 // authentication. | 48 // authentication. |
| 47 class AuthenticatedRequestInterface { | 49 class AuthenticatedRequestInterface { |
| 48 public: | 50 public: |
| 49 // Called when re-authentication is required. See Start() for details. | 51 // Called when re-authentication is required. See Start() for details. |
| 50 typedef base::Callback<void(AuthenticatedRequestInterface* request)> | 52 typedef base::Callback<void(AuthenticatedRequestInterface* request)> |
| 51 ReAuthenticateCallback; | 53 ReAuthenticateCallback; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 // Invoked when ProcessURLFetchResults() is completed. | 141 // Invoked when ProcessURLFetchResults() is completed. |
| 140 void OnProcessURLFetchResultsComplete(bool result); | 142 void OnProcessURLFetchResultsComplete(bool result); |
| 141 | 143 |
| 142 // Returns an appropriate GDataErrorCode based on the HTTP response code and | 144 // Returns an appropriate GDataErrorCode based on the HTTP response code and |
| 143 // the status of the URLFetcher. | 145 // the status of the URLFetcher. |
| 144 static GDataErrorCode GetErrorCode(const net::URLFetcher* source); | 146 static GDataErrorCode GetErrorCode(const net::URLFetcher* source); |
| 145 | 147 |
| 146 // Returns true if called on the thread where the constructor was called. | 148 // Returns true if called on the thread where the constructor was called. |
| 147 bool CalledOnValidThread(); | 149 bool CalledOnValidThread(); |
| 148 | 150 |
| 151 // Returns the task runner that should be used for blocking tasks. | |
| 152 base::TaskRunner* blocking_task_runner() const; | |
| 153 | |
| 149 private: | 154 private: |
| 150 // URLFetcherDelegate overrides. | 155 // URLFetcherDelegate overrides. |
| 151 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 156 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 152 | 157 |
| 153 // AuthenticatedRequestInterface overrides. | 158 // AuthenticatedRequestInterface overrides. |
| 154 virtual void OnAuthFailed(GDataErrorCode code) OVERRIDE; | 159 virtual void OnAuthFailed(GDataErrorCode code) OVERRIDE; |
| 155 | 160 |
| 156 ReAuthenticateCallback re_authenticate_callback_; | 161 ReAuthenticateCallback re_authenticate_callback_; |
| 157 int re_authenticate_count_; | 162 int re_authenticate_count_; |
| 158 scoped_ptr<net::URLFetcher> url_fetcher_; | 163 scoped_ptr<net::URLFetcher> url_fetcher_; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 // Callback type for DocumentServiceInterface::GetResourceList. | 203 // Callback type for DocumentServiceInterface::GetResourceList. |
| 199 // Note: json_data argument should be passed using base::Passed(&json_data), not | 204 // Note: json_data argument should be passed using base::Passed(&json_data), not |
| 200 // json_data.Pass(). | 205 // json_data.Pass(). |
| 201 typedef base::Callback<void(GDataErrorCode error, | 206 typedef base::Callback<void(GDataErrorCode error, |
| 202 scoped_ptr<base::Value> json_data)> GetDataCallback; | 207 scoped_ptr<base::Value> json_data)> GetDataCallback; |
| 203 | 208 |
| 204 // This class performs the request for fetching and converting the fetched | 209 // This class performs the request for fetching and converting the fetched |
| 205 // content into a base::Value. | 210 // content into a base::Value. |
| 206 class GetDataRequest : public UrlFetchRequestBase { | 211 class GetDataRequest : public UrlFetchRequestBase { |
| 207 public: | 212 public: |
| 208 // |callback| must not be null. | 213 // |callback| must not be null. |
|
satorux1
2013/07/08 01:30:07
While you are at it, could you document what |call
kinaba
2013/07/08 03:12:02
Done.
| |
| 209 GetDataRequest(RequestSender* sender, const GetDataCallback& callback); | 214 GetDataRequest(RequestSender* sender, const GetDataCallback& callback); |
| 210 virtual ~GetDataRequest(); | 215 virtual ~GetDataRequest(); |
| 211 | 216 |
| 212 // Parses JSON response. | 217 // Parses JSON response. |
| 213 void ParseResponse(GDataErrorCode fetch_error_code, const std::string& data); | 218 void ParseResponse(GDataErrorCode fetch_error_code, const std::string& data); |
| 214 | 219 |
| 215 protected: | 220 protected: |
| 216 // UrlFetchRequestBase overrides. | 221 // UrlFetchRequestBase overrides. |
| 217 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; | 222 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; |
| 218 virtual void RunCallbackOnPrematureFailure( | 223 virtual void RunCallbackOnPrematureFailure( |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 488 const ProgressCallback progress_callback_; | 493 const ProgressCallback progress_callback_; |
| 489 const GURL download_url_; | 494 const GURL download_url_; |
| 490 const base::FilePath output_file_path_; | 495 const base::FilePath output_file_path_; |
| 491 | 496 |
| 492 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequestBase); | 497 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequestBase); |
| 493 }; | 498 }; |
| 494 | 499 |
| 495 } // namespace google_apis | 500 } // namespace google_apis |
| 496 | 501 |
| 497 #endif // CHROME_BROWSER_GOOGLE_APIS_BASE_REQUESTS_H_ | 502 #endif // CHROME_BROWSER_GOOGLE_APIS_BASE_REQUESTS_H_ |
| OLD | NEW |