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

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

Issue 6516025: Remove GetInputStreamBufferSize() method from FilterContext. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed signed/unsigned error Created 9 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
OLDNEW
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 #include "net/base/filter.h" 5 #include "net/base/filter.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "net/base/gzip_filter.h" 9 #include "net/base/gzip_filter.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
(...skipping 16 matching lines...) Expand all
27 const char kUncompressed[] = "uncompressed"; 27 const char kUncompressed[] = "uncompressed";
28 28
29 // Mime types: 29 // Mime types:
30 const char kApplicationXGzip[] = "application/x-gzip"; 30 const char kApplicationXGzip[] = "application/x-gzip";
31 const char kApplicationGzip[] = "application/gzip"; 31 const char kApplicationGzip[] = "application/gzip";
32 const char kApplicationXGunzip[] = "application/x-gunzip"; 32 const char kApplicationXGunzip[] = "application/x-gunzip";
33 const char kApplicationXCompress[] = "application/x-compress"; 33 const char kApplicationXCompress[] = "application/x-compress";
34 const char kApplicationCompress[] = "application/compress"; 34 const char kApplicationCompress[] = "application/compress";
35 const char kTextHtml[] = "text/html"; 35 const char kTextHtml[] = "text/html";
36 36
37 // Buffer size allocated when de-compressing data.
38 const int kFilterBufSize = 32 * 1024;
jar (doing other things) 2011/02/25 18:37:24 As per comment in filter.h: Please make this non-c
39
37 } // namespace 40 } // namespace
38 41
39 FilterContext::~FilterContext() { 42 FilterContext::~FilterContext() {
40 } 43 }
41 44
42 Filter::~Filter() {} 45 Filter::~Filter() {}
43 46
44 Filter* Filter::Factory(const std::vector<FilterType>& filter_types, 47 Filter* Filter::Factory(const std::vector<FilterType>& filter_types,
45 const FilterContext& filter_context) { 48 const FilterContext& filter_context) {
46 DCHECK_GT(filter_context.GetInputStreamBufferSize(), 0); 49 if (filter_types.empty())
47 if (filter_types.empty() || filter_context.GetInputStreamBufferSize() <= 0)
48 return NULL; 50 return NULL;
49 51
50
51 Filter* filter_list = NULL; // Linked list of filters. 52 Filter* filter_list = NULL; // Linked list of filters.
52 for (size_t i = 0; i < filter_types.size(); i++) { 53 for (size_t i = 0; i < filter_types.size(); i++) {
53 filter_list = PrependNewFilter(filter_types[i], filter_context, 54 filter_list = PrependNewFilter(filter_types[i], filter_context,
54 filter_list); 55 filter_list);
55 if (!filter_list) 56 if (!filter_list)
56 return NULL; 57 return NULL;
57 } 58 }
58 return filter_list; 59 return filter_list;
59 } 60 }
60 61
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 // This approach nicely handles the empty() list as well, and should work with 285 // This approach nicely handles the empty() list as well, and should work with
285 // other (as yet undiscovered) proxies the choose to re-compressed with some 286 // other (as yet undiscovered) proxies the choose to re-compressed with some
286 // other encoding (such as bzip2, etc.). 287 // other encoding (such as bzip2, etc.).
287 encoding_types->insert(encoding_types->begin(), 288 encoding_types->insert(encoding_types->begin(),
288 FILTER_TYPE_GZIP_HELPING_SDCH); 289 FILTER_TYPE_GZIP_HELPING_SDCH);
289 encoding_types->insert(encoding_types->begin(), FILTER_TYPE_SDCH_POSSIBLE); 290 encoding_types->insert(encoding_types->begin(), FILTER_TYPE_SDCH_POSSIBLE);
290 return; 291 return;
291 } 292 }
292 293
293 Filter::Filter(const FilterContext& filter_context) 294 Filter::Filter(const FilterContext& filter_context)
294 : stream_buffer_(NULL), 295 : stream_buffer_(new net::IOBuffer(kFilterBufSize)),
295 stream_buffer_size_(0), 296 stream_buffer_size_(kFilterBufSize),
296 next_stream_data_(NULL), 297 next_stream_data_(NULL),
297 stream_data_len_(0), 298 stream_data_len_(0),
298 next_filter_(NULL), 299 next_filter_(NULL),
299 last_status_(FILTER_NEED_MORE_DATA), 300 last_status_(FILTER_NEED_MORE_DATA),
300 filter_context_(filter_context) { 301 filter_context_(filter_context) {
301 } 302 }
302 303
303 Filter::FilterStatus Filter::ReadFilteredData(char* dest_buffer, 304 Filter::FilterStatus Filter::ReadFilteredData(char* dest_buffer,
304 int* dest_len) { 305 int* dest_len) {
305 return Filter::FILTER_ERROR; 306 return Filter::FILTER_ERROR;
(...skipping 24 matching lines...) Expand all
330 Filter* Filter::PrependNewFilter(FilterType type_id, 331 Filter* Filter::PrependNewFilter(FilterType type_id,
331 const FilterContext& filter_context, 332 const FilterContext& filter_context,
332 Filter* filter_list) { 333 Filter* filter_list) {
333 Filter* first_filter = NULL; // Soon to be start of chain. 334 Filter* first_filter = NULL; // Soon to be start of chain.
334 switch (type_id) { 335 switch (type_id) {
335 case FILTER_TYPE_GZIP_HELPING_SDCH: 336 case FILTER_TYPE_GZIP_HELPING_SDCH:
336 case FILTER_TYPE_DEFLATE: 337 case FILTER_TYPE_DEFLATE:
337 case FILTER_TYPE_GZIP: { 338 case FILTER_TYPE_GZIP: {
338 scoped_ptr<net::GZipFilter> gz_filter( 339 scoped_ptr<net::GZipFilter> gz_filter(
339 new net::GZipFilter(filter_context)); 340 new net::GZipFilter(filter_context));
340 if (gz_filter->InitBuffer()) { 341 if (gz_filter->InitDecoding(type_id)) {
341 if (gz_filter->InitDecoding(type_id)) { 342 first_filter = gz_filter.release();
342 first_filter = gz_filter.release();
343 }
344 } 343 }
345 break; 344 break;
346 } 345 }
347 case FILTER_TYPE_SDCH: 346 case FILTER_TYPE_SDCH:
348 case FILTER_TYPE_SDCH_POSSIBLE: { 347 case FILTER_TYPE_SDCH_POSSIBLE: {
349 scoped_ptr<net::SdchFilter> sdch_filter( 348 scoped_ptr<net::SdchFilter> sdch_filter(
350 new net::SdchFilter(filter_context)); 349 new net::SdchFilter(filter_context));
351 if (sdch_filter->InitBuffer()) { 350 if (sdch_filter->InitDecoding(type_id)) {
352 if (sdch_filter->InitDecoding(type_id)) { 351 first_filter = sdch_filter.release();
353 first_filter = sdch_filter.release();
354 }
355 } 352 }
356 break; 353 break;
357 } 354 }
358 default: { 355 default: {
359 break; 356 break;
360 } 357 }
361 } 358 }
362 359
363 if (!first_filter) { 360 if (!first_filter) {
364 // Cleanup and exit, since we can't construct this filter list. 361 // Cleanup and exit, since we can't construct this filter list.
365 delete filter_list; 362 delete filter_list;
366 return NULL; 363 return NULL;
367 } 364 }
368 365
369 first_filter->next_filter_.reset(filter_list); 366 first_filter->next_filter_.reset(filter_list);
370 return first_filter; 367 return first_filter;
371 } 368 }
372 369
373 bool Filter::InitBuffer() {
374 int buffer_size = filter_context_.GetInputStreamBufferSize();
375 DCHECK_GT(buffer_size, 0);
376 if (buffer_size <= 0 || stream_buffer())
377 return false;
378
379 stream_buffer_ = new net::IOBuffer(buffer_size);
380
381 if (stream_buffer()) {
382 stream_buffer_size_ = buffer_size;
383 return true;
384 }
385
386 return false;
387 }
388
389 void Filter::PushDataIntoNextFilter() { 370 void Filter::PushDataIntoNextFilter() {
390 net::IOBuffer* next_buffer = next_filter_->stream_buffer(); 371 net::IOBuffer* next_buffer = next_filter_->stream_buffer();
391 int next_size = next_filter_->stream_buffer_size(); 372 int next_size = next_filter_->stream_buffer_size();
392 last_status_ = ReadFilteredData(next_buffer->data(), &next_size); 373 last_status_ = ReadFilteredData(next_buffer->data(), &next_size);
393 if (FILTER_ERROR != last_status_) 374 if (FILTER_ERROR != last_status_)
394 next_filter_->FlushStreamBuffer(next_size); 375 next_filter_->FlushStreamBuffer(next_size);
395 } 376 }
OLDNEW
« net/base/filter.h ('K') | « net/base/filter.h ('k') | net/base/filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698