diff options
author | gspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-11 18:28:50 +0000 |
---|---|---|
committer | gspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-11 18:28:50 +0000 |
commit | 779f93c652dc0525ef47716eb6b8e3fd511c7b5c (patch) | |
tree | 6bb4ff7aab423c96928b46dc3eed286d12ba5f07 /chrome/browser/chromeos | |
parent | a5ea96fef6e2c20afa18c58ddd3b8aa997b460b9 (diff) | |
download | chromium_src-779f93c652dc0525ef47716eb6b8e3fd511c7b5c.zip chromium_src-779f93c652dc0525ef47716eb6b8e3fd511c7b5c.tar.gz chromium_src-779f93c652dc0525ef47716eb6b8e3fd511c7b5c.tar.bz2 |
Merge 144895 - gdata: Uploading of an empty file.
The patch
1) Drops/bypasses several DCHECKs preventing empty upload.
2) Avoids ill-formed PUT request header "Content-Range: 0--1/0" to GData API.
BUG=134552, 132968
TEST=manually tested: put an empty file on local Download folder, and copy to
Google Drive folder in the file manager by drag and drop.
Review URL: https://chromiumcodereview.appspot.com/10636053
TBR=kinaba@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10692166
git-svn-id: svn://svn.chromium.org/chrome/branches/1180/src@146152 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos')
-rw-r--r-- | chrome/browser/chromeos/gdata/gdata_file_system.cc | 8 | ||||
-rw-r--r-- | chrome/browser/chromeos/gdata/gdata_operations.cc | 13 | ||||
-rw-r--r-- | chrome/browser/chromeos/gdata/gdata_uploader.cc | 38 | ||||
-rw-r--r-- | chrome/browser/chromeos/gdata/gdata_uploader.h | 3 |
4 files changed, 45 insertions, 17 deletions
diff --git a/chrome/browser/chromeos/gdata/gdata_file_system.cc b/chrome/browser/chromeos/gdata/gdata_file_system.cc index a4061f5..ae21b46 100644 --- a/chrome/browser/chromeos/gdata/gdata_file_system.cc +++ b/chrome/browser/chromeos/gdata/gdata_file_system.cc @@ -2235,14 +2235,6 @@ void GDataFileSystem::OnGetFileCompleteForUpdateFile( } GDataFile* file = entry->AsGDataFile(); - // TODO(satorux): Uploading of empty files are currently not supported. - // crbug.com/134552 - if (file->file_info().size == 0) { - if (!callback.is_null()) - callback.Run(base::PLATFORM_FILE_ERROR_FAILED); - return; - } - uploader_->UploadExistingFile( file->upload_url(), file->GetFilePath(), diff --git a/chrome/browser/chromeos/gdata/gdata_operations.cc b/chrome/browser/chromeos/gdata/gdata_operations.cc index dcfde09..479c460 100644 --- a/chrome/browser/chromeos/gdata/gdata_operations.cc +++ b/chrome/browser/chromeos/gdata/gdata_operations.cc @@ -973,11 +973,7 @@ bool InitiateUploadOperation::GetContentData(std::string* upload_content_type, if (params_.upload_mode == UPLOAD_EXISTING_FILE) { // When uploading an existing file, the body is empty as we don't modify // the metadata. - // - // However, URLFetcher DCHECKs with an empty body with PUT request, hence - // sending "\r\n" instead. - // TODO(satorux): Remove the workaround: crbug.com/134261. - *upload_content = "\r\n"; + *upload_content = ""; // Even though the body is empty, Content-Type should be set to // "text/plain". Otherwise, the server won't accept. *upload_content_type = "text/plain"; @@ -1110,6 +1106,13 @@ URLFetcher::RequestType ResumeUploadOperation::GetRequestType() const { } std::vector<std::string> ResumeUploadOperation::GetExtraRequestHeaders() const { + if (params_.content_length == 0) { + // For uploading an empty document, just PUT an empty content. + DCHECK_EQ(params_.start_range, 0); + DCHECK_EQ(params_.end_range, -1); + return std::vector<std::string>(); + } + // The header looks like // Content-Range: bytes <start_range>-<end_range>/<content_length> // for example: diff --git a/chrome/browser/chromeos/gdata/gdata_uploader.cc b/chrome/browser/chromeos/gdata/gdata_uploader.cc index de27875..2d4df95 100644 --- a/chrome/browser/chromeos/gdata/gdata_uploader.cc +++ b/chrome/browser/chromeos/gdata/gdata_uploader.cc @@ -46,7 +46,6 @@ int GDataUploader::UploadNewFile(scoped_ptr<UploadFileInfo> upload_file_info) { DCHECK(upload_file_info.get()); DCHECK_EQ(upload_file_info->upload_id, -1); DCHECK(!upload_file_info->file_path.empty()); - DCHECK_NE(upload_file_info->file_size, 0); DCHECK(!upload_file_info->gdata_path.empty()); DCHECK(!upload_file_info->title.empty()); DCHECK(!upload_file_info->content_type.empty()); @@ -87,8 +86,9 @@ int GDataUploader::StartUploadFile( // Create a FileStream to make sure the file can be opened successfully. info->file_stream = new net::FileStream(NULL); - // Create buffer to hold upload data. - info->buf_len = std::min(info->file_size, kUploadChunkSize); + // Create buffer to hold upload data. The full file size may not be known at + // this point, so it may not be appropriate to use info->file_size. + info->buf_len = kUploadChunkSize; info->buf = new net::IOBuffer(info->buf_len); OpenFile(info); @@ -105,7 +105,6 @@ int GDataUploader::UploadExistingFile( DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(!upload_location.is_empty()); DCHECK(!local_file_path.empty()); - DCHECK_NE(file_size, 0); DCHECK(!content_type.empty()); scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo); @@ -314,6 +313,29 @@ void GDataUploader::UploadNextChunk(UploadFileInfo* upload_file_info) { return; } + if (bytes_to_read == 0) { + // This should only happen when the actual file size is 0. + DCHECK(upload_file_info->all_bytes_present && + upload_file_info->content_length == 0); + + upload_file_info->start_range = 0; + upload_file_info->end_range = -1; + // Skips file_stream->Read and error checks for 0-byte case. Immediately + // proceeds to ResumeUpload. + // TODO(kinaba): http://crbug.com/134814 + // Replace the following PostTask() to an direct method call. This is needed + // because we have to ResumeUpload after the previous InitiateUpload or + // ResumeUpload is completely finished; at this point, we are inside the + // callback function from the previous operation, which is not treated as + // finished yet. + base::MessageLoopProxy::current()->PostTask( + FROM_HERE, + base::Bind(&GDataUploader::ResumeUpload, + uploader_factory_.GetWeakPtr(), + upload_file_info->upload_id)); + return; + } + upload_file_info->file_stream->Read( upload_file_info->buf, bytes_to_read, @@ -345,6 +367,14 @@ void GDataUploader::ReadCompletionCallback( upload_file_info->end_range = upload_file_info->start_range + bytes_read - 1; + ResumeUpload(upload_id); +} + +void GDataUploader::ResumeUpload(int upload_id) { + UploadFileInfo* upload_file_info = GetUploadFileInfo(upload_id); + if (!upload_file_info) + return; + documents_service_->ResumeUpload( ResumeUploadParams(upload_file_info->upload_mode, upload_file_info->start_range, diff --git a/chrome/browser/chromeos/gdata/gdata_uploader.h b/chrome/browser/chromeos/gdata/gdata_uploader.h index 211e487..94abd47 100644 --- a/chrome/browser/chromeos/gdata/gdata_uploader.h +++ b/chrome/browser/chromeos/gdata/gdata_uploader.h @@ -111,6 +111,9 @@ class GDataUploader : public GDataUploaderInterface { int bytes_to_read, int bytes_read); + // Calls DocumentsService's ResumeUpload with the current upload info. + void ResumeUpload(int upload_id); + // DocumentsService callback for ResumeUpload. void OnResumeUploadResponseReceived(int upload_id, const ResumeUploadResponse& response, |