Index: webkit/browser/fileapi/copy_or_move_operation_delegate.cc |
diff --git a/webkit/browser/fileapi/copy_or_move_operation_delegate.cc b/webkit/browser/fileapi/copy_or_move_operation_delegate.cc |
index cae5a6aae993e6d02baacdc90e9f48d3bc0cc702..967b5c28f0d0cc76e199e5388dea1defdea691c3 100644 |
--- a/webkit/browser/fileapi/copy_or_move_operation_delegate.cc |
+++ b/webkit/browser/fileapi/copy_or_move_operation_delegate.cc |
@@ -20,6 +20,8 @@ |
namespace fileapi { |
+const int64 kFlushIntervalInBytes = 10 << 20; // 10MB. |
+ |
class CopyOrMoveOperationDelegate::CopyOrMoveImpl { |
public: |
virtual ~CopyOrMoveImpl() {} |
@@ -543,6 +545,7 @@ CopyOrMoveOperationDelegate::StreamCopyHelper::StreamCopyHelper( |
file_progress_callback_(file_progress_callback), |
io_buffer_(new net::IOBufferWithSize(buffer_size)), |
num_copied_bytes_(0), |
+ previous_flush_offset_(0), |
min_progress_callback_invocation_span_( |
min_progress_callback_invocation_span), |
cancel_requested_(false), |
@@ -588,7 +591,7 @@ void CopyOrMoveOperationDelegate::StreamCopyHelper::DidRead( |
if (result == 0) { |
// Here is the EOF. |
if (need_flush_) |
- Flush(callback); |
+ Flush(callback, true /* is_eof */); |
else |
callback.Run(base::PLATFORM_FILE_OK); |
return; |
@@ -640,27 +643,35 @@ void CopyOrMoveOperationDelegate::StreamCopyHelper::DidWrite( |
return; |
} |
- Read(callback); |
+ if (need_flush_ && |
+ (num_copied_bytes_ - previous_flush_offset_) > kFlushIntervalInBytes) { |
+ Flush(callback, false /* not is_eof */); |
+ } else { |
+ Read(callback); |
+ } |
} |
void CopyOrMoveOperationDelegate::StreamCopyHelper::Flush( |
- const StatusCallback& callback) { |
+ const StatusCallback& callback, bool is_eof) { |
int result = writer_->Flush( |
base::Bind(&StreamCopyHelper::DidFlush, |
- weak_factory_.GetWeakPtr(), callback)); |
+ weak_factory_.GetWeakPtr(), callback, is_eof)); |
if (result != net::ERR_IO_PENDING) |
- DidFlush(callback, result); |
+ DidFlush(callback, is_eof, result); |
} |
void CopyOrMoveOperationDelegate::StreamCopyHelper::DidFlush( |
- const StatusCallback& callback, |
- int result) { |
+ const StatusCallback& callback, bool is_eof, int result) { |
if (cancel_requested_) { |
callback.Run(base::PLATFORM_FILE_ERROR_ABORT); |
return; |
} |
- callback.Run(NetErrorToPlatformFileError(result)); |
+ previous_flush_offset_ = num_copied_bytes_; |
+ if (is_eof) |
+ callback.Run(NetErrorToPlatformFileError(result)); |
+ else |
+ Read(callback); |
} |
CopyOrMoveOperationDelegate::CopyOrMoveOperationDelegate( |