OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 12 #pragma once |
13 | 13 |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/platform_file.h" | 15 #include "base/platform_file.h" |
16 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
17 #include "net/base/net_export.h" | 17 #include "net/base/net_export.h" |
18 #include "net/base/net_log.h" | |
18 | 19 |
19 class FilePath; | 20 class FilePath; |
20 | 21 |
21 namespace net { | 22 namespace net { |
22 | 23 |
23 // TODO(darin): Move this to a more generic location. | 24 // TODO(darin): Move this to a more generic location. |
24 // This explicit mapping matches both FILE_ on Windows and SEEK_ on Linux. | 25 // This explicit mapping matches both FILE_ on Windows and SEEK_ on Linux. |
25 enum Whence { | 26 enum Whence { |
26 FROM_BEGIN = 0, | 27 FROM_BEGIN = 0, |
27 FROM_CURRENT = 1, | 28 FROM_CURRENT = 1, |
28 FROM_END = 2 | 29 FROM_END = 2 |
29 }; | 30 }; |
30 | 31 |
31 class NET_EXPORT FileStream { | 32 class NET_EXPORT FileStream { |
32 public: | 33 public: |
33 FileStream(); | 34 FileStream(); |
34 | 35 |
36 // Create a new BoundNetLog and attach it to the stream. | |
Randy Smith (Not in Mondays)
2012/01/30 21:27:41
The primary thing a constructor does is construct
ahendrickson
2012/01/30 22:30:53
Done.
| |
37 FileStream(net::NetLog* log); | |
38 | |
35 // Construct a FileStream with an existing file handle and opening flags. | 39 // Construct a FileStream with an existing file handle and opening flags. |
36 // |file| is valid file handle. | 40 // |file| is valid file handle. |
37 // |flags| is a bitfield of base::PlatformFileFlags when the file handle was | 41 // |flags| is a bitfield of base::PlatformFileFlags when the file handle was |
38 // opened. | 42 // opened. |
39 // The already opened file will not be automatically closed when FileStream | 43 // The already opened file will not be automatically closed when FileStream |
40 // is destructed. | 44 // is destructed. |
41 FileStream(base::PlatformFile file, int flags); | 45 FileStream(base::PlatformFile file, int flags); |
42 | 46 |
43 virtual ~FileStream(); | 47 virtual ~FileStream(); |
44 | 48 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 // calling. | 133 // calling. |
130 // | 134 // |
131 /// Returns an error code if the operation could not be performed. | 135 /// Returns an error code if the operation could not be performed. |
132 // | 136 // |
133 // This method should not be called if the stream was opened READ_ONLY. | 137 // This method should not be called if the stream was opened READ_ONLY. |
134 virtual int Flush(); | 138 virtual int Flush(); |
135 | 139 |
136 // Turns on UMA error statistics gathering. | 140 // Turns on UMA error statistics gathering. |
137 void EnableErrorStatistics(); | 141 void EnableErrorStatistics(); |
138 | 142 |
143 // Sets the source reference for net-internals logging. | |
Randy Smith (Not in Mondays)
2012/01/30 21:27:41
If this has restrictions with regard to how the Fi
ahendrickson
2012/01/30 22:30:53
The only difference is that if |net_log_| is inval
| |
144 void SetBoundNetLogSource(const net::BoundNetLog& log); | |
145 | |
139 private: | 146 private: |
140 class AsyncContext; | 147 class AsyncContext; |
141 friend class AsyncContext; | 148 friend class AsyncContext; |
142 friend class FileStreamTest; | 149 friend class FileStreamTest; |
143 | 150 |
144 // This member is used to support asynchronous reads. It is non-null when | 151 // This member is used to support asynchronous reads. It is non-null when |
145 // the FileStream was opened with PLATFORM_FILE_ASYNC. | 152 // the FileStream was opened with PLATFORM_FILE_ASYNC. |
146 scoped_ptr<AsyncContext> async_context_; | 153 scoped_ptr<AsyncContext> async_context_; |
147 | 154 |
148 base::PlatformFile file_; | 155 base::PlatformFile file_; |
149 int open_flags_; | 156 int open_flags_; |
150 bool auto_closed_; | 157 bool auto_closed_; |
151 bool record_uma_; | 158 bool record_uma_; |
159 net::BoundNetLog net_log_; | |
Randy Smith (Not in Mondays)
2012/01/30 21:27:41
I'm uncomfortable calling a BoundNetLog a net_log_
ahendrickson
2012/01/30 22:30:53
Done.
| |
152 | 160 |
153 DISALLOW_COPY_AND_ASSIGN(FileStream); | 161 DISALLOW_COPY_AND_ASSIGN(FileStream); |
154 }; | 162 }; |
155 | 163 |
156 } // namespace net | 164 } // namespace net |
157 | 165 |
158 #endif // NET_BASE_FILE_STREAM_H_ | 166 #endif // NET_BASE_FILE_STREAM_H_ |
OLD | NEW |