diff options
author | kinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-12 13:37:49 +0000 |
---|---|---|
committer | kinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-12 13:37:49 +0000 |
commit | cb4b63c9add1e28ea1139131b923b8e2dde56933 (patch) | |
tree | 0ae8a7a3c66d28f131c98a80bac97e5ac3988836 /webkit/browser/fileapi | |
parent | 6d3d7cf593c6a76b2b8755dfbb8d2908d4bdc1db (diff) | |
download | chromium_src-cb4b63c9add1e28ea1139131b923b8e2dde56933.zip chromium_src-cb4b63c9add1e28ea1139131b923b8e2dde56933.tar.gz chromium_src-cb4b63c9add1e28ea1139131b923b8e2dde56933.tar.bz2 |
Flush after FileSystem API copy when necessary (case for stream-based copies).
BUG=276276
Review URL: https://codereview.chromium.org/106163013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240303 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/browser/fileapi')
-rw-r--r-- | webkit/browser/fileapi/copy_or_move_operation_delegate.cc | 31 | ||||
-rw-r--r-- | webkit/browser/fileapi/copy_or_move_operation_delegate.h | 6 |
2 files changed, 36 insertions, 1 deletions
diff --git a/webkit/browser/fileapi/copy_or_move_operation_delegate.cc b/webkit/browser/fileapi/copy_or_move_operation_delegate.cc index d83dc99..cae5a6a 100644 --- a/webkit/browser/fileapi/copy_or_move_operation_delegate.cc +++ b/webkit/browser/fileapi/copy_or_move_operation_delegate.cc @@ -440,10 +440,14 @@ class StreamCopyOrMoveImpl return; } + const bool need_flush = dest_url_.mount_option().copy_sync_option() == + fileapi::COPY_SYNC_OPTION_SYNC; + DCHECK(!copy_helper_); copy_helper_.reset( new CopyOrMoveOperationDelegate::StreamCopyHelper( reader_.Pass(), writer_.Pass(), + need_flush, kReadBufferSize, file_progress_callback_, base::TimeDelta::FromMilliseconds( @@ -528,12 +532,14 @@ class StreamCopyOrMoveImpl CopyOrMoveOperationDelegate::StreamCopyHelper::StreamCopyHelper( scoped_ptr<webkit_blob::FileStreamReader> reader, scoped_ptr<FileStreamWriter> writer, + bool need_flush, int buffer_size, const FileSystemOperation::CopyFileProgressCallback& file_progress_callback, const base::TimeDelta& min_progress_callback_invocation_span) : reader_(reader.Pass()), writer_(writer.Pass()), + need_flush_(need_flush), file_progress_callback_(file_progress_callback), io_buffer_(new net::IOBufferWithSize(buffer_size)), num_copied_bytes_(0), @@ -581,7 +587,10 @@ void CopyOrMoveOperationDelegate::StreamCopyHelper::DidRead( if (result == 0) { // Here is the EOF. - callback.Run(base::PLATFORM_FILE_OK); + if (need_flush_) + Flush(callback); + else + callback.Run(base::PLATFORM_FILE_OK); return; } @@ -634,6 +643,26 @@ void CopyOrMoveOperationDelegate::StreamCopyHelper::DidWrite( Read(callback); } +void CopyOrMoveOperationDelegate::StreamCopyHelper::Flush( + const StatusCallback& callback) { + int result = writer_->Flush( + base::Bind(&StreamCopyHelper::DidFlush, + weak_factory_.GetWeakPtr(), callback)); + if (result != net::ERR_IO_PENDING) + DidFlush(callback, result); +} + +void CopyOrMoveOperationDelegate::StreamCopyHelper::DidFlush( + const StatusCallback& callback, + int result) { + if (cancel_requested_) { + callback.Run(base::PLATFORM_FILE_ERROR_ABORT); + return; + } + + callback.Run(NetErrorToPlatformFileError(result)); +} + CopyOrMoveOperationDelegate::CopyOrMoveOperationDelegate( FileSystemContext* file_system_context, const FileSystemURL& src_root, diff --git a/webkit/browser/fileapi/copy_or_move_operation_delegate.h b/webkit/browser/fileapi/copy_or_move_operation_delegate.h index 3d45a41..3ab58c8 100644 --- a/webkit/browser/fileapi/copy_or_move_operation_delegate.h +++ b/webkit/browser/fileapi/copy_or_move_operation_delegate.h @@ -48,6 +48,7 @@ class CopyOrMoveOperationDelegate StreamCopyHelper( scoped_ptr<webkit_blob::FileStreamReader> reader, scoped_ptr<FileStreamWriter> writer, + bool need_flush, int buffer_size, const FileSystemOperation::CopyFileProgressCallback& file_progress_callback, @@ -71,8 +72,13 @@ class CopyOrMoveOperationDelegate void DidWrite(const StatusCallback& callback, scoped_refptr<net::DrainableIOBuffer> buffer, int result); + // Flushes the written content in |writer_|. + void Flush(const StatusCallback& callback); + void DidFlush(const StatusCallback& callback, int result); + scoped_ptr<webkit_blob::FileStreamReader> reader_; scoped_ptr<FileStreamWriter> writer_; + const bool need_flush_; FileSystemOperation::CopyFileProgressCallback file_progress_callback_; scoped_refptr<net::IOBufferWithSize> io_buffer_; int64 num_copied_bytes_; |