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

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

Issue 647883002: git cl format the final third of the net/base directory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 // started then an error code is returned. 43 // started then an error code is returned.
44 // 44 //
45 // Once the operation is done, |callback| will be run on the thread where 45 // Once the operation is done, |callback| will be run on the thread where
46 // Open() was called, with the result code. open_flags is a bitfield of 46 // Open() was called, with the result code. open_flags is a bitfield of
47 // base::File::Flags. 47 // base::File::Flags.
48 // 48 //
49 // If the file stream is not closed manually, the underlying file will be 49 // If the file stream is not closed manually, the underlying file will be
50 // automatically closed when FileStream is destructed in an asynchronous 50 // automatically closed when FileStream is destructed in an asynchronous
51 // manner (i.e. the file stream is closed in the background but you don't 51 // manner (i.e. the file stream is closed in the background but you don't
52 // know when). 52 // know when).
53 virtual int Open(const base::FilePath& path, int open_flags, 53 virtual int Open(const base::FilePath& path,
54 int open_flags,
54 const CompletionCallback& callback); 55 const CompletionCallback& callback);
55 56
56 // Returns ERR_IO_PENDING and closes the file asynchronously, calling 57 // Returns ERR_IO_PENDING and closes the file asynchronously, calling
57 // |callback| when done. 58 // |callback| when done.
58 // It is invalid to request any asynchronous operations while there is an 59 // It is invalid to request any asynchronous operations while there is an
59 // in-flight asynchronous operation. 60 // in-flight asynchronous operation.
60 virtual int Close(const CompletionCallback& callback); 61 virtual int Close(const CompletionCallback& callback);
61 62
62 // Returns true if Open succeeded and Close has not been called. 63 // Returns true if Open succeeded and Close has not been called.
63 virtual bool IsOpen() const; 64 virtual bool IsOpen() const;
64 65
65 // Adjust the position from where data is read asynchronously. 66 // Adjust the position from where data is read asynchronously.
66 // Upon success, ERR_IO_PENDING is returned and |callback| will be run 67 // Upon success, ERR_IO_PENDING is returned and |callback| will be run
67 // on the thread where Seek() was called with the the stream position 68 // on the thread where Seek() was called with the the stream position
68 // relative to the start of the file. Otherwise, an error code is returned. 69 // relative to the start of the file. Otherwise, an error code is returned.
69 // It is invalid to request any asynchronous operations while there is an 70 // It is invalid to request any asynchronous operations while there is an
70 // in-flight asynchronous operation. 71 // in-flight asynchronous operation.
71 virtual int Seek(base::File::Whence whence, int64 offset, 72 virtual int Seek(base::File::Whence whence,
73 int64 offset,
72 const Int64CompletionCallback& callback); 74 const Int64CompletionCallback& callback);
73 75
74 // Call this method to read data from the current stream position 76 // Call this method to read data from the current stream position
75 // asynchronously. Up to buf_len bytes will be copied into buf. (In 77 // asynchronously. Up to buf_len bytes will be copied into buf. (In
76 // other words, partial reads are allowed.) Returns the number of bytes 78 // other words, partial reads are allowed.) Returns the number of bytes
77 // copied, 0 if at end-of-file, or an error code if the operation could 79 // copied, 0 if at end-of-file, or an error code if the operation could
78 // not be performed. 80 // not be performed.
79 // 81 //
80 // The file must be opened with FLAG_ASYNC, and a non-null 82 // The file must be opened with FLAG_ASYNC, and a non-null
81 // callback must be passed to this method. If the read could not 83 // callback must be passed to this method. If the read could not
82 // complete synchronously, then ERR_IO_PENDING is returned, and the 84 // complete synchronously, then ERR_IO_PENDING is returned, and the
83 // callback will be run on the thread where Read() was called, when the 85 // callback will be run on the thread where Read() was called, when the
84 // read has completed. 86 // read has completed.
85 // 87 //
86 // It is valid to destroy or close the file stream while there is an 88 // It is valid to destroy or close the file stream while there is an
87 // asynchronous read in progress. That will cancel the read and allow 89 // asynchronous read in progress. That will cancel the read and allow
88 // the buffer to be freed. 90 // the buffer to be freed.
89 // 91 //
90 // It is invalid to request any asynchronous operations while there is an 92 // It is invalid to request any asynchronous operations while there is an
91 // in-flight asynchronous operation. 93 // in-flight asynchronous operation.
92 // 94 //
93 // This method must not be called if the stream was opened WRITE_ONLY. 95 // This method must not be called if the stream was opened WRITE_ONLY.
94 virtual int Read(IOBuffer* buf, int buf_len, 96 virtual int Read(IOBuffer* buf,
97 int buf_len,
95 const CompletionCallback& callback); 98 const CompletionCallback& callback);
96 99
97 // Call this method to write data at the current stream position 100 // Call this method to write data at the current stream position
98 // asynchronously. Up to buf_len bytes will be written from buf. (In 101 // asynchronously. Up to buf_len bytes will be written from buf. (In
99 // other words, partial writes are allowed.) Returns the number of 102 // other words, partial writes are allowed.) Returns the number of
100 // bytes written, or an error code if the operation could not be 103 // bytes written, or an error code if the operation could not be
101 // performed. 104 // performed.
102 // 105 //
103 // The file must be opened with FLAG_ASYNC, and a non-null 106 // The file must be opened with FLAG_ASYNC, and a non-null
104 // callback must be passed to this method. If the write could not 107 // callback must be passed to this method. If the write could not
105 // complete synchronously, then ERR_IO_PENDING is returned, and the 108 // complete synchronously, then ERR_IO_PENDING is returned, and the
106 // callback will be run on the thread where Write() was called when 109 // callback will be run on the thread where Write() was called when
107 // the write has completed. 110 // the write has completed.
108 // 111 //
109 // It is valid to destroy or close the file stream while there is an 112 // It is valid to destroy or close the file stream while there is an
110 // asynchronous write in progress. That will cancel the write and allow 113 // asynchronous write in progress. That will cancel the write and allow
111 // the buffer to be freed. 114 // the buffer to be freed.
112 // 115 //
113 // It is invalid to request any asynchronous operations while there is an 116 // It is invalid to request any asynchronous operations while there is an
114 // in-flight asynchronous operation. 117 // in-flight asynchronous operation.
115 // 118 //
116 // This method must not be called if the stream was opened READ_ONLY. 119 // This method must not be called if the stream was opened READ_ONLY.
117 // 120 //
118 // Zero byte writes are not allowed. 121 // Zero byte writes are not allowed.
119 virtual int Write(IOBuffer* buf, int buf_len, 122 virtual int Write(IOBuffer* buf,
123 int buf_len,
120 const CompletionCallback& callback); 124 const CompletionCallback& callback);
121 125
122 // Forces out a filesystem sync on this file to make sure that the file was 126 // Forces out a filesystem sync on this file to make sure that the file was
123 // written out to disk and is not currently sitting in the buffer. This does 127 // written out to disk and is not currently sitting in the buffer. This does
124 // not have to be called, it just forces one to happen at the time of 128 // not have to be called, it just forces one to happen at the time of
125 // calling. 129 // calling.
126 // 130 //
127 // The file must be opened with FLAG_ASYNC, and a non-null 131 // The file must be opened with FLAG_ASYNC, and a non-null
128 // callback must be passed to this method. If the write could not 132 // callback must be passed to this method. If the write could not
129 // complete synchronously, then ERR_IO_PENDING is returned, and the 133 // complete synchronously, then ERR_IO_PENDING is returned, and the
(...skipping 22 matching lines...) Expand all
152 // without explicitly calling Close, the file should be closed asynchronously 156 // without explicitly calling Close, the file should be closed asynchronously
153 // without delaying FileStream's destructor. 157 // without delaying FileStream's destructor.
154 scoped_ptr<Context> context_; 158 scoped_ptr<Context> context_;
155 159
156 DISALLOW_COPY_AND_ASSIGN(FileStream); 160 DISALLOW_COPY_AND_ASSIGN(FileStream);
157 }; 161 };
158 162
159 } // namespace net 163 } // namespace net
160 164
161 #endif // NET_BASE_FILE_STREAM_H_ 165 #endif // NET_BASE_FILE_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698