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

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: Clean up. 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 3794eddc57e8b0ca976415a165f59379f099b60b..df97a237be5275abbc1910c9e6264ac69f3f818e 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:
@@ -187,7 +189,10 @@ void FileWriterDelegate::OnError(base::PlatformFileError error) {
request_->Cancel();
}
- write_callback_.Run(error, 0, GetCompletionStatusOnError());
+ if (writing_started_)
+ FlushForCompletion(error, 0, ERROR_WRITE_STARTED);
+ else
+ write_callback_.Run(error, 0, ERROR_WRITE_NOT_STARTED);
}
void FileWriterDelegate::OnProgress(int bytes_written, bool done) {
@@ -201,8 +206,13 @@ void FileWriterDelegate::OnProgress(int bytes_written, bool done) {
last_progress_event_time_ = currentTime;
bytes_written_backlog_ = 0;
- WriteProgressStatus status = done ? SUCCESS_COMPLETED : SUCCESS_IO_PENDING;
- write_callback_.Run(base::PLATFORM_FILE_OK, bytes_written, status);
+ if (done) {
+ FlushForCompletion(base::PLATFORM_FILE_OK, bytes_written,
+ SUCCESS_COMPLETED);
+ } else {
+ write_callback_.Run(base::PLATFORM_FILE_OK, bytes_written,
+ SUCCESS_IO_PENDING);
+ }
return;
}
bytes_written_backlog_ += bytes_written;
@@ -213,4 +223,29 @@ void FileWriterDelegate::OnWriteCancelled(int status) {
GetCompletionStatusOnError());
}
+void FileWriterDelegate::FlushForCompletion(
+ base::PlatformFileError error,
+ int bytes_written,
+ WriteProgressStatus progress_status) {
+ int 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);
+}
+
+void FileWriterDelegate::OnFlushed(base::PlatformFileError error,
+ int bytes_written,
+ WriteProgressStatus progress_status,
+ int flush_error) {
+ if (error == base::PLATFORM_FILE_OK && flush_error != net::OK) {
+ // If the Flush introduced an error, overwrite the status.
+ // Otherwise, keep the original error status.
+ error = NetErrorToPlatformFileError(flush_error);
+ progress_status = GetCompletionStatusOnError();
+ }
+ write_callback_.Run(error, bytes_written, progress_status);
+}
+
} // 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