Chromium Code Reviews| Index: webkit/fileapi/file_writer_delegate.cc |
| diff --git a/webkit/fileapi/file_writer_delegate.cc b/webkit/fileapi/file_writer_delegate.cc |
| index 98dbaabecf839daa6626a88dadb436063a9ad832..c1ed40369bceccc68bea2c13819166e598a5be97 100644 |
| --- a/webkit/fileapi/file_writer_delegate.cc |
| +++ b/webkit/fileapi/file_writer_delegate.cc |
| @@ -24,6 +24,8 @@ namespace { |
| base::PlatformFileError NetErrorToPlatformFileError(int error) { |
| // TODO(kinuko): Move this static method to more convenient place. |
| switch (error) { |
| + case net::OK: |
| + return base::PLATFORM_FILE_OK; |
| case net::ERR_FILE_NO_SPACE: |
| return base::PLATFORM_FILE_ERROR_NO_SPACE; |
| case net::ERR_FILE_NOT_FOUND: |
| @@ -193,8 +195,19 @@ void FileWriterDelegate::OnProgress(int bytes_written, bool done) { |
| bytes_written += bytes_written_backlog_; |
| last_progress_event_time_ = currentTime; |
| bytes_written_backlog_ = 0; |
| - write_callback_.Run( |
| - base::PLATFORM_FILE_OK, bytes_written, done); |
| + if (done) { |
| + // All write operation completed, be sure to flush the data. |
| + int result = file_stream_writer_->Flush( |
| + base::Bind(&FileWriterDelegate::OnSuccessfulCompletion, |
| + weak_factory_.GetWeakPtr(), |
| + bytes_written)); |
| + if (result != net::ERR_IO_PENDING) { |
| + write_callback_.Run(NetErrorToPlatformFileError(result), |
| + bytes_written, done); |
| + } |
| + } else { |
| + write_callback_.Run(base::PLATFORM_FILE_OK, bytes_written, done); |
| + } |
|
kinuko
2012/09/26 08:34:08
Do we need to do this when error has happend after
kinaba
2012/09/28 11:15:25
Thanks. I rebased this CL on top of it.
I've also
|
| return; |
| } |
| bytes_written_backlog_ += bytes_written; |
| @@ -204,4 +217,8 @@ void FileWriterDelegate::OnWriteCancelled(int status) { |
| write_callback_.Run(base::PLATFORM_FILE_ERROR_ABORT, 0, true); |
| } |
| +void FileWriterDelegate::OnSuccessfulCompletion(int bytes_written, int status) { |
| + write_callback_.Run(NetErrorToPlatformFileError(status), bytes_written, true); |
| +} |
| + |
| } // namespace fileapi |