Chromium Code Reviews| Index: net/base/file_stream_posix.h |
| =================================================================== |
| --- net/base/file_stream_posix.h (revision 151422) |
| +++ net/base/file_stream_posix.h (working copy) |
| @@ -7,74 +7,132 @@ |
| #ifndef NET_BASE_FILE_STREAM_POSIX_H_ |
| #define NET_BASE_FILE_STREAM_POSIX_H_ |
| -#include "base/memory/scoped_ptr.h" |
| -#include "base/memory/weak_ptr.h" |
| +#include <errno.h> |
| + |
| #include "base/platform_file.h" |
| #include "net/base/completion_callback.h" |
| +#include "net/base/file_stream.h" |
| +#include "net/base/file_stream_metrics.h" |
| #include "net/base/file_stream_whence.h" |
| #include "net/base/net_export.h" |
| #include "net/base/net_log.h" |
| class FilePath; |
| -namespace base { |
| -class WaitableEvent; |
| -} |
| - |
| namespace net { |
| class IOBuffer; |
| -class NET_EXPORT FileStreamPosix { |
| +class FileStream::Context { |
| public: |
| - explicit FileStreamPosix(net::NetLog* net_log); |
| - FileStreamPosix(base::PlatformFile file, int flags, net::NetLog* net_log); |
| - ~FileStreamPosix(); |
| + explicit Context(const BoundNetLog& bound_net_log); |
| + Context(base::PlatformFile file, |
| + const BoundNetLog& bound_net_log, |
| + int open_flags); |
| + ~Context(); |
| - // FileStream implementations. |
| - void Close(const CompletionCallback& callback); |
| + // Destroys the context. It can be deleted in the method or deletion can be |
| + // deferred to WorkerPool if some asynchronous operation is now in progress |
| + // or if auto-closing is needed. |
| + void Orphan(); |
| + |
| + bool record_uma() const { return record_uma_; } |
| + void set_record_uma(bool value) { record_uma_ = value; } |
| + base::PlatformFile file() const { return file_; } |
| + bool async_in_progress() const { return async_in_progress_; } |
| + |
| + // Sync and async versions of all operations |
| + void OpenAsync(const FilePath& path, |
| + int open_flags, |
| + const CompletionCallback& callback); |
| + int OpenSync(const FilePath& path, int open_flags); |
| + |
| + void CloseAsync(const CompletionCallback& callback); |
| void CloseSync(); |
| - int Open(const FilePath& path, int open_flags, |
| - const CompletionCallback& callback); |
| - int OpenSync(const FilePath& path, int open_flags); |
| - bool IsOpen() const; |
| - int Seek(Whence whence, int64 offset, |
| - const Int64CompletionCallback& callback); |
| + |
| + void SeekAsync(Whence whence, |
| + int64 offset, |
| + const Int64CompletionCallback& callback); |
| int64 SeekSync(Whence whence, int64 offset); |
| - int64 Available(); |
| - int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback); |
| + |
| + int64 GetFileSize() const; |
| + |
| + int ReadAsync(IOBuffer* buf, |
| + int buf_len, |
| + const CompletionCallback& callback); |
| int ReadSync(char* buf, int buf_len); |
| - int ReadUntilComplete(char *buf, int buf_len); |
| - int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback); |
| + |
| + int WriteAsync(IOBuffer* buf, |
| + int buf_len, |
| + const CompletionCallback& callback); |
| int WriteSync(const char* buf, int buf_len); |
| - int64 Truncate(int64 bytes); |
| + |
| int Flush(); |
| - void EnableErrorStatistics(); |
| - void SetBoundNetLogSource( |
| - const net::BoundNetLog& owner_bound_net_log); |
| - base::PlatformFile GetPlatformFileForTesting(); |
| - // Resets on_io_complete_ and WeakPtr's. |
| - // Called when Read() or Write() is completed. |
| - void ResetOnIOComplete(); |
| + int Truncate(int64 bytes); |
| private: |
| - // Called when the file_ is closed asynchronously. |
| - void OnClosed(const CompletionCallback& callback); |
| + enum { |
| + kErrorBadFile = EBADF |
| + }; |
| - // Waits until the in-flight async open/close/read/write operation is |
| - // complete. |
| - void WaitForIOCompletion(); |
| + struct OpenResult { |
| + base::PlatformFile file; |
| + int error_code; |
| + }; |
| + // Stubs to make more of the Context code multi-platform. |
|
willchan no longer on Chromium
2012/09/11 23:05:02
Can you use banner comments to indicate which sect
|
| + int GetLastErrno() { return errno; } |
| + void OnAsyncFileOpened() {} |
| + |
| + // Map system error into network error code and log it with |bound_net_log_|. |
| + int RecordAndMapError(int error, FileErrorSource source) const; |
| + |
| + void BeginOpenEvent(const FilePath& path); |
| + |
| + // Opens a file. |
| + OpenResult OpenFileImpl(const FilePath& path, int open_flags); |
| + |
| + int ProcessOpenError(int error_code); |
| + void OnOpenCompleted(const CompletionCallback& callback, OpenResult result); |
| + |
| + void OnCloseCompleted(const CompletionCallback& callback); |
| + |
| + // Adjusts the position from where the data is read. |
| + int64 SeekFileImpl(Whence whence, int64 offset); |
| + |
| + // ReadFile() is a simple wrapper around read() that handles EINTR signals |
| + // and calls RecordAndMapError() to map errno to net error codes. |
| + int64 ReadFileImpl(scoped_refptr<IOBuffer> buf, int buf_len); |
| + |
| + // WriteFile() is a simple wrapper around write() that handles EINTR signals |
| + // and calls MapSystemError() to map errno to net error codes. It tries |
| + // to write to completion. |
| + int64 WriteFileImpl(scoped_refptr<IOBuffer> buf, int buf_len); |
| + |
| + Int64CompletionCallback IntToInt64(const CompletionCallback& callback); |
| + |
| + // Checks for IO error that probably happened in ReadFileImpl(), |
| + // WriteFileImpl() or SeekFileImpl(). If there was error reports it. |
| + void CheckForIOError(int64* result, FileErrorSource source); |
| + |
| + // Called when asynchronous Read(), Write() or Seek() is completed. |
| + // Reports error if needed and calls callback. |
| + void ProcessAsyncResult(const Int64CompletionCallback& callback, |
| + FileErrorSource source, |
| + int64 result); |
| + |
| + // Called when asynchronous Open(), Read(), Write() or Seek() |
| + // is completed. |result| contains the result or a network error code. |
| + void OnAsyncCompleted(const Int64CompletionCallback& callback, int64 result); |
| + |
| base::PlatformFile file_; |
| - int open_flags_; |
| - bool auto_closed_; |
| bool record_uma_; |
| - net::BoundNetLog bound_net_log_; |
| - base::WeakPtrFactory<FileStreamPosix> weak_ptr_factory_; |
| - scoped_ptr<base::WaitableEvent> on_io_complete_; |
| + bool async_in_progress_; |
| + bool orphaned_; |
| + BoundNetLog bound_net_log_; |
| - DISALLOW_COPY_AND_ASSIGN(FileStreamPosix); |
| + DISALLOW_COPY_AND_ASSIGN(Context); |
| }; |
| } // namespace net |