summaryrefslogtreecommitdiffstats
path: root/google_apis
diff options
context:
space:
mode:
authorhirono <hirono@chromium.org>2015-04-08 01:01:40 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-08 08:02:18 +0000
commit900d55c855dc055f82bc3db1cb313b3e8ae1781b (patch)
tree543d8a985a2028cbd703c273b59f0a95fc367665 /google_apis
parentc5c07de291701d5e055d20a2a22f7065baeabdc0 (diff)
downloadchromium_src-900d55c855dc055f82bc3db1cb313b3e8ae1781b.zip
chromium_src-900d55c855dc055f82bc3db1cb313b3e8ae1781b.tar.gz
chromium_src-900d55c855dc055f82bc3db1cb313b3e8ae1781b.tar.bz2
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}
Diffstat (limited to 'google_apis')
-rw-r--r--google_apis/drive/base_requests.cc32
-rw-r--r--google_apis/drive/base_requests.h26
2 files changed, 52 insertions, 6 deletions
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<std::string> 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<std::string> 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.