summaryrefslogtreecommitdiffstats
path: root/net/base
diff options
context:
space:
mode:
authordhg@chromium.org <dhg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-10 22:36:38 +0000
committerdhg@chromium.org <dhg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-10 22:36:38 +0000
commitb2a3a25224f1e0cbc9ab77ea8b5f098d494c6c18 (patch)
tree6a085883d6c9c048efa1f72b9189bc3a6b4498ce /net/base
parent4fbaaee2b26f3edb0fc68a9b330f70e09d1f749d (diff)
downloadchromium_src-b2a3a25224f1e0cbc9ab77ea8b5f098d494c6c18.zip
chromium_src-b2a3a25224f1e0cbc9ab77ea8b5f098d494c6c18.tar.gz
chromium_src-b2a3a25224f1e0cbc9ab77ea8b5f098d494c6c18.tar.bz2
Adding flushing of files on chromeos, so that when something is downloaded, its written out ot disk shortly after finish downloading.
BUG=chromium-os:2661 TEST=none Review URL: http://codereview.chromium.org/2770002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49461 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r--net/base/file_stream.h9
-rw-r--r--net/base/file_stream_posix.cc17
-rw-r--r--net/base/file_stream_win.cc15
3 files changed, 41 insertions, 0 deletions
diff --git a/net/base/file_stream.h b/net/base/file_stream.h
index ff9e7a6..a6d5739 100644
--- a/net/base/file_stream.h
+++ b/net/base/file_stream.h
@@ -120,6 +120,15 @@ class FileStream {
// platform with this call.
int64 Truncate(int64 bytes);
+ // Forces out a filesystem sync on this file to make sure that the file was
+ // written out to disk and is not currently sitting in the buffer. This does
+ // not have to be called, it just forces one to happen at the time of
+ // calling.
+ //
+ /// Returns an error code if the operation could not be performed.
+ //
+ // This method should not be called if the stream was opened READ_ONLY.
+ int Flush();
private:
class AsyncContext;
friend class AsyncContext;
diff --git a/net/base/file_stream_posix.cc b/net/base/file_stream_posix.cc
index 8a0f2e3..2036260 100644
--- a/net/base/file_stream_posix.cc
+++ b/net/base/file_stream_posix.cc
@@ -70,6 +70,16 @@ int WriteFile(base::PlatformFile file, const char* buf, int buf_len) {
return res;
}
+// FlushFile() is a simple wrapper around fsync() that handles EINTR signals and
+// calls MapErrorCode() to map errno to net error codes. It tries to flush to
+// completion.
+int FlushFile(base::PlatformFile file) {
+ ssize_t res = HANDLE_EINTR(fsync(file));
+ if (res == -1)
+ return MapErrorCode(errno);
+ return res;
+}
+
// BackgroundReadTask is a simple task that reads a file and then runs
// |callback|. AsyncContext will post this task to the WorkerPool.
class BackgroundReadTask : public Task {
@@ -445,6 +455,13 @@ int FileStream::Write(
}
}
+int FileStream::Flush() {
+ if (!IsOpen())
+ return ERR_UNEXPECTED;
+
+ return FlushFile(file_);
+}
+
int64 FileStream::Truncate(int64 bytes) {
if (!IsOpen())
return ERR_UNEXPECTED;
diff --git a/net/base/file_stream_win.cc b/net/base/file_stream_win.cc
index 6a6db90..8b7f090 100644
--- a/net/base/file_stream_win.cc
+++ b/net/base/file_stream_win.cc
@@ -302,6 +302,21 @@ int FileStream::Write(
return rv;
}
+int FileStream::Flush() {
+ if (!IsOpen())
+ return ERR_UNEXPECTED;
+
+ DCHECK(open_flags_ & base::PLATFORM_FILE_WRITE);
+ if (FlushFileBuffers(file_)) {
+ return OK;
+ }
+
+ int rv;
+ DWORD error = GetLastError();
+ rv = MapErrorCode(error);
+ return rv;
+}
+
int64 FileStream::Truncate(int64 bytes) {
if (!IsOpen())
return ERR_UNEXPECTED;