| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 #endif | 68 #endif |
| 69 | 69 |
| 70 int Read(IOBuffer* buf, | 70 int Read(IOBuffer* buf, |
| 71 int buf_len, | 71 int buf_len, |
| 72 const CompletionCallback& callback); | 72 const CompletionCallback& callback); |
| 73 | 73 |
| 74 int Write(IOBuffer* buf, | 74 int Write(IOBuffer* buf, |
| 75 int buf_len, | 75 int buf_len, |
| 76 const CompletionCallback& callback); | 76 const CompletionCallback& callback); |
| 77 | 77 |
| 78 const base::File& file() const { return file_; } | |
| 79 bool async_in_progress() const { return async_in_progress_; } | 78 bool async_in_progress() const { return async_in_progress_; } |
| 80 | 79 |
| 81 //////////////////////////////////////////////////////////////////////////// | 80 //////////////////////////////////////////////////////////////////////////// |
| 82 // Platform-independent methods implemented in file_stream_context.cc. | 81 // Platform-independent methods implemented in file_stream_context.cc. |
| 83 //////////////////////////////////////////////////////////////////////////// | 82 //////////////////////////////////////////////////////////////////////////// |
| 84 | 83 |
| 85 // Destroys the context. It can be deleted in the method or deletion can be | 84 // Destroys the context. It can be deleted in the method or deletion can be |
| 86 // deferred if some asynchronous operation is now in progress or if file is | 85 // deferred if some asynchronous operation is now in progress or if file is |
| 87 // not closed yet. | 86 // not closed yet. |
| 88 void Orphan(); | 87 void Orphan(); |
| 89 | 88 |
| 90 void Open(const base::FilePath& path, | 89 void Open(const base::FilePath& path, |
| 91 int open_flags, | 90 int open_flags, |
| 92 const CompletionCallback& callback); | 91 const CompletionCallback& callback); |
| 93 | 92 |
| 94 void Close(const CompletionCallback& callback); | 93 void Close(const CompletionCallback& callback); |
| 95 | 94 |
| 96 void Seek(base::File::Whence whence, | 95 // Seeks |offset| bytes from the start of the file. |
| 97 int64_t offset, | 96 void Seek(int64_t offset, const Int64CompletionCallback& callback); |
| 98 const Int64CompletionCallback& callback); | |
| 99 | 97 |
| 100 void Flush(const CompletionCallback& callback); | 98 void Flush(const CompletionCallback& callback); |
| 101 | 99 |
| 100 bool IsOpen() const; |
| 101 |
| 102 private: | 102 private: |
| 103 struct IOResult { | 103 struct IOResult { |
| 104 IOResult(); | 104 IOResult(); |
| 105 IOResult(int64_t result, logging::SystemErrorCode os_error); | 105 IOResult(int64_t result, logging::SystemErrorCode os_error); |
| 106 static IOResult FromOSError(logging::SystemErrorCode os_error); | 106 static IOResult FromOSError(logging::SystemErrorCode os_error); |
| 107 | 107 |
| 108 int64_t result; | 108 int64_t result; |
| 109 logging::SystemErrorCode os_error; // Set only when result < 0. | 109 logging::SystemErrorCode os_error; // Set only when result < 0. |
| 110 }; | 110 }; |
| 111 | 111 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 // network error code. | 143 // network error code. |
| 144 void OnAsyncCompleted(const Int64CompletionCallback& callback, | 144 void OnAsyncCompleted(const Int64CompletionCallback& callback, |
| 145 const IOResult& result); | 145 const IOResult& result); |
| 146 | 146 |
| 147 //////////////////////////////////////////////////////////////////////////// | 147 //////////////////////////////////////////////////////////////////////////// |
| 148 // Platform-dependent methods implemented in | 148 // Platform-dependent methods implemented in |
| 149 // file_stream_context_{win,posix}.cc. | 149 // file_stream_context_{win,posix}.cc. |
| 150 //////////////////////////////////////////////////////////////////////////// | 150 //////////////////////////////////////////////////////////////////////////// |
| 151 | 151 |
| 152 // Adjusts the position from where the data is read. | 152 // Adjusts the position from where the data is read. |
| 153 IOResult SeekFileImpl(base::File::Whence whence, int64_t offset); | 153 IOResult SeekFileImpl(int64_t offset); |
| 154 | 154 |
| 155 void OnFileOpened(); | 155 void OnFileOpened(); |
| 156 | 156 |
| 157 #if defined(OS_WIN) | 157 #if defined(OS_WIN) |
| 158 void IOCompletionIsPending(const CompletionCallback& callback, IOBuffer* buf); | 158 void IOCompletionIsPending(const CompletionCallback& callback, IOBuffer* buf); |
| 159 | 159 |
| 160 // Implementation of MessageLoopForIO::IOHandler. | 160 // Implementation of MessageLoopForIO::IOHandler. |
| 161 void OnIOCompleted(base::MessageLoopForIO::IOContext* context, | 161 void OnIOCompleted(base::MessageLoopForIO::IOContext* context, |
| 162 DWORD bytes_read, | 162 DWORD bytes_read, |
| 163 DWORD error) override; | 163 DWORD error) override; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 // Tracks the result of the IO completion operation. Set in OnIOComplete. | 234 // Tracks the result of the IO completion operation. Set in OnIOComplete. |
| 235 int result_; | 235 int result_; |
| 236 #endif | 236 #endif |
| 237 | 237 |
| 238 DISALLOW_COPY_AND_ASSIGN(Context); | 238 DISALLOW_COPY_AND_ASSIGN(Context); |
| 239 }; | 239 }; |
| 240 | 240 |
| 241 } // namespace net | 241 } // namespace net |
| 242 | 242 |
| 243 #endif // NET_BASE_FILE_STREAM_CONTEXT_H_ | 243 #endif // NET_BASE_FILE_STREAM_CONTEXT_H_ |
| OLD | NEW |