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, a basic interface for reading and writing files | 5 // This file defines FileStream, a basic interface for reading and writing files |
6 // synchronously or asynchronously with support for seeking to an offset. | 6 // synchronously or asynchronously with support for seeking to an offset. |
7 // Note that even when used asynchronously, only one operation is supported at | 7 // Note that even when used asynchronously, only one operation is supported at |
8 // a time. | 8 // a time. |
9 | 9 |
10 #ifndef NET_BASE_FILE_STREAM_H_ | 10 #ifndef NET_BASE_FILE_STREAM_H_ |
(...skipping 22 matching lines...) Expand all Loading... | |
33 // attached. |net_log| may be NULL if no logging is needed. | 33 // attached. |net_log| may be NULL if no logging is needed. |
34 explicit FileStream(net::NetLog* net_log); | 34 explicit FileStream(net::NetLog* net_log); |
35 | 35 |
36 // Construct a FileStream with an existing file handle and opening flags. | 36 // Construct a FileStream with an existing file handle and opening flags. |
37 // |file| is valid file handle. | 37 // |file| is valid file handle. |
38 // |flags| is a bitfield of base::PlatformFileFlags when the file handle was | 38 // |flags| is a bitfield of base::PlatformFileFlags when the file handle was |
39 // opened. | 39 // opened. |
40 // |net_log| is the net log pointer to use to create a |BoundNetLog|. May be | 40 // |net_log| is the net log pointer to use to create a |BoundNetLog|. May be |
41 // NULL if logging is not needed. | 41 // NULL if logging is not needed. |
42 // The already opened file will not be automatically closed when FileStream | 42 // The already opened file will not be automatically closed when FileStream |
43 // is destructed. | 43 // is destroyed. |
44 // Note: new FileStream object takes ownership of the PlatformFile and will | |
45 // close it on destruction. | |
44 FileStream(base::PlatformFile file, int flags, net::NetLog* net_log); | 46 FileStream(base::PlatformFile file, int flags, net::NetLog* net_log); |
45 | 47 |
46 // If the file stream was opened with Open() or OpenSync(), the underlying | 48 // If the file stream was opened with Open() or OpenSync(), the underlying |
47 // file will be closed automatically by the destructor, if not closed | 49 // file will be closed automatically by the destructor, if not closed |
48 // manually. | 50 // manually. |
49 virtual ~FileStream(); | 51 virtual ~FileStream(); |
50 | 52 |
51 // Call this method to close the FileStream, which was previously opened in | 53 // Call this method to close the FileStream, which was previously opened in |
52 // the async mode (PLATFORM_FILE_ASYNC) asynchronously. | 54 // the async mode (PLATFORM_FILE_ASYNC) asynchronously. |
53 // | 55 // |
54 // Once the operation is done, |callback| will be run on the thread where | 56 // Once the operation is done, |callback| will be run on the thread where |
55 // Close() was called, with OK (i.e. an error is not propagated just like | 57 // Close() was called, with OK (i.e. an error is not propagated just like |
56 // CloseSync() does not). | 58 // CloseSync() does not). |
57 // | 59 // |
58 // It is not OK to call Close() multiple times. The behavior is not defined. | 60 // It is not OK to call Close() multiple times. The behavior is not defined. |
59 // Note that there must never be any pending async operations. | 61 // Note that there must never be any pending async operations. |
60 virtual void Close(const CompletionCallback& callback); | 62 virtual void Close(const CompletionCallback& callback); |
61 | 63 |
62 // Call this method to close the FileStream synchronously. | 64 // Call this method to close the FileStream synchronously. |
63 // It is OK to call CloseSync() multiple times. Redundant calls are | 65 // It is OK to call CloseSync() multiple times. Redundant calls are |
64 // ignored. Note that if there are any pending async operations, they'll | 66 // ignored. Note that if there are any pending async operations, then |
65 // be aborted. | 67 // behavior of this method is equivalent to CloseAndCancelAsync(). |
willchan no longer on Chromium
2012/07/27 21:19:47
You can undo this comment change, right?
| |
66 virtual void CloseSync(); | 68 virtual void CloseSync(); |
67 | 69 |
68 // Call this method to open the FileStream asynchronously. The remaining | 70 // Call this method to open the FileStream asynchronously. The remaining |
69 // methods cannot be used unless the file is opened successfully. Returns | 71 // methods cannot be used unless the file is opened successfully. Returns |
70 // ERR_IO_PENDING if the operation is started. If the operation cannot be | 72 // ERR_IO_PENDING if the operation is started. If the operation cannot be |
71 // started then an error code is returned. | 73 // started then an error code is returned. |
72 // | 74 // |
73 // Once the operation is done, |callback| will be run on the thread where | 75 // Once the operation is done, |callback| will be run on the thread where |
74 // Open() was called, with the result code. open_flags is a bitfield of | 76 // Open() was called, with the result code. open_flags is a bitfield of |
75 // base::PlatformFileFlags. | 77 // base::PlatformFileFlags. |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 #elif defined(OS_POSIX) | 223 #elif defined(OS_POSIX) |
222 FileStreamPosix impl_; | 224 FileStreamPosix impl_; |
223 #endif | 225 #endif |
224 | 226 |
225 DISALLOW_COPY_AND_ASSIGN(FileStream); | 227 DISALLOW_COPY_AND_ASSIGN(FileStream); |
226 }; | 228 }; |
227 | 229 |
228 } // namespace net | 230 } // namespace net |
229 | 231 |
230 #endif // NET_BASE_FILE_STREAM_H_ | 232 #endif // NET_BASE_FILE_STREAM_H_ |
OLD | NEW |