diff options
author | hirono <hirono@chromium.org> | 2015-01-07 19:42:43 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-08 03:43:29 +0000 |
commit | d0621e592ade387f7e51ad360bb745c3a4f5bfa4 (patch) | |
tree | cd8ebcb2739ad214c49c23c64baaafc947a77fa7 /google_apis | |
parent | 53681badd6b3c87997baf9faba0a58a8c797ff6b (diff) | |
download | chromium_src-d0621e592ade387f7e51ad360bb745c3a4f5bfa4.zip chromium_src-d0621e592ade387f7e51ad360bb745c3a4f5bfa4.tar.gz chromium_src-d0621e592ade387f7e51ad360bb745c3a4f5bfa4.tar.bz2 |
DriveAPI: Add two request classes inheriting MultipartUploadRequestBase for multipart uploading.
* MultipartUploadNewFileRequest
* MultipartUploadExistingFileRequest
BUG=269922
TEST=None
Review URL: https://codereview.chromium.org/811453003
Cr-Commit-Position: refs/heads/master@{#310450}
Diffstat (limited to 'google_apis')
-rw-r--r-- | google_apis/drive/drive_api_requests.cc | 91 | ||||
-rw-r--r-- | google_apis/drive/drive_api_requests.h | 71 |
2 files changed, 162 insertions, 0 deletions
diff --git a/google_apis/drive/drive_api_requests.cc b/google_apis/drive/drive_api_requests.cc index d734125d..431f5ab 100644 --- a/google_apis/drive/drive_api_requests.cc +++ b/google_apis/drive/drive_api_requests.cc @@ -702,6 +702,97 @@ void GetUploadStatusRequest::OnRangeRequestComplete( ParseFileResourceWithUploadRangeAndRun(callback_, response, value.Pass()); } +//======================= MultipartUploadNewFileRequest ======================= + +MultipartUploadNewFileRequest::MultipartUploadNewFileRequest( + RequestSender* sender, + const std::string& title, + const std::string& parent_resource_id, + const std::string& content_type, + int64 content_length, + const base::Time& modified_date, + const base::Time& last_viewed_by_me_date, + const base::FilePath& local_file_path, + const DriveApiUrlGenerator& url_generator, + const FileResourceCallback& callback, + const ProgressCallback& progress_callback) + : MultipartUploadRequestBase(sender, + title, + parent_resource_id, + content_type, + content_length, + modified_date, + last_viewed_by_me_date, + local_file_path, + callback, + progress_callback), + url_generator_(url_generator) { +} + +MultipartUploadNewFileRequest::~MultipartUploadNewFileRequest() { +} + +GURL MultipartUploadNewFileRequest::GetURL() const { + return url_generator_.GetMultipartUploadNewFileUrl(has_modified_date()); +} + +net::URLFetcher::RequestType MultipartUploadNewFileRequest::GetRequestType() + const { + return net::URLFetcher::POST; +} + +//======================= MultipartUploadExistingFileRequest =================== + +MultipartUploadExistingFileRequest::MultipartUploadExistingFileRequest( + RequestSender* sender, + const std::string& title, + const std::string& resource_id, + const std::string& parent_resource_id, + const std::string& content_type, + int64 content_length, + const base::Time& modified_date, + const base::Time& last_viewed_by_me_date, + const base::FilePath& local_file_path, + const std::string& etag, + const DriveApiUrlGenerator& url_generator, + const FileResourceCallback& callback, + const ProgressCallback& progress_callback) + : MultipartUploadRequestBase(sender, + title, + parent_resource_id, + content_type, + content_length, + modified_date, + last_viewed_by_me_date, + local_file_path, + callback, + progress_callback), + resource_id_(resource_id), + etag_(etag), + url_generator_(url_generator) { +} + +MultipartUploadExistingFileRequest::~MultipartUploadExistingFileRequest() { +} + +std::vector<std::string> +MultipartUploadExistingFileRequest::GetExtraRequestHeaders() const { + std::vector<std::string> headers( + MultipartUploadRequestBase::GetExtraRequestHeaders()); + headers.push_back(util::GenerateIfMatchHeader(etag_)); + return headers; +} + +GURL MultipartUploadExistingFileRequest::GetURL() const { + return url_generator_.GetMultipartUploadExistingFileUrl( + resource_id_, has_modified_date()); +} + +net::URLFetcher::RequestType +MultipartUploadExistingFileRequest::GetRequestType() const { + return net::URLFetcher::PUT; +} + //========================== DownloadFileRequest ========================== DownloadFileRequest::DownloadFileRequest( diff --git a/google_apis/drive/drive_api_requests.h b/google_apis/drive/drive_api_requests.h index 951c4e7..5ebb047 100644 --- a/google_apis/drive/drive_api_requests.h +++ b/google_apis/drive/drive_api_requests.h @@ -888,6 +888,77 @@ class GetUploadStatusRequest : public GetUploadStatusRequestBase { DISALLOW_COPY_AND_ASSIGN(GetUploadStatusRequest); }; +//======================= MultipartUploadNewFileRequest ======================= + +// This class performs the request for initiating the upload of a new file. +class MultipartUploadNewFileRequest : public MultipartUploadRequestBase { + public: + // |parent_resource_id| should be the resource id of the parent directory. + // |title| should be set. + // See also the comments of MultipartUploadRequestBase for more details + // about the other parameters. + MultipartUploadNewFileRequest(RequestSender* sender, + const std::string& title, + const std::string& parent_resource_id, + const std::string& content_type, + int64 content_length, + const base::Time& modified_date, + const base::Time& last_viewed_by_me_date, + const base::FilePath& local_file_path, + const DriveApiUrlGenerator& url_generator, + const FileResourceCallback& callback, + const ProgressCallback& progress_callback); + ~MultipartUploadNewFileRequest() override; + + protected: + // UrlFetchRequestBase overrides. + GURL GetURL() const override; + net::URLFetcher::RequestType GetRequestType() const override; + + private: + const DriveApiUrlGenerator url_generator_; + + DISALLOW_COPY_AND_ASSIGN(MultipartUploadNewFileRequest); +}; + +//======================= MultipartUploadExistingFileRequest =================== + +// This class performs the request for initiating the upload of a new file. +class MultipartUploadExistingFileRequest : public MultipartUploadRequestBase { + public: + // |parent_resource_id| should be the resource id of the parent directory. + // |title| should be set. + // See also the comments of MultipartUploadRequestBase for more details + // about the other parameters. + MultipartUploadExistingFileRequest(RequestSender* sender, + const std::string& title, + const std::string& resource_id, + const std::string& parent_resource_id, + const std::string& content_type, + int64 content_length, + const base::Time& modified_date, + const base::Time& last_viewed_by_me_date, + const base::FilePath& local_file_path, + const std::string& etag, + const DriveApiUrlGenerator& url_generator, + const FileResourceCallback& callback, + const ProgressCallback& progress_callback); + ~MultipartUploadExistingFileRequest() override; + + protected: + // UrlFetchRequestBase overrides. + std::vector<std::string> GetExtraRequestHeaders() const override; + GURL GetURL() const override; + net::URLFetcher::RequestType GetRequestType() const override; + + private: + const std::string resource_id_; + const std::string etag_; + const DriveApiUrlGenerator url_generator_; + + DISALLOW_COPY_AND_ASSIGN(MultipartUploadExistingFileRequest); +}; + //========================== DownloadFileRequest ========================== // This class performs the request for downloading of a specified file. |