Chromium Code Reviews| Index: net/base/file_stream_context.h |
| diff --git a/net/base/file_stream_context.h b/net/base/file_stream_context.h |
| index c4a06ee1de62c4168675ae47d3150fc65069670b..5cd98e8370b30ad3abc47df3f877db8fc1651d1c 100644 |
| --- a/net/base/file_stream_context.h |
| +++ b/net/base/file_stream_context.h |
| @@ -33,7 +33,6 @@ |
| #include "base/task_runner.h" |
| #include "net/base/completion_callback.h" |
| #include "net/base/file_stream.h" |
| -#include "net/base/file_stream_whence.h" |
| #if defined(OS_POSIX) |
| #include <errno.h> |
| @@ -50,7 +49,7 @@ class IOBuffer; |
| #if defined(OS_WIN) |
| class FileStream::Context : public base::MessageLoopForIO::IOHandler { |
| #elif defined(OS_POSIX) |
| -class FileStream::Context { |
| +class FileStream::Context : public base::MessageLoopForIO::Watcher { |
| #endif |
| public: |
| //////////////////////////////////////////////////////////////////////////// |
| @@ -60,23 +59,23 @@ class FileStream::Context { |
| explicit Context(const scoped_refptr<base::TaskRunner>& task_runner); |
| Context(base::File file, const scoped_refptr<base::TaskRunner>& task_runner); |
| -#if defined(OS_WIN) |
| virtual ~Context(); |
| -#elif defined(OS_POSIX) |
| - ~Context(); |
| -#endif |
| - int ReadAsync(IOBuffer* buf, |
| - int buf_len, |
| - const CompletionCallback& callback); |
| + int Read(IOBuffer* buf, |
| + int buf_len, |
| + const CompletionCallback& callback); |
| - int WriteAsync(IOBuffer* buf, |
| - int buf_len, |
| - const CompletionCallback& callback); |
| + int ReadNoBlocking(IOBuffer* buf, |
| + int buf_len, |
| + const CompletionCallback& callback); |
| - //////////////////////////////////////////////////////////////////////////// |
| - // Inline methods. |
| - //////////////////////////////////////////////////////////////////////////// |
| + int Write(IOBuffer* buf, |
| + int buf_len, |
| + const CompletionCallback& callback); |
| + |
| + int WriteNoBlocking(IOBuffer* buf, |
| + int buf_len, |
| + const CompletionCallback& callback); |
| const base::File& file() const { return file_; } |
| bool async_in_progress() const { return async_in_progress_; } |
| @@ -90,23 +89,19 @@ class FileStream::Context { |
| // not closed yet. |
| void Orphan(); |
| - void OpenAsync(const base::FilePath& path, |
| - int open_flags, |
| - const CompletionCallback& callback); |
| + void Open(const base::FilePath& path, |
| + int open_flags, |
| + const CompletionCallback& callback); |
| - void CloseAsync(const CompletionCallback& callback); |
| + void Close(const CompletionCallback& callback); |
| - void SeekAsync(Whence whence, |
| - int64 offset, |
| - const Int64CompletionCallback& callback); |
| + void Seek(base::File::Whence whence, |
| + int64 offset, |
| + const Int64CompletionCallback& callback); |
| - void FlushAsync(const CompletionCallback& callback); |
| + void Flush(const CompletionCallback& callback); |
| private: |
| - //////////////////////////////////////////////////////////////////////////// |
| - // Platform-independent methods implemented in file_stream_context.cc. |
| - //////////////////////////////////////////////////////////////////////////// |
| - |
| struct IOResult { |
| IOResult(); |
| IOResult(int64 result, int os_error); |
| @@ -129,10 +124,16 @@ class FileStream::Context { |
| IOResult error_code; |
| }; |
| + //////////////////////////////////////////////////////////////////////////// |
| + // Platform-independent methods implemented in file_stream_context.cc. |
| + //////////////////////////////////////////////////////////////////////////// |
| + |
| OpenResult OpenFileImpl(const base::FilePath& path, int open_flags); |
| IOResult CloseFileImpl(); |
| + IOResult FlushFileImpl(); |
| + |
| void OnOpenCompleted(const CompletionCallback& callback, |
| OpenResult open_result); |
| @@ -140,39 +141,21 @@ class FileStream::Context { |
| Int64CompletionCallback IntToInt64(const CompletionCallback& callback); |
| - // Called when asynchronous Open() or Seek() |
| - // is completed. |result| contains the result or a network error code. |
| + // Called when Open() or Seek() completes. |result| contains the result or a |
| + // network error code. |
| void OnAsyncCompleted(const Int64CompletionCallback& callback, |
| const IOResult& result); |
| //////////////////////////////////////////////////////////////////////////// |
| - // Helper stuff which is platform-dependent but is used in the platform- |
| - // independent code implemented in file_stream_context.cc. These helpers were |
| - // introduced solely to implement as much of the Context methods as |
| - // possible independently from platform. |
| - //////////////////////////////////////////////////////////////////////////// |
| - |
| -#if defined(OS_WIN) |
| - int GetLastErrno() { return GetLastError(); } |
| - void OnAsyncFileOpened(); |
| -#elif defined(OS_POSIX) |
| - int GetLastErrno() { return errno; } |
| - void OnAsyncFileOpened() {} |
| - void CancelIo(base::PlatformFile) {} |
| -#endif |
| - |
| - //////////////////////////////////////////////////////////////////////////// |
| // Platform-dependent methods implemented in |
| // file_stream_context_{win,posix}.cc. |
| //////////////////////////////////////////////////////////////////////////// |
| // Adjusts the position from where the data is read. |
| - IOResult SeekFileImpl(Whence whence, int64 offset); |
| - |
| - // Flushes all data written to the stream. |
| - IOResult FlushFileImpl(); |
| + IOResult SeekFileImpl(base::File::Whence whence, int64 offset); |
| #if defined(OS_WIN) |
| + void OnFileOpened(); |
| void IOCompletionIsPending(const CompletionCallback& callback, IOBuffer* buf); |
| // Implementation of MessageLoopForIO::IOHandler. |
| @@ -180,6 +163,8 @@ class FileStream::Context { |
| DWORD bytes_read, |
| DWORD error) OVERRIDE; |
| #elif defined(OS_POSIX) |
| + void OnFileOpened() {} |
|
hashimoto
2014/06/12 13:03:36
nit: This can be put outside of #if? You can put a
rvargas (doing something else)
2014/06/13 02:49:10
Done.
|
| + |
| // ReadFileImpl() is a simple wrapper around read() that handles EINTR |
| // signals and calls RecordAndMapError() to map errno to net error codes. |
| IOResult ReadFileImpl(scoped_refptr<IOBuffer> buf, int buf_len); |
| @@ -188,6 +173,10 @@ class FileStream::Context { |
| // signals and calls MapSystemError() to map errno to net error codes. |
| // It tries to write to completion. |
| IOResult WriteFileImpl(scoped_refptr<IOBuffer> buf, int buf_len); |
| + |
| + // MessageLoopForIO::Watcher interface |
| + virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; |
| + virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; |
| #endif |
| base::File file_; |
| @@ -199,6 +188,12 @@ class FileStream::Context { |
| base::MessageLoopForIO::IOContext io_context_; |
| CompletionCallback callback_; |
| scoped_refptr<IOBuffer> in_flight_buf_; |
| +#elif defined(OS_POSIX) |
| + base::MessageLoopForIO::FileDescriptorWatcher file_watcher_; |
| + // ReadNoBlocking/WriteNoBlocking arguments. |
| + scoped_refptr<IOBuffer> buf_; |
|
hashimoto
2014/06/12 13:03:36
nit: How about renaming this to |in_flight_buf_| t
rvargas (doing something else)
2014/06/13 02:49:10
I didn't even look at the win members!. done.
|
| + int buf_len_; |
| + CompletionCallback callback_; |
|
hashimoto
2014/06/12 13:03:37
nit: This can be put outside of #if?
rvargas (doing something else)
2014/06/13 02:49:10
Done.
|
| #endif |
| DISALLOW_COPY_AND_ASSIGN(Context); |