| Index: storage/browser/fileapi/file_writer_delegate.cc
|
| diff --git a/storage/browser/fileapi/file_writer_delegate.cc b/storage/browser/fileapi/file_writer_delegate.cc
|
| index abc9976e6d5be4ece24ee745ea86ab69464fb74d..5141b66008e395c740bea86e4bc5319fc63e8e8b 100644
|
| --- a/storage/browser/fileapi/file_writer_delegate.cc
|
| +++ b/storage/browser/fileapi/file_writer_delegate.cc
|
| @@ -31,6 +31,7 @@ FileWriterDelegate::FileWriterDelegate(
|
| bytes_written_backlog_(0),
|
| bytes_written_(0),
|
| bytes_read_(0),
|
| + total_bytes_read_(0),
|
| io_buffer_(new net::IOBufferWithSize(kReadBufSize)),
|
| weak_factory_(this) {
|
| }
|
| @@ -135,7 +136,14 @@ void FileWriterDelegate::Read() {
|
|
|
| void FileWriterDelegate::OnDataReceived(int bytes_read) {
|
| bytes_read_ = bytes_read;
|
| + total_bytes_read_ += bytes_read;
|
| if (!bytes_read_) { // We're done.
|
| + if (total_bytes_read_ == 0) {
|
| + // Need to call Write (even though no data was received). This is because
|
| + // the file is created lazily upon first receipt of data, so without it
|
| + // no empty file would be created.
|
| + Write();
|
| + }
|
| OnProgress(0, true);
|
| } else {
|
| // This could easily be optimized to rotate between a pool of buffers, so
|
| @@ -234,9 +242,12 @@ void FileWriterDelegate::MaybeFlushForCompletion(
|
| // DCHECK_EQ on enum classes is not supported.
|
| DCHECK(flush_policy_ == FlushPolicy::FLUSH_ON_COMPLETION);
|
|
|
| - int flush_error = file_stream_writer_->Flush(
|
| - base::Bind(&FileWriterDelegate::OnFlushed, weak_factory_.GetWeakPtr(),
|
| - error, bytes_written, progress_status));
|
| + int flush_error = 0;
|
| + if (bytes_written) {
|
| + flush_error = file_stream_writer_->Flush(
|
| + base::Bind(&FileWriterDelegate::OnFlushed, weak_factory_.GetWeakPtr(),
|
| + error, bytes_written, progress_status));
|
| + }
|
| if (flush_error != net::ERR_IO_PENDING)
|
| OnFlushed(error, bytes_written, progress_status, flush_error);
|
| }
|
|
|