Chromium Code Reviews| 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_api.h" | 17 #include "net/base/net_api.h" |
| 18 | 18 |
| 19 class FilePath; | 19 class FilePath; |
| 20 | 20 |
| 21 namespace net { | 21 namespace net { |
| 22 | 22 |
| 23 enum RecordingClass { | |
|
cbentzel
2011/08/15 19:49:11
This CL would be a lot easier without the Recordin
ahendrickson
2011/08/15 23:42:26
Done.
| |
| 24 RECORDING_CLASS_NONE = 0, | |
| 25 RECORDING_CLASS_DOWNLOADS = 1, | |
| 26 // Add more flags here as necessary. Max 31. | |
| 27 RECORDING_CLASS_MAX, | |
| 28 }; | |
| 29 | |
| 30 enum FileErrorTypes { | |
|
cbentzel
2011/08/15 19:49:11
This doesn't need to be exposed in this header - i
cbentzel
2011/08/15 19:49:11
Nit: maybe FileError rather than FileErrorTypes
ahendrickson
2011/08/15 23:42:26
Renamed to FileErrorSource.
ahendrickson
2011/08/15 23:42:26
Done.
| |
| 31 FILE_ERROR_TYPES_IS_NOT_OPEN = 0, | |
| 32 FILE_ERROR_TYPES_OPEN, | |
| 33 FILE_ERROR_TYPES_WRITE, | |
| 34 FILE_ERROR_TYPES_READ, | |
| 35 FILE_ERROR_TYPES_SEEK, | |
| 36 FILE_ERROR_TYPES_FLUSH, | |
| 37 FILE_ERROR_TYPES_SET_EOF, | |
| 38 FILE_ERROR_TYPES_GET_SIZE, | |
| 39 FILE_ERROR_TYPES_COUNT, | |
| 40 }; | |
| 41 | |
| 42 void EnableRecordingForClass(int class_flags); | |
| 43 | |
| 44 void RecordFileError(int error, FileErrorTypes type, int class_flags); | |
|
cbentzel
2011/08/15 19:49:11
This would also move to the new header.
ahendrickson
2011/08/15 23:42:26
Done.
| |
| 45 | |
| 23 // TODO(darin): Move this to a more generic location. | 46 // TODO(darin): Move this to a more generic location. |
| 24 // This explicit mapping matches both FILE_ on Windows and SEEK_ on Linux. | 47 // This explicit mapping matches both FILE_ on Windows and SEEK_ on Linux. |
| 25 enum Whence { | 48 enum Whence { |
| 26 FROM_BEGIN = 0, | 49 FROM_BEGIN = 0, |
| 27 FROM_CURRENT = 1, | 50 FROM_CURRENT = 1, |
| 28 FROM_END = 2 | 51 FROM_END = 2 |
| 29 }; | 52 }; |
| 30 | 53 |
| 31 class NET_API FileStream { | 54 class NET_API FileStream { |
| 32 public: | 55 public: |
| 33 FileStream(); | 56 FileStream(); |
| 57 explicit FileStream(int class_flags); | |
|
cbentzel
2011/08/15 19:49:11
Remove the new constructors and just use EnableRec
ahendrickson
2011/08/15 23:42:26
Done.
| |
| 34 | 58 |
| 35 // Construct a FileStream with an existing file handle and opening flags. | 59 // Construct a FileStream with an existing file handle and opening flags. |
| 36 // |file| is valid file handle. | 60 // |file| is valid file handle. |
| 37 // |flags| is a bitfield of base::PlatformFileFlags when the file handle was | 61 // |flags| is a bitfield of base::PlatformFileFlags when the file handle was |
| 38 // opened. | 62 // opened. |
| 39 // The already opened file will not be automatically closed when FileStream | 63 // The already opened file will not be automatically closed when FileStream |
| 40 // is destructed. | 64 // is destructed. |
| 41 FileStream(base::PlatformFile file, int flags); | 65 FileStream(base::PlatformFile file, int flags); |
| 42 | 66 |
| 67 // Construct a FileStream with an existing file handle and opening flags. | |
|
cbentzel
2011/08/15 19:49:11
Ditto.
ahendrickson
2011/08/15 23:42:26
Done.
| |
| 68 // |file| is valid file handle. | |
| 69 // |flags| is a bitfield of base::PlatformFileFlags when the file handle was | |
| 70 // opened. | |
| 71 // The already opened file will not be automatically closed when FileStream | |
| 72 // is destructed. | |
| 73 FileStream(base::PlatformFile file, int flags, int class_flags); | |
| 74 | |
| 43 ~FileStream(); | 75 ~FileStream(); |
| 44 | 76 |
| 45 // Call this method to close the FileStream. It is OK to call Close | 77 // Call this method to close the FileStream. It is OK to call Close |
| 46 // multiple times. Redundant calls are ignored. | 78 // multiple times. Redundant calls are ignored. |
| 47 // Note that if there are any pending async operations, they'll be aborted. | 79 // Note that if there are any pending async operations, they'll be aborted. |
| 48 void Close(); | 80 void Close(); |
| 49 | 81 |
| 50 // Call this method to open the FileStream. The remaining methods | 82 // Call this method to open the FileStream. The remaining methods |
| 51 // cannot be used unless this method returns OK. If the file cannot be | 83 // cannot be used unless this method returns OK. If the file cannot be |
| 52 // opened then an error code is returned. | 84 // opened then an error code is returned. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 // Forces out a filesystem sync on this file to make sure that the file was | 157 // Forces out a filesystem sync on this file to make sure that the file was |
| 126 // written out to disk and is not currently sitting in the buffer. This does | 158 // written out to disk and is not currently sitting in the buffer. This does |
| 127 // not have to be called, it just forces one to happen at the time of | 159 // not have to be called, it just forces one to happen at the time of |
| 128 // calling. | 160 // calling. |
| 129 // | 161 // |
| 130 /// Returns an error code if the operation could not be performed. | 162 /// Returns an error code if the operation could not be performed. |
| 131 // | 163 // |
| 132 // This method should not be called if the stream was opened READ_ONLY. | 164 // This method should not be called if the stream was opened READ_ONLY. |
| 133 int Flush(); | 165 int Flush(); |
| 134 | 166 |
| 167 void EnableRecording(bool enable, int class_flags); | |
|
cbentzel
2011/08/15 19:49:11
Just make this
void EnableRecording();
enable i
ahendrickson
2011/08/15 23:42:26
Done.
| |
| 168 | |
| 135 private: | 169 private: |
| 136 class AsyncContext; | 170 class AsyncContext; |
| 137 friend class AsyncContext; | 171 friend class AsyncContext; |
| 138 | 172 |
| 139 // This member is used to support asynchronous reads. It is non-null when | 173 // This member is used to support asynchronous reads. It is non-null when |
| 140 // the FileStream was opened with PLATFORM_FILE_ASYNC. | 174 // the FileStream was opened with PLATFORM_FILE_ASYNC. |
| 141 scoped_ptr<AsyncContext> async_context_; | 175 scoped_ptr<AsyncContext> async_context_; |
| 142 | 176 |
| 143 base::PlatformFile file_; | 177 base::PlatformFile file_; |
| 144 int open_flags_; | 178 int open_flags_; |
| 145 bool auto_closed_; | 179 bool auto_closed_; |
| 180 int class_flags_; | |
| 146 | 181 |
| 147 DISALLOW_COPY_AND_ASSIGN(FileStream); | 182 DISALLOW_COPY_AND_ASSIGN(FileStream); |
| 148 }; | 183 }; |
| 149 | 184 |
| 150 } // namespace net | 185 } // namespace net |
| 151 | 186 |
| 152 #endif // NET_BASE_FILE_STREAM_H_ | 187 #endif // NET_BASE_FILE_STREAM_H_ |
| OLD | NEW |