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_ |
11 #define NET_BASE_FILE_STREAM_H_ | 11 #define NET_BASE_FILE_STREAM_H_ |
12 | 12 |
13 #include "base/platform_file.h" | 13 #include "base/platform_file.h" |
14 #include "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
15 #include "net/base/file_stream_whence.h" | 15 #include "net/base/file_stream_whence.h" |
16 #include "net/base/net_export.h" | 16 #include "net/base/net_export.h" |
17 #include "net/base/net_log.h" | 17 #include "net/base/net_log.h" |
18 | 18 |
| 19 namespace base { |
19 class FilePath; | 20 class FilePath; |
| 21 } |
20 | 22 |
21 namespace net { | 23 namespace net { |
22 | 24 |
23 class IOBuffer; | 25 class IOBuffer; |
24 | 26 |
25 class NET_EXPORT FileStream { | 27 class NET_EXPORT FileStream { |
26 public: | 28 public: |
27 // Creates a |FileStream| with a new |BoundNetLog| (based on |net_log|) | 29 // Creates a |FileStream| with a new |BoundNetLog| (based on |net_log|) |
28 // attached. |net_log| may be NULL if no logging is needed. | 30 // attached. |net_log| may be NULL if no logging is needed. |
29 explicit FileStream(net::NetLog* net_log); | 31 explicit FileStream(net::NetLog* net_log); |
(...skipping 17 matching lines...) Expand all Loading... |
47 // started then an error code is returned. | 49 // started then an error code is returned. |
48 // | 50 // |
49 // Once the operation is done, |callback| will be run on the thread where | 51 // Once the operation is done, |callback| will be run on the thread where |
50 // Open() was called, with the result code. open_flags is a bitfield of | 52 // Open() was called, with the result code. open_flags is a bitfield of |
51 // base::PlatformFileFlags. | 53 // base::PlatformFileFlags. |
52 // | 54 // |
53 // If the file stream is not closed manually, the underlying file will be | 55 // If the file stream is not closed manually, the underlying file will be |
54 // automatically closed when FileStream is destructed in an asynchronous | 56 // automatically closed when FileStream is destructed in an asynchronous |
55 // manner (i.e. the file stream is closed in the background but you don't | 57 // manner (i.e. the file stream is closed in the background but you don't |
56 // know when). | 58 // know when). |
57 virtual int Open(const FilePath& path, int open_flags, | 59 virtual int Open(const base::FilePath& path, int open_flags, |
58 const CompletionCallback& callback); | 60 const CompletionCallback& callback); |
59 | 61 |
60 // Call this method to open the FileStream synchronously. | 62 // Call this method to open the FileStream synchronously. |
61 // The remaining methods cannot be used unless this method returns OK. If | 63 // The remaining methods cannot be used unless this method returns OK. If |
62 // the file cannot be opened then an error code is returned. open_flags is | 64 // the file cannot be opened then an error code is returned. open_flags is |
63 // a bitfield of base::PlatformFileFlags | 65 // a bitfield of base::PlatformFileFlags |
64 // | 66 // |
65 // If the file stream is not closed manually, the underlying file will be | 67 // If the file stream is not closed manually, the underlying file will be |
66 // automatically closed when FileStream is destructed. | 68 // automatically closed when FileStream is destructed. |
67 virtual int OpenSync(const FilePath& path, int open_flags); | 69 virtual int OpenSync(const base::FilePath& path, int open_flags); |
68 | 70 |
69 // Returns true if Open succeeded and Close has not been called. | 71 // Returns true if Open succeeded and Close has not been called. |
70 virtual bool IsOpen() const; | 72 virtual bool IsOpen() const; |
71 | 73 |
72 // Adjust the position from where data is read asynchronously. | 74 // Adjust the position from where data is read asynchronously. |
73 // Upon success, ERR_IO_PENDING is returned and |callback| will be run | 75 // Upon success, ERR_IO_PENDING is returned and |callback| will be run |
74 // on the thread where Seek() was called with the the stream position | 76 // on the thread where Seek() was called with the the stream position |
75 // relative to the start of the file. Otherwise, an error code is returned. | 77 // relative to the start of the file. Otherwise, an error code is returned. |
76 // It is invalid to request any asynchronous operations while there is an | 78 // It is invalid to request any asynchronous operations while there is an |
77 // in-flight asynchronous operation. | 79 // in-flight asynchronous operation. |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 // delaying FileStream's destructor. To perform all that separate object is | 229 // delaying FileStream's destructor. To perform all that separate object is |
228 // necessary. | 230 // necessary. |
229 scoped_ptr<Context> context_; | 231 scoped_ptr<Context> context_; |
230 | 232 |
231 DISALLOW_COPY_AND_ASSIGN(FileStream); | 233 DISALLOW_COPY_AND_ASSIGN(FileStream); |
232 }; | 234 }; |
233 | 235 |
234 } // namespace net | 236 } // namespace net |
235 | 237 |
236 #endif // NET_BASE_FILE_STREAM_H_ | 238 #endif // NET_BASE_FILE_STREAM_H_ |
OLD | NEW |