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

Side by Side Diff: net/base/filter.cc

Issue 19004: Change URLRequest to use a ref-counted buffer for actual IO.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « net/base/filter.h ('k') | net/base/gzip_filter_unittest.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include "net/base/filter.h" 5 #include "net/base/filter.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "net/base/gzip_filter.h" 8 #include "net/base/gzip_filter.h"
9 #include "net/base/bzip2_filter.h" 9 #include "net/base/bzip2_filter.h"
10 #include "net/base/sdch_filter.h" 10 #include "net/base/sdch_filter.h"
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 next_filter_(NULL), 221 next_filter_(NULL),
222 last_status_(FILTER_NEED_MORE_DATA) { 222 last_status_(FILTER_NEED_MORE_DATA) {
223 } 223 }
224 224
225 Filter::~Filter() {} 225 Filter::~Filter() {}
226 226
227 bool Filter::InitBuffer(int buffer_size) { 227 bool Filter::InitBuffer(int buffer_size) {
228 if (buffer_size < 0 || stream_buffer()) 228 if (buffer_size < 0 || stream_buffer())
229 return false; 229 return false;
230 230
231 stream_buffer_.reset(new char[buffer_size]); 231 stream_buffer_ = new net::IOBuffer(buffer_size);
232 232
233 if (stream_buffer()) { 233 if (stream_buffer()) {
234 stream_buffer_size_ = buffer_size; 234 stream_buffer_size_ = buffer_size;
235 return true; 235 return true;
236 } 236 }
237 237
238 return false; 238 return false;
239 } 239 }
240 240
241 241
(...skipping 26 matching lines...) Expand all
268 268
269 Filter::FilterStatus Filter::ReadData(char* dest_buffer, int* dest_len) { 269 Filter::FilterStatus Filter::ReadData(char* dest_buffer, int* dest_len) {
270 if (last_status_ == FILTER_ERROR) 270 if (last_status_ == FILTER_ERROR)
271 return last_status_; 271 return last_status_;
272 if (!next_filter_.get()) 272 if (!next_filter_.get())
273 return last_status_ = ReadFilteredData(dest_buffer, dest_len); 273 return last_status_ = ReadFilteredData(dest_buffer, dest_len);
274 if (last_status_ == FILTER_NEED_MORE_DATA && !stream_data_len()) 274 if (last_status_ == FILTER_NEED_MORE_DATA && !stream_data_len())
275 return next_filter_->ReadData(dest_buffer, dest_len); 275 return next_filter_->ReadData(dest_buffer, dest_len);
276 if (next_filter_->last_status() == FILTER_NEED_MORE_DATA) { 276 if (next_filter_->last_status() == FILTER_NEED_MORE_DATA) {
277 // Push data into next filter's input. 277 // Push data into next filter's input.
278 char* next_buffer = next_filter_->stream_buffer(); 278 net::IOBuffer* next_buffer = next_filter_->stream_buffer();
279 int next_size = next_filter_->stream_buffer_size(); 279 int next_size = next_filter_->stream_buffer_size();
280 last_status_ = ReadFilteredData(next_buffer, &next_size); 280 last_status_ = ReadFilteredData(next_buffer->data(), &next_size);
281 next_filter_->FlushStreamBuffer(next_size); 281 next_filter_->FlushStreamBuffer(next_size);
282 switch (last_status_) { 282 switch (last_status_) {
283 case FILTER_ERROR: 283 case FILTER_ERROR:
284 return last_status_; 284 return last_status_;
285 285
286 case FILTER_NEED_MORE_DATA: 286 case FILTER_NEED_MORE_DATA:
287 return next_filter_->ReadData(dest_buffer, dest_len); 287 return next_filter_->ReadData(dest_buffer, dest_len);
288 288
289 case FILTER_OK: 289 case FILTER_OK:
290 case FILTER_DONE: 290 case FILTER_DONE:
291 break; 291 break;
292 } 292 }
293 } 293 }
294 FilterStatus status = next_filter_->ReadData(dest_buffer, dest_len); 294 FilterStatus status = next_filter_->ReadData(dest_buffer, dest_len);
295 // We could loop to fill next_filter_ if it needs data, but we have to be 295 // We could loop to fill next_filter_ if it needs data, but we have to be
296 // careful about output buffer. Simpler is to just wait until we are called 296 // careful about output buffer. Simpler is to just wait until we are called
297 // again, and return FILTER_OK. 297 // again, and return FILTER_OK.
298 return (status == FILTER_ERROR) ? FILTER_ERROR : FILTER_OK; 298 return (status == FILTER_ERROR) ? FILTER_ERROR : FILTER_OK;
299 } 299 }
300 300
301 bool Filter::FlushStreamBuffer(int stream_data_len) { 301 bool Filter::FlushStreamBuffer(int stream_data_len) {
302 if (stream_data_len <= 0 || stream_data_len > stream_buffer_size_) 302 if (stream_data_len <= 0 || stream_data_len > stream_buffer_size_)
303 return false; 303 return false;
304 304
305 // bail out if there are more data in the stream buffer to be filtered. 305 // bail out if there are more data in the stream buffer to be filtered.
306 if (!stream_buffer() || stream_data_len_) 306 if (!stream_buffer() || stream_data_len_)
307 return false; 307 return false;
308 308
309 next_stream_data_ = stream_buffer(); 309 next_stream_data_ = stream_buffer()->data();
310 stream_data_len_ = stream_data_len; 310 stream_data_len_ = stream_data_len;
311 return true; 311 return true;
312 } 312 }
313 313
314 void Filter::SetURL(const GURL& url) { 314 void Filter::SetURL(const GURL& url) {
315 url_ = url; 315 url_ = url;
316 if (next_filter_.get()) 316 if (next_filter_.get())
317 next_filter_->SetURL(url); 317 next_filter_->SetURL(url);
318 } 318 }
319 319
320 void Filter::SetMimeType(const std::string& mime_type) { 320 void Filter::SetMimeType(const std::string& mime_type) {
321 mime_type_ = mime_type; 321 mime_type_ = mime_type;
322 if (next_filter_.get()) 322 if (next_filter_.get())
323 next_filter_->SetMimeType(mime_type); 323 next_filter_->SetMimeType(mime_type);
324 } 324 }
325 325
326 void Filter::SetConnectTime(const base::Time& time, bool was_cached) { 326 void Filter::SetConnectTime(const base::Time& time, bool was_cached) {
327 connect_time_ = time; 327 connect_time_ = time;
328 was_cached_ = was_cached; 328 was_cached_ = was_cached;
329 if (next_filter_.get()) 329 if (next_filter_.get())
330 next_filter_->SetConnectTime(time, was_cached_); 330 next_filter_->SetConnectTime(time, was_cached_);
331 } 331 }
OLDNEW
« no previous file with comments | « net/base/filter.h ('k') | net/base/gzip_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698