| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file defines FileStream::Context class. | 5 // This file defines FileStream::Context class. |
| 6 // The general design of FileStream is as follows: file_stream.h defines | 6 // The general design of FileStream is as follows: file_stream.h defines |
| 7 // FileStream class which basically is just an "wrapper" not containing any | 7 // FileStream class which basically is just an "wrapper" not containing any |
| 8 // specific implementation details. It re-routes all its method calls to | 8 // specific implementation details. It re-routes all its method calls to |
| 9 // the instance of FileStream::Context (FileStream holds a scoped_ptr to | 9 // the instance of FileStream::Context (FileStream holds a scoped_ptr to |
| 10 // FileStream::Context instance). Context was extracted into a different class | 10 // FileStream::Context instance). Context was extracted into a different class |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 #endif | 67 #endif |
| 68 | 68 |
| 69 int Read(IOBuffer* buf, | 69 int Read(IOBuffer* buf, |
| 70 int buf_len, | 70 int buf_len, |
| 71 const CompletionCallback& callback); | 71 const CompletionCallback& callback); |
| 72 | 72 |
| 73 int Write(IOBuffer* buf, | 73 int Write(IOBuffer* buf, |
| 74 int buf_len, | 74 int buf_len, |
| 75 const CompletionCallback& callback); | 75 const CompletionCallback& callback); |
| 76 | 76 |
| 77 const base::File& file() const { return file_; } | |
| 78 bool async_in_progress() const { return async_in_progress_; } | 77 bool async_in_progress() const { return async_in_progress_; } |
| 79 | 78 |
| 80 //////////////////////////////////////////////////////////////////////////// | 79 //////////////////////////////////////////////////////////////////////////// |
| 81 // Platform-independent methods implemented in file_stream_context.cc. | 80 // Platform-independent methods implemented in file_stream_context.cc. |
| 82 //////////////////////////////////////////////////////////////////////////// | 81 //////////////////////////////////////////////////////////////////////////// |
| 83 | 82 |
| 84 // Destroys the context. It can be deleted in the method or deletion can be | 83 // Destroys the context. It can be deleted in the method or deletion can be |
| 85 // deferred if some asynchronous operation is now in progress or if file is | 84 // deferred if some asynchronous operation is now in progress or if file is |
| 86 // not closed yet. | 85 // not closed yet. |
| 87 void Orphan(); | 86 void Orphan(); |
| 88 | 87 |
| 89 void Open(const base::FilePath& path, | 88 void Open(const base::FilePath& path, |
| 90 int open_flags, | 89 int open_flags, |
| 91 const CompletionCallback& callback); | 90 const CompletionCallback& callback); |
| 92 | 91 |
| 93 void Close(const CompletionCallback& callback); | 92 void Close(const CompletionCallback& callback); |
| 94 | 93 |
| 95 void Seek(base::File::Whence whence, | 94 // Seeks |offset| bytes from the start of the file. |
| 96 int64 offset, | 95 void Seek(int64 offset, const Int64CompletionCallback& callback); |
| 97 const Int64CompletionCallback& callback); | |
| 98 | 96 |
| 99 void Flush(const CompletionCallback& callback); | 97 void Flush(const CompletionCallback& callback); |
| 100 | 98 |
| 99 bool IsOpen() const; |
| 100 |
| 101 private: | 101 private: |
| 102 struct IOResult { | 102 struct IOResult { |
| 103 IOResult(); | 103 IOResult(); |
| 104 IOResult(int64 result, logging::SystemErrorCode os_error); | 104 IOResult(int64 result, logging::SystemErrorCode os_error); |
| 105 static IOResult FromOSError(logging::SystemErrorCode os_error); | 105 static IOResult FromOSError(logging::SystemErrorCode os_error); |
| 106 | 106 |
| 107 int64 result; | 107 int64 result; |
| 108 logging::SystemErrorCode os_error; // Set only when result < 0. | 108 logging::SystemErrorCode os_error; // Set only when result < 0. |
| 109 }; | 109 }; |
| 110 | 110 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 // network error code. | 142 // network error code. |
| 143 void OnAsyncCompleted(const Int64CompletionCallback& callback, | 143 void OnAsyncCompleted(const Int64CompletionCallback& callback, |
| 144 const IOResult& result); | 144 const IOResult& result); |
| 145 | 145 |
| 146 //////////////////////////////////////////////////////////////////////////// | 146 //////////////////////////////////////////////////////////////////////////// |
| 147 // Platform-dependent methods implemented in | 147 // Platform-dependent methods implemented in |
| 148 // file_stream_context_{win,posix}.cc. | 148 // file_stream_context_{win,posix}.cc. |
| 149 //////////////////////////////////////////////////////////////////////////// | 149 //////////////////////////////////////////////////////////////////////////// |
| 150 | 150 |
| 151 // Adjusts the position from where the data is read. | 151 // Adjusts the position from where the data is read. |
| 152 IOResult SeekFileImpl(base::File::Whence whence, int64 offset); | 152 IOResult SeekFileImpl(int64 offset); |
| 153 | 153 |
| 154 void OnFileOpened(); | 154 void OnFileOpened(); |
| 155 | 155 |
| 156 #if defined(OS_WIN) | 156 #if defined(OS_WIN) |
| 157 void IOCompletionIsPending(const CompletionCallback& callback, IOBuffer* buf); | 157 void IOCompletionIsPending(const CompletionCallback& callback, IOBuffer* buf); |
| 158 | 158 |
| 159 // Implementation of MessageLoopForIO::IOHandler. | 159 // Implementation of MessageLoopForIO::IOHandler. |
| 160 void OnIOCompleted(base::MessageLoopForIO::IOContext* context, | 160 void OnIOCompleted(base::MessageLoopForIO::IOContext* context, |
| 161 DWORD bytes_read, | 161 DWORD bytes_read, |
| 162 DWORD error) override; | 162 DWORD error) override; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 // Tracks the result of the IO completion operation. Set in OnIOComplete. | 233 // Tracks the result of the IO completion operation. Set in OnIOComplete. |
| 234 int result_; | 234 int result_; |
| 235 #endif | 235 #endif |
| 236 | 236 |
| 237 DISALLOW_COPY_AND_ASSIGN(Context); | 237 DISALLOW_COPY_AND_ASSIGN(Context); |
| 238 }; | 238 }; |
| 239 | 239 |
| 240 } // namespace net | 240 } // namespace net |
| 241 | 241 |
| 242 #endif // NET_BASE_FILE_STREAM_CONTEXT_H_ | 242 #endif // NET_BASE_FILE_STREAM_CONTEXT_H_ |
| OLD | NEW |