diff options
author | dhg@chromium.org <dhg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-10 22:36:38 +0000 |
---|---|---|
committer | dhg@chromium.org <dhg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-10 22:36:38 +0000 |
commit | b2a3a25224f1e0cbc9ab77ea8b5f098d494c6c18 (patch) | |
tree | 6a085883d6c9c048efa1f72b9189bc3a6b4498ce /net/base/file_stream_posix.cc | |
parent | 4fbaaee2b26f3edb0fc68a9b330f70e09d1f749d (diff) | |
download | chromium_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/file_stream_posix.cc')
-rw-r--r-- | net/base/file_stream_posix.cc | 17 |
1 files changed, 17 insertions, 0 deletions
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; |