diff options
-rw-r--r-- | chrome/browser/drive/drive_api_service.cc | 15 | ||||
-rw-r--r-- | google_apis/drive/drive_api_requests.cc | 91 | ||||
-rw-r--r-- | google_apis/drive/drive_api_requests.h | 71 |
3 files changed, 173 insertions, 4 deletions
diff --git a/chrome/browser/drive/drive_api_service.cc b/chrome/browser/drive/drive_api_service.cc index 9180594..c3df4b6 100644 --- a/chrome/browser/drive/drive_api_service.cc +++ b/chrome/browser/drive/drive_api_service.cc @@ -645,8 +645,11 @@ CancelCallback DriveAPIService::MultipartUploadNewFile( DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(!callback.is_null()); - NOTIMPLEMENTED(); - return CancelCallback(); + return sender_->StartRequestWithRetry( + new google_apis::drive::MultipartUploadNewFileRequest( + sender_.get(), title, parent_resource_id, content_type, + content_length, options.modified_date, options.last_viewed_by_me_date, + local_file_path, url_generator_, callback, progress_callback)); } CancelCallback DriveAPIService::MultipartUploadExistingFile( @@ -660,8 +663,12 @@ CancelCallback DriveAPIService::MultipartUploadExistingFile( DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(!callback.is_null()); - NOTIMPLEMENTED(); - return CancelCallback(); + return sender_->StartRequestWithRetry( + new google_apis::drive::MultipartUploadExistingFileRequest( + sender_.get(), options.title, resource_id, options.parent_resource_id, + content_type, content_length, options.modified_date, + options.last_viewed_by_me_date, local_file_path, options.etag, + url_generator_, callback, progress_callback)); } CancelCallback DriveAPIService::AuthorizeApp( 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. |