Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: net/base/file_stream.h

Issue 1148383003: Only support seeking file streams from the beginning of the file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Win DBG build by Pass()-ing file out of CreateForAsyncHandle. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/android/url_request_content_job.cc ('k') | net/base/file_stream.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 // Returns ERR_IO_PENDING and closes the file asynchronously, calling 56 // Returns ERR_IO_PENDING and closes the file asynchronously, calling
57 // |callback| when done. 57 // |callback| when done.
58 // It is invalid to request any asynchronous operations while there is an 58 // It is invalid to request any asynchronous operations while there is an
59 // in-flight asynchronous operation. 59 // in-flight asynchronous operation.
60 virtual int Close(const CompletionCallback& callback); 60 virtual int Close(const CompletionCallback& callback);
61 61
62 // Returns true if Open succeeded and Close has not been called. 62 // Returns true if Open succeeded and Close has not been called.
63 virtual bool IsOpen() const; 63 virtual bool IsOpen() const;
64 64
65 // Adjust the position from where data is read asynchronously. 65 // Adjust the position from the start of the file where data is read
66 // Upon success, ERR_IO_PENDING is returned and |callback| will be run 66 // asynchronously. Upon success, ERR_IO_PENDING is returned and |callback|
67 // on the thread where Seek() was called with the the stream position 67 // will be run on the thread where Seek() was called with the the stream
68 // relative to the start of the file. Otherwise, an error code is returned. 68 // position relative to the start of the file. Otherwise, an error code is
69 // It is invalid to request any asynchronous operations while there is an 69 // returned. It is invalid to request any asynchronous operations while there
70 // in-flight asynchronous operation. 70 // is an in-flight asynchronous operation.
71 virtual int Seek(base::File::Whence whence, 71 virtual int Seek(int64_t offset, const Int64CompletionCallback& callback);
72 int64_t offset,
73 const Int64CompletionCallback& callback);
74 72
75 // Call this method to read data from the current stream position 73 // Call this method to read data from the current stream position
76 // asynchronously. Up to buf_len bytes will be copied into buf. (In 74 // asynchronously. Up to buf_len bytes will be copied into buf. (In
77 // other words, partial reads are allowed.) Returns the number of bytes 75 // other words, partial reads are allowed.) Returns the number of bytes
78 // copied, 0 if at end-of-file, or an error code if the operation could 76 // copied, 0 if at end-of-file, or an error code if the operation could
79 // not be performed. 77 // not be performed.
80 // 78 //
81 // The file must be opened with FLAG_ASYNC, and a non-null 79 // The file must be opened with FLAG_ASYNC, and a non-null
82 // callback must be passed to this method. If the read could not 80 // callback must be passed to this method. If the read could not
83 // complete synchronously, then ERR_IO_PENDING is returned, and the 81 // complete synchronously, then ERR_IO_PENDING is returned, and the
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // It is valid to destroy or close the file stream while there is an 132 // It is valid to destroy or close the file stream while there is an
135 // asynchronous flush in progress. That will cancel the flush and allow 133 // asynchronous flush in progress. That will cancel the flush and allow
136 // the buffer to be freed. 134 // the buffer to be freed.
137 // 135 //
138 // It is invalid to request any asynchronous operations while there is an 136 // It is invalid to request any asynchronous operations while there is an
139 // in-flight asynchronous operation. 137 // in-flight asynchronous operation.
140 // 138 //
141 // This method should not be called if the stream was opened READ_ONLY. 139 // This method should not be called if the stream was opened READ_ONLY.
142 virtual int Flush(const CompletionCallback& callback); 140 virtual int Flush(const CompletionCallback& callback);
143 141
144 // Returns the underlying file for testing.
145 const base::File& GetFileForTesting() const;
146
147 private: 142 private:
148 class Context; 143 class Context;
149 144
150 // Context performing I/O operations. It was extracted into a separate class 145 // Context performing I/O operations. It was extracted into a separate class
151 // to perform asynchronous operations because FileStream can be destroyed 146 // to perform asynchronous operations because FileStream can be destroyed
152 // before completion of an async operation. Also if a FileStream is destroyed 147 // before completion of an async operation. Also if a FileStream is destroyed
153 // without explicitly calling Close, the file should be closed asynchronously 148 // without explicitly calling Close, the file should be closed asynchronously
154 // without delaying FileStream's destructor. 149 // without delaying FileStream's destructor.
155 scoped_ptr<Context> context_; 150 scoped_ptr<Context> context_;
156 151
157 DISALLOW_COPY_AND_ASSIGN(FileStream); 152 DISALLOW_COPY_AND_ASSIGN(FileStream);
158 }; 153 };
159 154
160 } // namespace net 155 } // namespace net
161 156
162 #endif // NET_BASE_FILE_STREAM_H_ 157 #endif // NET_BASE_FILE_STREAM_H_
OLDNEW
« no previous file with comments | « content/browser/android/url_request_content_job.cc ('k') | net/base/file_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698