diff options
author | adamk@chromium.org <adamk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-16 20:14:30 +0000 |
---|---|---|
committer | adamk@chromium.org <adamk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-16 20:14:30 +0000 |
commit | 36a931cb3eae8d813424844cd2665eacaf8a636b (patch) | |
tree | 3aaa060bc074e084046adedcc786bf2b41d98733 /net | |
parent | c754c149df15538175605bbb6d70808995f1d9a9 (diff) | |
download | chromium_src-36a931cb3eae8d813424844cd2665eacaf8a636b.zip chromium_src-36a931cb3eae8d813424844cd2665eacaf8a636b.tar.gz chromium_src-36a931cb3eae8d813424844cd2665eacaf8a636b.tar.bz2 |
More cleanup in Filter/FilterContext: pass and store FilterContext only where it's used.
FilterContext is only accessed by Filter's static Factory() and FixupEncodingTypes() methods,
and GZipFilter doesn't access it at all, so there's no need for the base class to hold a
reference to it. Instead, SdchFilter holds onto the reference itself, as it's the main consumer.
I argue that this makes it more clear which code has access to the FilterContext.
R=jar@chromium.org
BUG=none
TEST=net_unittests
Review URL: http://codereview.chromium.org/6670035
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78414 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/filter.cc | 7 | ||||
-rw-r--r-- | net/base/filter.h | 9 | ||||
-rw-r--r-- | net/base/gzip_filter.cc | 5 | ||||
-rw-r--r-- | net/base/gzip_filter.h | 2 | ||||
-rw-r--r-- | net/base/sdch_filter.cc | 26 | ||||
-rw-r--r-- | net/base/sdch_filter.h | 3 |
6 files changed, 23 insertions, 29 deletions
diff --git a/net/base/filter.cc b/net/base/filter.cc index 931feac..49d9229 100644 --- a/net/base/filter.cc +++ b/net/base/filter.cc @@ -309,14 +309,13 @@ void Filter::FixupEncodingTypes( return; } -Filter::Filter(const FilterContext& filter_context) +Filter::Filter() : stream_buffer_(NULL), stream_buffer_size_(0), next_stream_data_(NULL), stream_data_len_(0), next_filter_(NULL), - last_status_(FILTER_NEED_MORE_DATA), - filter_context_(filter_context) { + last_status_(FILTER_NEED_MORE_DATA) { } Filter::FilterStatus Filter::CopyOut(char* dest_buffer, int* dest_len) { @@ -351,7 +350,7 @@ Filter* Filter::PrependNewFilter(FilterType type_id, case FILTER_TYPE_DEFLATE: case FILTER_TYPE_GZIP: { scoped_ptr<net::GZipFilter> gz_filter( - new net::GZipFilter(filter_context)); + new net::GZipFilter()); gz_filter->InitBuffer(buffer_size); if (gz_filter->InitDecoding(type_id)) { first_filter = gz_filter.release(); diff --git a/net/base/filter.h b/net/base/filter.h index 9ad86a5..4dacb64 100644 --- a/net/base/filter.h +++ b/net/base/filter.h @@ -195,7 +195,7 @@ class Filter { friend class GZipUnitTest; friend class SdchFilterChainingTest; - explicit Filter(const FilterContext& filter_context); + Filter(); // Filters the data stored in stream_buffer_ and writes the output into the // dest_buffer passed in. @@ -215,8 +215,6 @@ class Filter { FilterStatus last_status() const { return last_status_; } - const FilterContext& filter_context() const { return filter_context_; } - // Buffer to hold the data to be filtered (the input queue). scoped_refptr<net::IOBuffer> stream_buffer_; @@ -258,11 +256,6 @@ class Filter { // chained filters. FilterStatus last_status_; - // Context data from the owner of this filter. Some filters need additional - // context information (mime type, etc.) to properly function, and they access - // this data via this reference member. - const FilterContext& filter_context_; - DISALLOW_COPY_AND_ASSIGN(Filter); }; diff --git a/net/base/gzip_filter.cc b/net/base/gzip_filter.cc index daee25f..d4d72c3 100644 --- a/net/base/gzip_filter.cc +++ b/net/base/gzip_filter.cc @@ -15,9 +15,8 @@ namespace net { -GZipFilter::GZipFilter(const FilterContext& filter_context) - : Filter(filter_context), - decoding_status_(DECODING_UNINITIALIZED), +GZipFilter::GZipFilter() + : decoding_status_(DECODING_UNINITIALIZED), decoding_mode_(DECODE_MODE_UNKNOWN), gzip_header_status_(GZIP_CHECK_HEADER_IN_PROGRESS), zlib_header_added_(false), diff --git a/net/base/gzip_filter.h b/net/base/gzip_filter.h index 7496be5..2b4de11 100644 --- a/net/base/gzip_filter.h +++ b/net/base/gzip_filter.h @@ -74,7 +74,7 @@ class GZipFilter : public Filter { static const int kGZipFooterSize = 8; // Only to be instantiated by Filter::Factory. - explicit GZipFilter(const FilterContext& filter_context); + GZipFilter(); friend class Filter; // Parses and verifies the GZip header. diff --git a/net/base/sdch_filter.cc b/net/base/sdch_filter.cc index 2be75db..47325ff 100644 --- a/net/base/sdch_filter.cc +++ b/net/base/sdch_filter.cc @@ -18,7 +18,7 @@ namespace net { SdchFilter::SdchFilter(const FilterContext& filter_context) - : Filter(filter_context), + : filter_context_(filter_context), decoding_status_(DECODING_UNINITIALIZED), vcdiff_streaming_decoder_(NULL), dictionary_hash_(), @@ -54,7 +54,7 @@ SdchFilter::~SdchFilter() { // in some rare case that the user is not stuck. SdchManager::BlacklistDomain(url_); UMA_HISTOGRAM_COUNTS("Sdch3.PartialBytesIn", - static_cast<int>(filter_context().GetByteReadCount())); + static_cast<int>(filter_context_.GetByteReadCount())); UMA_HISTOGRAM_COUNTS("Sdch3.PartialVcdiffIn", source_bytes_); UMA_HISTOGRAM_COUNTS("Sdch3.PartialVcdiffOut", output_bytes_); } @@ -64,14 +64,14 @@ SdchFilter::~SdchFilter() { // Filter chaining error, or premature teardown. SdchManager::SdchErrorRecovery(SdchManager::UNFLUSHED_CONTENT); UMA_HISTOGRAM_COUNTS("Sdch3.UnflushedBytesIn", - static_cast<int>(filter_context().GetByteReadCount())); + static_cast<int>(filter_context_.GetByteReadCount())); UMA_HISTOGRAM_COUNTS("Sdch3.UnflushedBufferSize", dest_buffer_excess_.size()); UMA_HISTOGRAM_COUNTS("Sdch3.UnflushedVcdiffIn", source_bytes_); UMA_HISTOGRAM_COUNTS("Sdch3.UnflushedVcdiffOut", output_bytes_); } - if (filter_context().IsCachedContent()) { + if (filter_context_.IsCachedContent()) { // Not a real error, but it is useful to have this tally. // TODO(jar): Remove this stat after SDCH stability is validated. SdchManager::SdchErrorRecovery(SdchManager::CACHE_DECODED); @@ -83,17 +83,17 @@ SdchFilter::~SdchFilter() { if (output_bytes_) UMA_HISTOGRAM_PERCENTAGE("Sdch3.Network_Decode_Ratio_a", static_cast<int>( - (filter_context().GetByteReadCount() * 100) / output_bytes_)); + (filter_context_.GetByteReadCount() * 100) / output_bytes_)); UMA_HISTOGRAM_COUNTS("Sdch3.Network_Decode_Bytes_VcdiffOut_a", output_bytes_); - filter_context().RecordPacketStats(FilterContext::SDCH_DECODE); + filter_context_.RecordPacketStats(FilterContext::SDCH_DECODE); // Allow latency experiments to proceed. SdchManager::Global()->SetAllowLatencyExperiment(url_, true); return; } case PASS_THROUGH: { - filter_context().RecordPacketStats(FilterContext::SDCH_PASSTHROUGH); + filter_context_.RecordPacketStats(FilterContext::SDCH_PASSTHROUGH); return; } case DECODING_UNINITIALIZED: { @@ -167,15 +167,15 @@ Filter::FilterStatus SdchFilter::ReadFilteredData(char* dest_buffer, // Watch out for an error page inserted by the proxy as part of a 40x // error response. When we see such content molestation, we certainly // need to fall into the meta-refresh case. - if (filter_context().GetResponseCode() == 404) { + if (filter_context_.GetResponseCode() == 404) { // We could be more generous, but for now, only a "NOT FOUND" code will // cause a pass through. All other bad codes will fall into a // meta-refresh. SdchManager::SdchErrorRecovery(SdchManager::PASS_THROUGH_404_CODE); decoding_status_ = PASS_THROUGH; - } else if (filter_context().GetResponseCode() != 200) { + } else if (filter_context_.GetResponseCode() != 200) { // We need to meta-refresh, with SDCH disabled. - } else if (filter_context().IsCachedContent() + } else if (filter_context_.IsCachedContent() && !dictionary_hash_is_plausible_) { // We must have hit the back button, and gotten content that was fetched // before we *really* advertised SDCH and a dictionary. @@ -200,7 +200,7 @@ Filter::FilterStatus SdchFilter::ReadFilteredData(char* dest_buffer, // We need a meta-refresh since we don't have the dictionary. // The common cause is a restart of the browser, where we try to render // cached content that was saved when we had a dictionary. - } else if (filter_context().IsSdchResponse()) { + } else if (filter_context_.IsSdchResponse()) { // This is a very corrupt SDCH request response. We can't decode it. // We'll use a meta-refresh, and get content without asking for SDCH. // This will also progressively disable SDCH for this domain. @@ -225,7 +225,7 @@ Filter::FilterStatus SdchFilter::ReadFilteredData(char* dest_buffer, // Since we can't do a meta-refresh (along with an exponential // backoff), we'll just make sure this NEVER happens again. SdchManager::BlacklistDomainForever(url_); - if (filter_context().IsCachedContent()) + if (filter_context_.IsCachedContent()) SdchManager::SdchErrorRecovery( SdchManager::CACHED_META_REFRESH_UNSUPPORTED); else @@ -235,7 +235,7 @@ Filter::FilterStatus SdchFilter::ReadFilteredData(char* dest_buffer, } // HTML content means we can issue a meta-refresh, and get the content // again, perhaps without SDCH (to be safe). - if (filter_context().IsCachedContent()) { + if (filter_context_.IsCachedContent()) { // Cached content is probably a startup tab, so we'll just get fresh // content and try again, without disabling sdch. SdchManager::SdchErrorRecovery( diff --git a/net/base/sdch_filter.h b/net/base/sdch_filter.h index 451e918..33aa46e 100644 --- a/net/base/sdch_filter.h +++ b/net/base/sdch_filter.h @@ -64,6 +64,9 @@ class SdchFilter : public Filter { // specified dest_buffer. int OutputBufferExcess(char* const dest_buffer, size_t available_space); + // Context data from the owner of this filter. + const FilterContext& filter_context_; + // Tracks the status of decoding. // This variable is initialized by InitDecoding and updated only by // ReadFilteredData. |