OLD | NEW |
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 #ifndef NET_BASE_IO_BUFFER_H_ | 5 #ifndef NET_BASE_IO_BUFFER_H_ |
6 #define NET_BASE_IO_BUFFER_H_ | 6 #define NET_BASE_IO_BUFFER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 public: | 97 public: |
98 explicit IOBufferWithSize(int size); | 98 explicit IOBufferWithSize(int size); |
99 | 99 |
100 int size() const { return size_; } | 100 int size() const { return size_; } |
101 | 101 |
102 protected: | 102 protected: |
103 // Purpose of this constructor is to give a subclass access to the base class | 103 // Purpose of this constructor is to give a subclass access to the base class |
104 // constructor IOBuffer(char*) thus allowing subclass to use underlying | 104 // constructor IOBuffer(char*) thus allowing subclass to use underlying |
105 // memory it does not own. | 105 // memory it does not own. |
106 IOBufferWithSize(char* data, int size); | 106 IOBufferWithSize(char* data, int size); |
107 virtual ~IOBufferWithSize(); | 107 ~IOBufferWithSize() override; |
108 | 108 |
109 int size_; | 109 int size_; |
110 }; | 110 }; |
111 | 111 |
112 // This is a read only IOBuffer. The data is stored in a string and | 112 // This is a read only IOBuffer. The data is stored in a string and |
113 // the IOBuffer interface does not provide a proper way to modify it. | 113 // the IOBuffer interface does not provide a proper way to modify it. |
114 class NET_EXPORT StringIOBuffer : public IOBuffer { | 114 class NET_EXPORT StringIOBuffer : public IOBuffer { |
115 public: | 115 public: |
116 explicit StringIOBuffer(const std::string& s); | 116 explicit StringIOBuffer(const std::string& s); |
117 explicit StringIOBuffer(scoped_ptr<std::string> s); | 117 explicit StringIOBuffer(scoped_ptr<std::string> s); |
118 | 118 |
119 int size() const { return static_cast<int>(string_data_.size()); } | 119 int size() const { return static_cast<int>(string_data_.size()); } |
120 | 120 |
121 private: | 121 private: |
122 virtual ~StringIOBuffer(); | 122 ~StringIOBuffer() override; |
123 | 123 |
124 std::string string_data_; | 124 std::string string_data_; |
125 }; | 125 }; |
126 | 126 |
127 // This version wraps an existing IOBuffer and provides convenient functions | 127 // This version wraps an existing IOBuffer and provides convenient functions |
128 // to progressively read all the data. | 128 // to progressively read all the data. |
129 // | 129 // |
130 // DrainableIOBuffer is useful when you have an IOBuffer that contains data | 130 // DrainableIOBuffer is useful when you have an IOBuffer that contains data |
131 // to be written progressively, and Write() function takes an IOBuffer rather | 131 // to be written progressively, and Write() function takes an IOBuffer rather |
132 // than char*. DrainableIOBuffer can be used as follows: | 132 // than char*. DrainableIOBuffer can be used as follows: |
(...skipping 22 matching lines...) Expand all Loading... |
155 // Returns the number of consumed bytes. | 155 // Returns the number of consumed bytes. |
156 int BytesConsumed() const; | 156 int BytesConsumed() const; |
157 | 157 |
158 // Seeks to an arbitrary point in the buffer. The notion of bytes consumed | 158 // Seeks to an arbitrary point in the buffer. The notion of bytes consumed |
159 // and remaining are updated appropriately. | 159 // and remaining are updated appropriately. |
160 void SetOffset(int bytes); | 160 void SetOffset(int bytes); |
161 | 161 |
162 int size() const { return size_; } | 162 int size() const { return size_; } |
163 | 163 |
164 private: | 164 private: |
165 virtual ~DrainableIOBuffer(); | 165 ~DrainableIOBuffer() override; |
166 | 166 |
167 scoped_refptr<IOBuffer> base_; | 167 scoped_refptr<IOBuffer> base_; |
168 int size_; | 168 int size_; |
169 int used_; | 169 int used_; |
170 }; | 170 }; |
171 | 171 |
172 // This version provides a resizable buffer and a changeable offset. | 172 // This version provides a resizable buffer and a changeable offset. |
173 // | 173 // |
174 // GrowableIOBuffer is useful when you read data progressively without | 174 // GrowableIOBuffer is useful when you read data progressively without |
175 // knowing the total size in advance. GrowableIOBuffer can be used as | 175 // knowing the total size in advance. GrowableIOBuffer can be used as |
(...skipping 19 matching lines...) Expand all Loading... |
195 int capacity() { return capacity_; } | 195 int capacity() { return capacity_; } |
196 | 196 |
197 // |offset| moves the |data_| pointer, allowing "seeking" in the data. | 197 // |offset| moves the |data_| pointer, allowing "seeking" in the data. |
198 void set_offset(int offset); | 198 void set_offset(int offset); |
199 int offset() { return offset_; } | 199 int offset() { return offset_; } |
200 | 200 |
201 int RemainingCapacity(); | 201 int RemainingCapacity(); |
202 char* StartOfBuffer(); | 202 char* StartOfBuffer(); |
203 | 203 |
204 private: | 204 private: |
205 virtual ~GrowableIOBuffer(); | 205 ~GrowableIOBuffer() override; |
206 | 206 |
207 scoped_ptr<char, base::FreeDeleter> real_data_; | 207 scoped_ptr<char, base::FreeDeleter> real_data_; |
208 int capacity_; | 208 int capacity_; |
209 int offset_; | 209 int offset_; |
210 }; | 210 }; |
211 | 211 |
212 // This versions allows a pickle to be used as the storage for a write-style | 212 // This versions allows a pickle to be used as the storage for a write-style |
213 // operation, avoiding an extra data copy. | 213 // operation, avoiding an extra data copy. |
214 class NET_EXPORT PickledIOBuffer : public IOBuffer { | 214 class NET_EXPORT PickledIOBuffer : public IOBuffer { |
215 public: | 215 public: |
216 PickledIOBuffer(); | 216 PickledIOBuffer(); |
217 | 217 |
218 Pickle* pickle() { return &pickle_; } | 218 Pickle* pickle() { return &pickle_; } |
219 | 219 |
220 // Signals that we are done writing to the pickle and we can use it for a | 220 // Signals that we are done writing to the pickle and we can use it for a |
221 // write-style IO operation. | 221 // write-style IO operation. |
222 void Done(); | 222 void Done(); |
223 | 223 |
224 private: | 224 private: |
225 virtual ~PickledIOBuffer(); | 225 ~PickledIOBuffer() override; |
226 | 226 |
227 Pickle pickle_; | 227 Pickle pickle_; |
228 }; | 228 }; |
229 | 229 |
230 // This class allows the creation of a temporary IOBuffer that doesn't really | 230 // This class allows the creation of a temporary IOBuffer that doesn't really |
231 // own the underlying buffer. Please use this class only as a last resort. | 231 // own the underlying buffer. Please use this class only as a last resort. |
232 // A good example is the buffer for a synchronous operation, where we can be | 232 // A good example is the buffer for a synchronous operation, where we can be |
233 // sure that nobody is keeping an extra reference to this object so the lifetime | 233 // sure that nobody is keeping an extra reference to this object so the lifetime |
234 // of the buffer can be completely managed by its intended owner. | 234 // of the buffer can be completely managed by its intended owner. |
235 class NET_EXPORT WrappedIOBuffer : public IOBuffer { | 235 class NET_EXPORT WrappedIOBuffer : public IOBuffer { |
236 public: | 236 public: |
237 explicit WrappedIOBuffer(const char* data); | 237 explicit WrappedIOBuffer(const char* data); |
238 | 238 |
239 protected: | 239 protected: |
240 virtual ~WrappedIOBuffer(); | 240 ~WrappedIOBuffer() override; |
241 }; | 241 }; |
242 | 242 |
243 } // namespace net | 243 } // namespace net |
244 | 244 |
245 #endif // NET_BASE_IO_BUFFER_H_ | 245 #endif // NET_BASE_IO_BUFFER_H_ |
OLD | NEW |