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 GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_ | 8 #ifndef GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_ |
9 #define GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_ | 9 #define GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_ |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "url/gurl.h" | 22 #include "url/gurl.h" |
23 | 23 |
24 namespace base { | 24 namespace base { |
25 class Value; | 25 class Value; |
26 } // namespace base | 26 } // namespace base |
27 | 27 |
28 namespace google_apis { | 28 namespace google_apis { |
29 | 29 |
30 class RequestSender; | 30 class RequestSender; |
31 | 31 |
| 32 // Callback used to pass parsed JSON from ParseJson(). If parsing error occurs, |
| 33 // then the passed argument is null. |
| 34 typedef base::Callback<void(scoped_ptr<base::Value> value)> ParseJsonCallback; |
| 35 |
32 // Callback used for DownloadFileRequest and ResumeUploadRequestBase. | 36 // Callback used for DownloadFileRequest and ResumeUploadRequestBase. |
33 typedef base::Callback<void(int64 progress, int64 total)> ProgressCallback; | 37 typedef base::Callback<void(int64 progress, int64 total)> ProgressCallback; |
34 | 38 |
35 // Callback used to get the content from DownloadFileRequest. | 39 // Callback used to get the content from DownloadFileRequest. |
36 typedef base::Callback<void( | 40 typedef base::Callback<void( |
37 GDataErrorCode error, | 41 GDataErrorCode error, |
38 scoped_ptr<std::string> content)> GetContentCallback; | 42 scoped_ptr<std::string> content)> GetContentCallback; |
39 | 43 |
40 // Parses JSON passed in |json|. Returns NULL on failure. | 44 // Parses JSON passed in |json| on |blocking_task_runner|. Runs |callback| on |
41 scoped_ptr<base::Value> ParseJson(const std::string& json); | 45 // the calling thread when finished with either success or failure. |
| 46 // The callback must not be null. |
| 47 void ParseJson(base::TaskRunner* blocking_task_runner, |
| 48 const std::string& json, |
| 49 const ParseJsonCallback& callback); |
42 | 50 |
43 //======================= AuthenticatedRequestInterface ====================== | 51 //======================= AuthenticatedRequestInterface ====================== |
44 | 52 |
45 // An interface class for implementing a request which requires OAuth2 | 53 // An interface class for implementing a request which requires OAuth2 |
46 // authentication. | 54 // authentication. |
47 class AuthenticatedRequestInterface { | 55 class AuthenticatedRequestInterface { |
48 public: | 56 public: |
49 // Called when re-authentication is required. See Start() for details. | 57 // Called when re-authentication is required. See Start() for details. |
50 typedef base::Callback<void(AuthenticatedRequestInterface* request)> | 58 typedef base::Callback<void(AuthenticatedRequestInterface* request)> |
51 ReAuthenticateCallback; | 59 ReAuthenticateCallback; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 // Overridden from UrlFetchRequestBase. | 242 // Overridden from UrlFetchRequestBase. |
235 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; | 243 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; |
236 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; | 244 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; |
237 | 245 |
238 private: | 246 private: |
239 const EntryActionCallback callback_; | 247 const EntryActionCallback callback_; |
240 | 248 |
241 DISALLOW_COPY_AND_ASSIGN(EntryActionRequest); | 249 DISALLOW_COPY_AND_ASSIGN(EntryActionRequest); |
242 }; | 250 }; |
243 | 251 |
| 252 //============================== GetDataRequest ============================== |
| 253 |
| 254 // Callback type for requests that returns JSON data. |
| 255 typedef base::Callback<void(GDataErrorCode error, |
| 256 scoped_ptr<base::Value> json_data)> GetDataCallback; |
| 257 |
| 258 // This class performs the request for fetching and converting the fetched |
| 259 // content into a base::Value. |
| 260 class GetDataRequest : public UrlFetchRequestBase { |
| 261 public: |
| 262 // |callback| is called when the request finishes either by success or by |
| 263 // failure. On success, a JSON Value object is passed. It must not be null. |
| 264 GetDataRequest(RequestSender* sender, const GetDataCallback& callback); |
| 265 virtual ~GetDataRequest(); |
| 266 |
| 267 protected: |
| 268 // UrlFetchRequestBase overrides. |
| 269 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; |
| 270 virtual void RunCallbackOnPrematureFailure( |
| 271 GDataErrorCode fetch_error_code) OVERRIDE; |
| 272 |
| 273 private: |
| 274 // Parses JSON response. |
| 275 void ParseResponse(GDataErrorCode fetch_error_code, const std::string& data); |
| 276 |
| 277 // Called when ParseJsonOnBlockingPool() is completed. |
| 278 void OnDataParsed(GDataErrorCode fetch_error_code, |
| 279 scoped_ptr<base::Value> value); |
| 280 |
| 281 const GetDataCallback callback_; |
| 282 |
| 283 // Note: This should remain the last member so it'll be destroyed and |
| 284 // invalidate its weak pointers before any other members are destroyed. |
| 285 base::WeakPtrFactory<GetDataRequest> weak_ptr_factory_; |
| 286 |
| 287 DISALLOW_COPY_AND_ASSIGN(GetDataRequest); |
| 288 }; |
| 289 |
| 290 |
244 //=========================== InitiateUploadRequestBase======================= | 291 //=========================== InitiateUploadRequestBase======================= |
245 | 292 |
246 // Callback type for DriveServiceInterface::InitiateUpload. | 293 // Callback type for DriveServiceInterface::InitiateUpload. |
247 typedef base::Callback<void(GDataErrorCode error, | 294 typedef base::Callback<void(GDataErrorCode error, |
248 const GURL& upload_url)> InitiateUploadCallback; | 295 const GURL& upload_url)> InitiateUploadCallback; |
249 | 296 |
250 // This class provides base implementation for performing the request for | 297 // This class provides base implementation for performing the request for |
251 // initiating the upload of a file. | 298 // initiating the upload of a file. |
252 // |callback| will be called with the obtained upload URL. The URL will be | 299 // |callback| will be called with the obtained upload URL. The URL will be |
253 // used with requests for resuming the file uploading. | 300 // used with requests for resuming the file uploading. |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 const ProgressCallback progress_callback_; | 530 const ProgressCallback progress_callback_; |
484 const GURL download_url_; | 531 const GURL download_url_; |
485 const base::FilePath output_file_path_; | 532 const base::FilePath output_file_path_; |
486 | 533 |
487 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequestBase); | 534 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequestBase); |
488 }; | 535 }; |
489 | 536 |
490 } // namespace google_apis | 537 } // namespace google_apis |
491 | 538 |
492 #endif // GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_ | 539 #endif // GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_ |
OLD | NEW |