Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Unified Diff: webkit/fileapi/file_writer_delegate.cc

Issue 10986045: Flush at the end of local file writing in FileWriter API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/fileapi/file_writer_delegate.h ('k') | webkit/fileapi/local_file_stream_writer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « webkit/fileapi/file_writer_delegate.h ('k') | webkit/fileapi/local_file_stream_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698