diff options
author | achuith@chromium.org <achuith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-13 02:39:03 +0000 |
---|---|---|
committer | achuith@chromium.org <achuith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-13 02:39:03 +0000 |
commit | c2e3fc490e25de1270f806f27ff89cb767a75c60 (patch) | |
tree | 656c1a616ce230c28f62f8188203b5cff55aa2f1 /chrome | |
parent | 6305e67ec597ebf2b6a9b223c2196928a7dfef03 (diff) | |
download | chromium_src-c2e3fc490e25de1270f806f27ff89cb767a75c60.zip chromium_src-c2e3fc490e25de1270f806f27ff89cb767a75c60.tar.gz chromium_src-c2e3fc490e25de1270f806f27ff89cb767a75c60.tar.bz2 |
Support for pause/resume.
BUG=chromium-os:23516
TEST=Pause a download, upload should pause. Same for resume.
Review URL: https://chromiumcodereview.appspot.com/9666047
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126315 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
4 files changed, 33 insertions, 13 deletions
diff --git a/chrome/browser/chromeos/gdata/gdata_upload_file_info.cc b/chrome/browser/chromeos/gdata/gdata_upload_file_info.cc index 7534b99..44c354e 100644 --- a/chrome/browser/chromeos/gdata/gdata_upload_file_info.cc +++ b/chrome/browser/chromeos/gdata/gdata_upload_file_info.cc @@ -15,12 +15,19 @@ UploadFileInfo::UploadFileInfo() buf_len(0), start_range(0), end_range(-1), - download_complete(false) { + download_complete(false), + upload_paused(false) { } UploadFileInfo::~UploadFileInfo() { } +int64 UploadFileInfo::SizeRemaining() const { + DCHECK(file_size > end_range); + // Note that uploaded_bytes = end_range + 1; + return file_size - end_range - 1; +} + std::string UploadFileInfo::DebugString() const { return "title=[" + title + "], file_path=[" + file_path.value() + diff --git a/chrome/browser/chromeos/gdata/gdata_upload_file_info.h b/chrome/browser/chromeos/gdata/gdata_upload_file_info.h index 6c36a5e..d2e048b 100644 --- a/chrome/browser/chromeos/gdata/gdata_upload_file_info.h +++ b/chrome/browser/chromeos/gdata/gdata_upload_file_info.h @@ -29,6 +29,9 @@ struct UploadFileInfo { UploadFileInfo(); ~UploadFileInfo(); + // Bytes left to upload. + int64 SizeRemaining() const; + // Useful for printf debugging. std::string DebugString() const; @@ -36,7 +39,7 @@ struct UploadFileInfo { // URL of physical file to be uploaded, used as main identifier in callbacks. FilePath file_path; // The path of the file to be uploaded. GURL file_url; // file: url of the file to the uploaded. - size_t file_size; // Last known size of the file. + int64 file_size; // Last known size of the file. // TODO(zelirag, achuith): Make this string16. std::string title; // Title to be used for file to be uploaded. @@ -56,7 +59,7 @@ struct UploadFileInfo { scoped_refptr<net::IOBuffer> buf; // Holds current content to be uploaded. // Size of |buf|, max is 512KB; Google Docs requires size of each upload chunk // to be a multiple of 512KB. - size_t buf_len; + int64 buf_len; // Data to be updated by caller before sending each ResumeUpload request. // Note that end_range is inclusive, so start_range=0, end_range=8 is 9 bytes. @@ -64,6 +67,7 @@ struct UploadFileInfo { int64 end_range; // End of range of contents currently stored in |buf|. bool download_complete; // Whether this file has finished downloading. + bool upload_paused; // Whether this file's upload has been paused. }; } // namespace gdata diff --git a/chrome/browser/chromeos/gdata/gdata_uploader.cc b/chrome/browser/chromeos/gdata/gdata_uploader.cc index 6fe8c6d..db7b94b 100644 --- a/chrome/browser/chromeos/gdata/gdata_uploader.cc +++ b/chrome/browser/chromeos/gdata/gdata_uploader.cc @@ -20,7 +20,7 @@ using content::BrowserThread; namespace { // Google Documents List API requires uploading in chunks of 512kB. -const size_t kUploadChunkSize = 512 * 1024; +const int64 kUploadChunkSize = 512 * 1024; } // namespace @@ -63,7 +63,7 @@ void GDataUploader::UploadFile(UploadFileInfo* upload_file_info) { } void GDataUploader::UpdateUpload(const GURL& file_url, - size_t file_size, + int64 file_size, bool download_complete) { UploadFileInfo* upload_file_info = GetUploadFileInfo(file_url); if (!upload_file_info) @@ -74,6 +74,15 @@ void GDataUploader::UpdateUpload(const GURL& file_url, << " to " << file_size; upload_file_info->file_size = file_size; upload_file_info->download_complete = download_complete; + + // Resume upload if necessary and possible. + if (upload_file_info->upload_paused && + (upload_file_info->download_complete || + upload_file_info->SizeRemaining() >= kUploadChunkSize)) { + DVLOG(1) << "Resuming upload " << upload_file_info->title; + upload_file_info->upload_paused = false; + UploadNextChunk(upload_file_info); + } } UploadFileInfo* GDataUploader::GetUploadFileInfo(const GURL& file_url) { @@ -131,6 +140,7 @@ void GDataUploader::OnUploadLocationReceived( if (code != HTTP_SUCCESS) { // TODO(achuith): Handle error codes from Google Docs server. RemovePendingUpload(upload_file_info); + NOTREACHED(); return; } @@ -148,18 +158,17 @@ void GDataUploader::UploadNextChunk(UploadFileInfo* upload_file_info) { // Determine number of bytes to read for this upload iteration, which cannot // exceed size of buf i.e. buf_len. - // Note that end_range = uploaded_bytes - 1. - const size_t size_remaining = upload_file_info->file_size - - upload_file_info->end_range - 1; - const int bytes_to_read = std::min(size_remaining, + const int bytes_to_read = std::min(upload_file_info->SizeRemaining(), upload_file_info->buf_len); // Update the content length if the file_size is known. - // TODO(achuith): Handle the case where the upload catches up to the download. if (upload_file_info->download_complete) upload_file_info->content_length = upload_file_info->file_size; - else - DCHECK(size_remaining > kUploadChunkSize); + else if (bytes_to_read < kUploadChunkSize) { + DVLOG(1) << "Paused upload " << upload_file_info->title; + upload_file_info->upload_paused = true; + return; + } upload_file_info->file_stream->Read( upload_file_info->buf, diff --git a/chrome/browser/chromeos/gdata/gdata_uploader.h b/chrome/browser/chromeos/gdata/gdata_uploader.h index bd80cd9..5fa11f2 100644 --- a/chrome/browser/chromeos/gdata/gdata_uploader.h +++ b/chrome/browser/chromeos/gdata/gdata_uploader.h @@ -31,7 +31,7 @@ class GDataUploader { // Updates size and download_completed of streaming upload. void UpdateUpload(const GURL& file_url, - size_t file_size, + int64 file_size, bool download_complete); private: |