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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 | 251 |
252 base::ThreadChecker thread_checker_; | 252 base::ThreadChecker thread_checker_; |
253 | 253 |
254 // Note: This should remain the last member so it'll be destroyed and | 254 // Note: This should remain the last member so it'll be destroyed and |
255 // invalidate its weak pointers before any other members are destroyed. | 255 // invalidate its weak pointers before any other members are destroyed. |
256 base::WeakPtrFactory<UrlFetchRequestBase> weak_ptr_factory_; | 256 base::WeakPtrFactory<UrlFetchRequestBase> weak_ptr_factory_; |
257 | 257 |
258 DISALLOW_COPY_AND_ASSIGN(UrlFetchRequestBase); | 258 DISALLOW_COPY_AND_ASSIGN(UrlFetchRequestBase); |
259 }; | 259 }; |
260 | 260 |
| 261 //============================ BatchableRequestBase ============================ |
| 262 |
| 263 class BatchableRequestBase : public UrlFetchRequestBase { |
| 264 public: |
| 265 explicit BatchableRequestBase(RequestSender* sender) : |
| 266 UrlFetchRequestBase(sender) {} |
| 267 |
| 268 GURL GetURL() const override = 0; |
| 269 net::URLFetcher::RequestType GetRequestType() const override; |
| 270 std::vector<std::string> GetExtraRequestHeaders() const override; |
| 271 void Prepare(const PrepareCallback& callback) override; |
| 272 bool GetContentData(std::string* upload_content_type, |
| 273 std::string* upload_content) override; |
| 274 void RunCallbackOnPrematureFailure(DriveApiErrorCode code) override = 0; |
| 275 virtual void ProcessURLFetchResults( |
| 276 DriveApiErrorCode code, const std::string& body) = 0; |
| 277 |
| 278 private: |
| 279 void ProcessURLFetchResults(const net::URLFetcher* source) final; |
| 280 }; |
| 281 |
261 //============================ EntryActionRequest ============================ | 282 //============================ EntryActionRequest ============================ |
262 | 283 |
263 // Callback type for requests that return only error status, like: Delete/Move. | 284 // Callback type for requests that return only error status, like: Delete/Move. |
264 typedef base::Callback<void(DriveApiErrorCode error)> EntryActionCallback; | 285 typedef base::Callback<void(DriveApiErrorCode error)> EntryActionCallback; |
265 | 286 |
266 // This class performs a simple action over a given entry (document/file). | 287 // This class performs a simple action over a given entry (document/file). |
267 // It is meant to be used for requests that return no JSON blobs. | 288 // It is meant to be used for requests that return no JSON blobs. |
268 class EntryActionRequest : public UrlFetchRequestBase { | 289 class EntryActionRequest : public UrlFetchRequestBase { |
269 public: | 290 public: |
270 // |callback| is called when the request is finished either by success or by | 291 // |callback| is called when the request is finished either by success or by |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 private: | 489 private: |
469 const int64 content_length_; | 490 const int64 content_length_; |
470 | 491 |
471 DISALLOW_COPY_AND_ASSIGN(GetUploadStatusRequestBase); | 492 DISALLOW_COPY_AND_ASSIGN(GetUploadStatusRequestBase); |
472 }; | 493 }; |
473 | 494 |
474 //=========================== MultipartUploadRequestBase======================= | 495 //=========================== MultipartUploadRequestBase======================= |
475 | 496 |
476 // This class provides base implementation for performing the request for | 497 // This class provides base implementation for performing the request for |
477 // uploading a file by multipart body. | 498 // uploading a file by multipart body. |
478 class MultipartUploadRequestBase : public UrlFetchRequestBase { | 499 class MultipartUploadRequestBase : public BatchableRequestBase { |
479 public: | 500 public: |
480 // Set boundary. Only tests can use this method. | 501 // Set boundary. Only tests can use this method. |
481 void SetBoundaryForTesting(const std::string& boundary); | 502 void SetBoundaryForTesting(const std::string& boundary); |
482 | 503 |
483 protected: | 504 protected: |
484 // |callback| will be called with the file resource.upload URL. | 505 // |callback| will be called with the file resource.upload URL. |
485 // |content_type| and |content_length| should be the attributes of the | 506 // |content_type| and |content_length| should be the attributes of the |
486 // uploading file. Other parameters are optional and can be empty or null | 507 // uploading file. Other parameters are optional and can be empty or null |
487 // depending on Upload URL provided by the subclasses. | 508 // depending on Upload URL provided by the subclasses. |
488 MultipartUploadRequestBase(RequestSender* sender, | 509 MultipartUploadRequestBase(RequestSender* sender, |
489 const std::string& metadata_json, | 510 const std::string& metadata_json, |
490 const std::string& content_type, | 511 const std::string& content_type, |
491 int64 content_length, | 512 int64 content_length, |
492 const base::FilePath& local_file_path, | 513 const base::FilePath& local_file_path, |
493 const FileResourceCallback& callback, | 514 const FileResourceCallback& callback, |
494 const ProgressCallback& progress_callback); | 515 const ProgressCallback& progress_callback); |
495 ~MultipartUploadRequestBase() override; | 516 ~MultipartUploadRequestBase() override; |
496 | 517 |
497 // Overridden from UrlFetchRequestBase. | 518 // Overridden from UrlFetchRequestBase. |
498 void Prepare(const PrepareCallback& callback) override; | 519 void Prepare(const PrepareCallback& callback) override; |
499 bool GetContentData(std::string* upload_content_type, | 520 bool GetContentData(std::string* upload_content_type, |
500 std::string* upload_content) override; | 521 std::string* upload_content) override; |
501 void ProcessURLFetchResults(const net::URLFetcher* source) override; | 522 void ProcessURLFetchResults( |
| 523 DriveApiErrorCode code, const std::string& body) override; |
502 void RunCallbackOnPrematureFailure(DriveApiErrorCode code) override; | 524 void RunCallbackOnPrematureFailure(DriveApiErrorCode code) override; |
503 | 525 |
504 // content::UrlFetcherDelegate overrides. | 526 // content::UrlFetcherDelegate overrides. |
505 void OnURLFetchUploadProgress(const net::URLFetcher* source, | 527 void OnURLFetchUploadProgress(const net::URLFetcher* source, |
506 int64 current, | 528 int64 current, |
507 int64 total) override; | 529 int64 total) override; |
508 | 530 |
509 // Parses the response value and invokes |callback_| with |FileResource|. | 531 // Parses the response value and invokes |callback_| with |FileResource|. |
510 void OnDataParsed(DriveApiErrorCode code, scoped_ptr<base::Value> value); | 532 void OnDataParsed(DriveApiErrorCode code, scoped_ptr<base::Value> value); |
511 | 533 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 const ProgressCallback progress_callback_; | 614 const ProgressCallback progress_callback_; |
593 const GURL download_url_; | 615 const GURL download_url_; |
594 const base::FilePath output_file_path_; | 616 const base::FilePath output_file_path_; |
595 | 617 |
596 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequestBase); | 618 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequestBase); |
597 }; | 619 }; |
598 | 620 |
599 } // namespace google_apis | 621 } // namespace google_apis |
600 | 622 |
601 #endif // GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_ | 623 #endif // GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_ |
OLD | NEW |