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

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

Issue 8018: Clean up filter and content encoding handling ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month 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/gzip_filter_unittest.cc ('k') | net/base/sdch_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 <ctype.h> 5 #include <ctype.h>
6 #include <algorithm> 6 #include <algorithm>
7 7
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/histogram.h" 9 #include "base/histogram.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 11 matching lines...) Expand all
22 dest_buffer_excess_(), 22 dest_buffer_excess_(),
23 dest_buffer_excess_index_(0), 23 dest_buffer_excess_index_(0),
24 source_bytes_(0), 24 source_bytes_(0),
25 output_bytes_(0) { 25 output_bytes_(0) {
26 } 26 }
27 27
28 SdchFilter::~SdchFilter() { 28 SdchFilter::~SdchFilter() {
29 static int filter_use_count = 0; 29 static int filter_use_count = 0;
30 ++filter_use_count; 30 ++filter_use_count;
31 if (META_REFRESH_RECOVERY == decoding_status_) { 31 if (META_REFRESH_RECOVERY == decoding_status_) {
32 HISTOGRAM_COUNTS(L"Sdch.FilterUseBeforeDisabling", filter_use_count); 32 UMA_HISTOGRAM_COUNTS(L"Sdch.FilterUseBeforeDisabling", filter_use_count);
33 } 33 }
34 34
35 if (vcdiff_streaming_decoder_.get()) { 35 if (vcdiff_streaming_decoder_.get()) {
36 if (!vcdiff_streaming_decoder_->FinishDecoding()) 36 if (!vcdiff_streaming_decoder_->FinishDecoding())
37 decoding_status_ = DECODING_ERROR; 37 decoding_status_ = DECODING_ERROR;
38 } 38 }
39 39
40 // TODO(jar): Use UMA_HISTOGRAM when we turn sdch on by default. 40 UMA_HISTOGRAM_COUNTS(L"Sdch.Bytes read", source_bytes_);
41 HISTOGRAM_COUNTS(L"Sdch.Bytes read", source_bytes_); 41 UMA_HISTOGRAM_COUNTS(L"Sdch.Bytes output", output_bytes_);
42 HISTOGRAM_COUNTS(L"Sdch.Bytes output", output_bytes_);
43 42
44 if (dictionary_) 43 if (dictionary_)
45 dictionary_->Release(); 44 dictionary_->Release();
46 } 45 }
47 46
48 bool SdchFilter::InitDecoding() { 47 bool SdchFilter::InitDecoding() {
49 if (decoding_status_ != DECODING_UNINITIALIZED) 48 if (decoding_status_ != DECODING_UNINITIALIZED)
50 return false; 49 return false;
51 50
52 // Initialize decoder only after we have a dictionary in hand. 51 // Initialize decoder only after we have a dictionary in hand.
(...skipping 22 matching lines...) Expand all
75 74
76 if (WAITING_FOR_DICTIONARY_SELECTION == decoding_status_) { 75 if (WAITING_FOR_DICTIONARY_SELECTION == decoding_status_) {
77 FilterStatus status = InitializeDictionary(); 76 FilterStatus status = InitializeDictionary();
78 if (FILTER_NEED_MORE_DATA == status) 77 if (FILTER_NEED_MORE_DATA == status)
79 return FILTER_NEED_MORE_DATA; 78 return FILTER_NEED_MORE_DATA;
80 if (FILTER_ERROR == status) { 79 if (FILTER_ERROR == status) {
81 DCHECK(DECODING_ERROR == decoding_status_); 80 DCHECK(DECODING_ERROR == decoding_status_);
82 DCHECK(0 == dest_buffer_excess_index_); 81 DCHECK(0 == dest_buffer_excess_index_);
83 DCHECK(dest_buffer_excess_.empty()); 82 DCHECK(dest_buffer_excess_.empty());
84 if (!dictionary_hash_is_plausible_) { 83 if (!dictionary_hash_is_plausible_) {
84 // One of the first 9 bytes precluded consideration as a hash.
85 // This can't be an SDCH payload.
85 SdchManager::SdchErrorRecovery(SdchManager::PASSING_THROUGH_NON_SDCH); 86 SdchManager::SdchErrorRecovery(SdchManager::PASSING_THROUGH_NON_SDCH);
86 decoding_status_ = PASS_THROUGH; 87 decoding_status_ = PASS_THROUGH;
87 dest_buffer_excess_ = dictionary_hash_; // Send what we scanned. 88 dest_buffer_excess_ = dictionary_hash_; // Send what we scanned.
88 } else { 89 } else {
89 SdchManager::BlacklistDomain(url()); 90 SdchManager::BlacklistDomain(url());
90 if (std::string::npos == mime_type().find_first_of("text/html")) { 91 if (std::string::npos == mime_type().find_first_of("text/html")) {
91 SdchManager::SdchErrorRecovery(SdchManager::UNRECOVERABLE_ERROR); 92 SdchManager::SdchErrorRecovery(SdchManager::UNRECOVERABLE_ERROR);
92 return FILTER_ERROR; 93 return FILTER_ERROR;
93 } 94 }
94 SdchManager::SdchErrorRecovery(SdchManager::META_REFRESH_RECOVERY); 95 SdchManager::SdchErrorRecovery(SdchManager::META_REFRESH_RECOVERY);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 dictionary_hash_is_plausible_ = true; // Assume plausible, but check. 179 dictionary_hash_is_plausible_ = true; // Assume plausible, but check.
179 if ('\0' == dictionary_hash_[kServerIdLength - 1]) 180 if ('\0' == dictionary_hash_[kServerIdLength - 1])
180 SdchManager::Global()->GetVcdiffDictionary(std::string(dictionary_hash_, 0, 181 SdchManager::Global()->GetVcdiffDictionary(std::string(dictionary_hash_, 0,
181 kServerIdLength - 1), 182 kServerIdLength - 1),
182 url(), &dictionary_); 183 url(), &dictionary_);
183 else 184 else
184 dictionary_hash_is_plausible_ = false; 185 dictionary_hash_is_plausible_ = false;
185 186
186 if (!dictionary_) { 187 if (!dictionary_) {
187 DCHECK(dictionary_hash_.size() == kServerIdLength); 188 DCHECK(dictionary_hash_.size() == kServerIdLength);
189 // Since dictionary was not found, check to see if hash was even plausible.
188 for (size_t i = 0; i < kServerIdLength - 1; ++i) { 190 for (size_t i = 0; i < kServerIdLength - 1; ++i) {
189 char base64_char = dictionary_hash_[i]; 191 char base64_char = dictionary_hash_[i];
190 if (!isalnum(base64_char) && '-' != base64_char && '_' != base64_char) { 192 if (!isalnum(base64_char) && '-' != base64_char && '_' != base64_char) {
191 dictionary_hash_is_plausible_ = false; 193 dictionary_hash_is_plausible_ = false;
192 break; 194 break;
193 } 195 }
194 } 196 }
195 if (dictionary_hash_is_plausible_) 197 if (dictionary_hash_is_plausible_)
196 SdchManager::SdchErrorRecovery(SdchManager::DICTIONARY_HASH_NOT_FOUND); 198 SdchManager::SdchErrorRecovery(SdchManager::DICTIONARY_HASH_NOT_FOUND);
197 else 199 else
(...skipping 19 matching lines...) Expand all
217 memcpy(dest_buffer, dest_buffer_excess_.data() + dest_buffer_excess_index_, 219 memcpy(dest_buffer, dest_buffer_excess_.data() + dest_buffer_excess_index_,
218 amount); 220 amount);
219 dest_buffer_excess_index_ += amount; 221 dest_buffer_excess_index_ += amount;
220 if (dest_buffer_excess_.size() <= dest_buffer_excess_index_) { 222 if (dest_buffer_excess_.size() <= dest_buffer_excess_index_) {
221 DCHECK(dest_buffer_excess_.size() == dest_buffer_excess_index_); 223 DCHECK(dest_buffer_excess_.size() == dest_buffer_excess_index_);
222 dest_buffer_excess_.clear(); 224 dest_buffer_excess_.clear();
223 dest_buffer_excess_index_ = 0; 225 dest_buffer_excess_index_ = 0;
224 } 226 }
225 return amount; 227 return amount;
226 } 228 }
OLDNEW
« no previous file with comments | « net/base/gzip_filter_unittest.cc ('k') | net/base/sdch_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698