From 900d55c855dc055f82bc3db1cb313b3e8ae1781b Mon Sep 17 00:00:00 2001 From: hirono Date: Wed, 8 Apr 2015 01:01:40 -0700 Subject: Drive: Add BatchableRequest subclass. To generate batch request from each request instance, batachable request class must publish several methods to BatchRequestClass. BUG=451917 TEST=None Review URL: https://codereview.chromium.org/1053123004 Cr-Commit-Position: refs/heads/master@{#324197} --- google_apis/drive/base_requests.cc | 32 ++++++++++++++++++++++++++++---- google_apis/drive/base_requests.h | 26 ++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 6 deletions(-) (limited to 'google_apis') diff --git a/google_apis/drive/base_requests.cc b/google_apis/drive/base_requests.cc index b5fd262..bcd1bab 100644 --- a/google_apis/drive/base_requests.cc +++ b/google_apis/drive/base_requests.cc @@ -556,6 +556,31 @@ UrlFetchRequestBase::GetWeakPtr() { return weak_ptr_factory_.GetWeakPtr(); } +//============================ BatchableRequestBase ============================ + +net::URLFetcher::RequestType BatchableRequestBase::GetRequestType() const { + return UrlFetchRequestBase::GetRequestType(); +} + +std::vector BatchableRequestBase::GetExtraRequestHeaders() const { + return UrlFetchRequestBase::GetExtraRequestHeaders(); +} + +void BatchableRequestBase::Prepare(const PrepareCallback& callback) { + return UrlFetchRequestBase::Prepare(callback); +} + +bool BatchableRequestBase::GetContentData( + std::string* upload_content_type, std::string* upload_content) { + return UrlFetchRequestBase::GetContentData( + upload_content_type, upload_content); +} + +void BatchableRequestBase::ProcessURLFetchResults( + const net::URLFetcher* source) { + ProcessURLFetchResults(GetErrorCode(), response_writer()->data()); +} + //============================ EntryActionRequest ============================ EntryActionRequest::EntryActionRequest(RequestSender* sender, @@ -832,7 +857,7 @@ MultipartUploadRequestBase::MultipartUploadRequestBase( const base::FilePath& local_file_path, const FileResourceCallback& callback, const ProgressCallback& progress_callback) - : UrlFetchRequestBase(sender), + : BatchableRequestBase(sender), metadata_json_(metadata_json), content_type_(content_type), local_path_(local_file_path), @@ -893,13 +918,12 @@ bool MultipartUploadRequestBase::GetContentData( } void MultipartUploadRequestBase::ProcessURLFetchResults( - const URLFetcher* source) { + DriveApiErrorCode code, const std::string& body) { // The upload is successfully done. Parse the response which should be // the entry's metadata. - const DriveApiErrorCode code = GetErrorCode(); if (code == HTTP_CREATED || code == HTTP_SUCCESS) { ParseJsonOnBlockingPool( - blocking_task_runner(), response_writer()->data(), + blocking_task_runner(), body, base::Bind(&MultipartUploadRequestBase::OnDataParsed, weak_ptr_factory_.GetWeakPtr(), code)); } else { diff --git a/google_apis/drive/base_requests.h b/google_apis/drive/base_requests.h index 9c66fe6..a95d234 100644 --- a/google_apis/drive/base_requests.h +++ b/google_apis/drive/base_requests.h @@ -258,6 +258,27 @@ class UrlFetchRequestBase : public AuthenticatedRequestInterface, DISALLOW_COPY_AND_ASSIGN(UrlFetchRequestBase); }; +//============================ BatchableRequestBase ============================ + +class BatchableRequestBase : public UrlFetchRequestBase { + public: + explicit BatchableRequestBase(RequestSender* sender) : + UrlFetchRequestBase(sender) {} + + GURL GetURL() const override = 0; + net::URLFetcher::RequestType GetRequestType() const override; + std::vector GetExtraRequestHeaders() const override; + void Prepare(const PrepareCallback& callback) override; + bool GetContentData(std::string* upload_content_type, + std::string* upload_content) override; + void RunCallbackOnPrematureFailure(DriveApiErrorCode code) override = 0; + virtual void ProcessURLFetchResults( + DriveApiErrorCode code, const std::string& body) = 0; + + private: + void ProcessURLFetchResults(const net::URLFetcher* source) final; +}; + //============================ EntryActionRequest ============================ // Callback type for requests that return only error status, like: Delete/Move. @@ -475,7 +496,7 @@ class GetUploadStatusRequestBase : public UploadRangeRequestBase { // This class provides base implementation for performing the request for // uploading a file by multipart body. -class MultipartUploadRequestBase : public UrlFetchRequestBase { +class MultipartUploadRequestBase : public BatchableRequestBase { public: // Set boundary. Only tests can use this method. void SetBoundaryForTesting(const std::string& boundary); @@ -498,7 +519,8 @@ class MultipartUploadRequestBase : public UrlFetchRequestBase { void Prepare(const PrepareCallback& callback) override; bool GetContentData(std::string* upload_content_type, std::string* upload_content) override; - void ProcessURLFetchResults(const net::URLFetcher* source) override; + void ProcessURLFetchResults( + DriveApiErrorCode code, const std::string& body) override; void RunCallbackOnPrematureFailure(DriveApiErrorCode code) override; // content::UrlFetcherDelegate overrides. -- cgit v1.1