| 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 |FileStream| with a new |BoundNetLog| (based on |log|) attached. |
| 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. |
| 144 // Creates source dependency events between |log| and |bound_net_log_|. |
| 145 // If |bound_net_log_| is not valid, nothing happens. |
| 146 void SetBoundNetLogSource(const net::BoundNetLog& log); |
| 147 |
| 139 private: | 148 private: |
| 140 class AsyncContext; | 149 class AsyncContext; |
| 141 friend class AsyncContext; | 150 friend class AsyncContext; |
| 142 friend class FileStreamTest; | 151 friend class FileStreamTest; |
| 143 | 152 |
| 144 // This member is used to support asynchronous reads. It is non-null when | 153 // This member is used to support asynchronous reads. It is non-null when |
| 145 // the FileStream was opened with PLATFORM_FILE_ASYNC. | 154 // the FileStream was opened with PLATFORM_FILE_ASYNC. |
| 146 scoped_ptr<AsyncContext> async_context_; | 155 scoped_ptr<AsyncContext> async_context_; |
| 147 | 156 |
| 148 base::PlatformFile file_; | 157 base::PlatformFile file_; |
| 149 int open_flags_; | 158 int open_flags_; |
| 150 bool auto_closed_; | 159 bool auto_closed_; |
| 151 bool record_uma_; | 160 bool record_uma_; |
| 161 net::BoundNetLog bound_net_log_; |
| 152 | 162 |
| 153 DISALLOW_COPY_AND_ASSIGN(FileStream); | 163 DISALLOW_COPY_AND_ASSIGN(FileStream); |
| 154 }; | 164 }; |
| 155 | 165 |
| 156 } // namespace net | 166 } // namespace net |
| 157 | 167 |
| 158 #endif // NET_BASE_FILE_STREAM_H_ | 168 #endif // NET_BASE_FILE_STREAM_H_ |
| OLD | NEW |