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

Unified Diff: net/base/file_stream_posix.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 | « net/base/file_stream_posix.h ('k') | net/base/file_stream_win.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/file_stream_posix.cc
diff --git a/net/base/file_stream_posix.cc b/net/base/file_stream_posix.cc
index 0cbd0bdc794a9922829825772779b08d0ff1da0a..5613fe3a11ec79cbb3f9f7bff7f503e439968cdc 100644
--- a/net/base/file_stream_posix.cc
+++ b/net/base/file_stream_posix.cc
@@ -231,6 +231,16 @@ int FlushFile(base::PlatformFile file,
return res;
}
+// Flushes a file using FlushFile() and signals the completion.
+void FlushFileAndSignal(base::PlatformFile file,
+ int* result,
+ bool record_uma,
+ base::WaitableEvent* on_io_complete,
+ const net::BoundNetLog& bound_net_log) {
+ *result = FlushFile(file, record_uma, bound_net_log);
+ on_io_complete->Signal();
+}
+
// Called when Read(), Write() or Seek() is completed.
// |result| contains the result or a network error code.
template <typename R>
@@ -588,7 +598,32 @@ int64 FileStreamPosix::Truncate(int64 bytes) {
bound_net_log_);
}
-int FileStreamPosix::Flush() {
+int FileStreamPosix::Flush(const CompletionCallback& callback) {
+ if (!IsOpen())
+ return ERR_UNEXPECTED;
+
+ // Make sure we're async and we have no other in-flight async operations.
+ DCHECK(open_flags_ & base::PLATFORM_FILE_ASYNC);
+ DCHECK(!weak_ptr_factory_.HasWeakPtrs());
+ DCHECK(!on_io_complete_.get());
+
+ on_io_complete_.reset(new base::WaitableEvent(
+ false /* manual_reset */, false /* initially_signaled */));
+
+ int* result = new int(OK);
+ const bool posted = base::WorkerPool::PostTaskAndReply(
+ FROM_HERE,
+ base::Bind(&FlushFileAndSignal, file_, result,
+ record_uma_, on_io_complete_.get(), bound_net_log_),
+ base::Bind(&OnIOComplete<int>,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback, base::Owned(result)),
+ true /* task is slow */);
+ DCHECK(posted);
+ return ERR_IO_PENDING;
+}
+
+int FileStreamPosix::FlushSync() {
if (!IsOpen())
return ERR_UNEXPECTED;
« no previous file with comments | « net/base/file_stream_posix.h ('k') | net/base/file_stream_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698