| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // The basic usage of the Filter interface is described in the comment at | 5 // The basic usage of the Filter interface is described in the comment at |
| 6 // the beginning of filter.h. If Filter::Factory is passed a vector of | 6 // the beginning of filter.h. If Filter::Factory is passed a vector of |
| 7 // size greater than 1, that interface is implemented by a series of filters | 7 // size greater than 1, that interface is implemented by a series of filters |
| 8 // connected in a chain. In such a case the first filter | 8 // connected in a chain. In such a case the first filter |
| 9 // in the chain proxies calls to ReadData() so that its return values | 9 // in the chain proxies calls to ReadData() so that its return values |
| 10 // apply to the entire chain. | 10 // apply to the entire chain. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 const int kFilterBufSize = 32 * 1024; | 57 const int kFilterBufSize = 32 * 1024; |
| 58 | 58 |
| 59 void LogSdchProblem(const FilterContext& filter_context, | 59 void LogSdchProblem(const FilterContext& filter_context, |
| 60 SdchProblemCode problem) { | 60 SdchProblemCode problem) { |
| 61 SdchManager::SdchErrorRecovery(problem); | 61 SdchManager::SdchErrorRecovery(problem); |
| 62 filter_context.GetNetLog().AddEvent( | 62 filter_context.GetNetLog().AddEvent( |
| 63 NetLog::TYPE_SDCH_DECODING_ERROR, | 63 NetLog::TYPE_SDCH_DECODING_ERROR, |
| 64 base::Bind(&NetLogSdchResourceProblemCallback, problem)); | 64 base::Bind(&NetLogSdchResourceProblemCallback, problem)); |
| 65 } | 65 } |
| 66 | 66 |
| 67 std::string FilterTypeAsString(Filter::FilterType type_id) { |
| 68 switch (type_id) { |
| 69 case Filter::FILTER_TYPE_DEFLATE: |
| 70 return "FILTER_TYPE_DEFLATE"; |
| 71 case Filter::FILTER_TYPE_GZIP: |
| 72 return "FILTER_TYPE_GZIP"; |
| 73 case Filter::FILTER_TYPE_GZIP_HELPING_SDCH: |
| 74 return "FILTER_TYPE_GZIP_HELPING_SDCH"; |
| 75 case Filter::FILTER_TYPE_SDCH: |
| 76 return "FILTER_TYPE_SDCH"; |
| 77 case Filter::FILTER_TYPE_SDCH_POSSIBLE : |
| 78 return "FILTER_TYPE_SDCH_POSSIBLE "; |
| 79 case Filter::FILTER_TYPE_UNSUPPORTED: |
| 80 return "FILTER_TYPE_UNSUPPORTED"; |
| 81 } |
| 82 return ""; |
| 83 } |
| 84 |
| 67 } // namespace | 85 } // namespace |
| 68 | 86 |
| 69 FilterContext::~FilterContext() { | 87 FilterContext::~FilterContext() { |
| 70 } | 88 } |
| 71 | 89 |
| 72 Filter::~Filter() {} | 90 Filter::~Filter() {} |
| 73 | 91 |
| 74 // static | 92 // static |
| 75 Filter* Filter::Factory(const std::vector<FilterType>& filter_types, | 93 Filter* Filter::Factory(const std::vector<FilterType>& filter_types, |
| 76 const FilterContext& filter_context) { | 94 const FilterContext& filter_context) { |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 // gunzip and tentative SDCH decoding. | 351 // gunzip and tentative SDCH decoding. |
| 334 // This approach nicely handles the empty() list as well, and should work with | 352 // This approach nicely handles the empty() list as well, and should work with |
| 335 // other (as yet undiscovered) proxies the choose to re-compressed with some | 353 // other (as yet undiscovered) proxies the choose to re-compressed with some |
| 336 // other encoding (such as bzip2, etc.). | 354 // other encoding (such as bzip2, etc.). |
| 337 encoding_types->insert(encoding_types->begin(), | 355 encoding_types->insert(encoding_types->begin(), |
| 338 FILTER_TYPE_GZIP_HELPING_SDCH); | 356 FILTER_TYPE_GZIP_HELPING_SDCH); |
| 339 encoding_types->insert(encoding_types->begin(), FILTER_TYPE_SDCH_POSSIBLE); | 357 encoding_types->insert(encoding_types->begin(), FILTER_TYPE_SDCH_POSSIBLE); |
| 340 return; | 358 return; |
| 341 } | 359 } |
| 342 | 360 |
| 343 Filter::Filter() | 361 std::string Filter::OrderedFilterList() const { |
| 362 if (next_filter_) { |
| 363 return FilterTypeAsString(type_id_) + "," + |
| 364 next_filter_->OrderedFilterList(); |
| 365 } else { |
| 366 return FilterTypeAsString(type_id_); |
| 367 } |
| 368 } |
| 369 |
| 370 Filter::Filter(FilterType type_id) |
| 344 : stream_buffer_(NULL), | 371 : stream_buffer_(NULL), |
| 345 stream_buffer_size_(0), | 372 stream_buffer_size_(0), |
| 346 next_stream_data_(NULL), | 373 next_stream_data_(NULL), |
| 347 stream_data_len_(0), | 374 stream_data_len_(0), |
| 348 last_status_(FILTER_NEED_MORE_DATA) {} | 375 last_status_(FILTER_NEED_MORE_DATA), |
| 376 type_id_(type_id) {} |
| 349 | 377 |
| 350 Filter::FilterStatus Filter::CopyOut(char* dest_buffer, int* dest_len) { | 378 Filter::FilterStatus Filter::CopyOut(char* dest_buffer, int* dest_len) { |
| 351 int out_len; | 379 int out_len; |
| 352 int input_len = *dest_len; | 380 int input_len = *dest_len; |
| 353 *dest_len = 0; | 381 *dest_len = 0; |
| 354 | 382 |
| 355 if (0 == stream_data_len_) | 383 if (0 == stream_data_len_) |
| 356 return Filter::FILTER_NEED_MORE_DATA; | 384 return Filter::FILTER_NEED_MORE_DATA; |
| 357 | 385 |
| 358 out_len = std::min(input_len, stream_data_len_); | 386 out_len = std::min(input_len, stream_data_len_); |
| 359 memcpy(dest_buffer, next_stream_data_, out_len); | 387 memcpy(dest_buffer, next_stream_data_, out_len); |
| 360 *dest_len += out_len; | 388 *dest_len += out_len; |
| 361 stream_data_len_ -= out_len; | 389 stream_data_len_ -= out_len; |
| 362 if (0 == stream_data_len_) { | 390 if (0 == stream_data_len_) { |
| 363 next_stream_data_ = NULL; | 391 next_stream_data_ = NULL; |
| 364 return Filter::FILTER_NEED_MORE_DATA; | 392 return Filter::FILTER_NEED_MORE_DATA; |
| 365 } else { | 393 } else { |
| 366 next_stream_data_ += out_len; | 394 next_stream_data_ += out_len; |
| 367 return Filter::FILTER_OK; | 395 return Filter::FILTER_OK; |
| 368 } | 396 } |
| 369 } | 397 } |
| 370 | 398 |
| 371 // static | 399 // static |
| 372 Filter* Filter::InitGZipFilter(FilterType type_id, int buffer_size) { | 400 Filter* Filter::InitGZipFilter(FilterType type_id, int buffer_size) { |
| 373 scoped_ptr<GZipFilter> gz_filter(new GZipFilter()); | 401 scoped_ptr<GZipFilter> gz_filter(new GZipFilter(type_id)); |
| 374 gz_filter->InitBuffer(buffer_size); | 402 gz_filter->InitBuffer(buffer_size); |
| 375 return gz_filter->InitDecoding(type_id) ? gz_filter.release() : NULL; | 403 return gz_filter->InitDecoding(type_id) ? gz_filter.release() : NULL; |
| 376 } | 404 } |
| 377 | 405 |
| 378 // static | 406 // static |
| 379 Filter* Filter::InitSdchFilter(FilterType type_id, | 407 Filter* Filter::InitSdchFilter(FilterType type_id, |
| 380 const FilterContext& filter_context, | 408 const FilterContext& filter_context, |
| 381 int buffer_size) { | 409 int buffer_size) { |
| 382 scoped_ptr<SdchFilter> sdch_filter(new SdchFilter(filter_context)); | 410 scoped_ptr<SdchFilter> sdch_filter(new SdchFilter(type_id, filter_context)); |
| 383 sdch_filter->InitBuffer(buffer_size); | 411 sdch_filter->InitBuffer(buffer_size); |
| 384 return sdch_filter->InitDecoding(type_id) ? sdch_filter.release() : NULL; | 412 return sdch_filter->InitDecoding(type_id) ? sdch_filter.release() : NULL; |
| 385 } | 413 } |
| 386 | 414 |
| 387 // static | 415 // static |
| 388 Filter* Filter::PrependNewFilter(FilterType type_id, | 416 Filter* Filter::PrependNewFilter(FilterType type_id, |
| 389 const FilterContext& filter_context, | 417 const FilterContext& filter_context, |
| 390 int buffer_size, | 418 int buffer_size, |
| 391 Filter* filter_list) { | 419 Filter* filter_list) { |
| 392 scoped_ptr<Filter> first_filter; // Soon to be start of chain. | 420 scoped_ptr<Filter> first_filter; // Soon to be start of chain. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 | 452 |
| 425 void Filter::PushDataIntoNextFilter() { | 453 void Filter::PushDataIntoNextFilter() { |
| 426 IOBuffer* next_buffer = next_filter_->stream_buffer(); | 454 IOBuffer* next_buffer = next_filter_->stream_buffer(); |
| 427 int next_size = next_filter_->stream_buffer_size(); | 455 int next_size = next_filter_->stream_buffer_size(); |
| 428 last_status_ = ReadFilteredData(next_buffer->data(), &next_size); | 456 last_status_ = ReadFilteredData(next_buffer->data(), &next_size); |
| 429 if (FILTER_ERROR != last_status_) | 457 if (FILTER_ERROR != last_status_) |
| 430 next_filter_->FlushStreamBuffer(next_size); | 458 next_filter_->FlushStreamBuffer(next_size); |
| 431 } | 459 } |
| 432 | 460 |
| 433 } // namespace net | 461 } // namespace net |
| OLD | NEW |