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

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

Issue 155064: Merge r18936.... (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/branches/172/src/
Patch Set: Created 11 years, 5 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
« 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')
Property Changes:
Modified: svn:mergeinfo
Merged /trunk/src/net/base/sdch_filter.cc:r14162,15308,16015,16808,17560,18936
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 <limits.h> 5 #include <limits.h>
6 #include <ctype.h> 6 #include <ctype.h>
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/histogram.h" 10 #include "base/histogram.h"
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 223
224 if (WAITING_FOR_DICTIONARY_SELECTION == decoding_status_) { 224 if (WAITING_FOR_DICTIONARY_SELECTION == decoding_status_) {
225 FilterStatus status = InitializeDictionary(); 225 FilterStatus status = InitializeDictionary();
226 if (FILTER_NEED_MORE_DATA == status) 226 if (FILTER_NEED_MORE_DATA == status)
227 return FILTER_NEED_MORE_DATA; 227 return FILTER_NEED_MORE_DATA;
228 if (FILTER_ERROR == status) { 228 if (FILTER_ERROR == status) {
229 DCHECK(DECODING_ERROR == decoding_status_); 229 DCHECK(DECODING_ERROR == decoding_status_);
230 DCHECK(0 == dest_buffer_excess_index_); 230 DCHECK(0 == dest_buffer_excess_index_);
231 DCHECK(dest_buffer_excess_.empty()); 231 DCHECK(dest_buffer_excess_.empty());
232 // This is where we try very hard to do error recovery, and make this 232 // This is where we try very hard to do error recovery, and make this
233 // protocol robust in teh face of proxies that do many different things. 233 // protocol robust in the face of proxies that do many different things.
234 // If we decide that things are looking very bad (too hard to recover), 234 // If we decide that things are looking very bad (too hard to recover),
235 // we may even issue a "meta-refresh" to reload the page without an SDCH 235 // we may even issue a "meta-refresh" to reload the page without an SDCH
236 // advertisement (so that we are sure we're not hurting anything). First 236 // advertisement (so that we are sure we're not hurting anything).
237 // we try for some light weight recovery, and teh final else clause below
238 // supports the last ditch meta-refresh approach.
239 // 237 //
240 // Watch out for an error page inserted by the proxy as part of a 40x 238 // Watch out for an error page inserted by the proxy as part of a 40x
241 // error response. When we see such content molestation, we certainly 239 // error response. When we see such content molestation, we certainly
242 // need to fall into the meta-refresh case. 240 // need to fall into the meta-refresh case.
243 bool successful_response = filter_context().GetResponseCode() == 200; 241 bool successful_response = filter_context().GetResponseCode() == 200;
244 if (possible_pass_through_ && successful_response) { 242 if (filter_context().GetResponseCode() == 404) {
245 // This is the most graceful response. There really was no error. We 243 // We could be more generous, but for now, only a "NOT FOUND" code will
246 // were just overly cautious. 244 // cause a pass through. All other codes will fall into a meta-refresh
245 // attempt.
246 SdchManager::SdchErrorRecovery(SdchManager::PASS_THROUGH_404_CODE);
247 decoding_status_ = PASS_THROUGH;
248 } else if (possible_pass_through_ && successful_response) {
249 // This is the potentially most graceful response. There really was no
250 // error. We were just overly cautious when we added a TENTATIVE_SDCH.
247 // We added the sdch coding tag, and it should not have been added. 251 // We added the sdch coding tag, and it should not have been added.
248 // This can happen in server experiments, where the server decides 252 // This can happen in server experiments, where the server decides
249 // not to use sdch, even though there is a dictionary. To be 253 // not to use sdch, even though there is a dictionary. To be
250 // conservative, we locally added the tentative sdch (fearing that a 254 // conservative, we locally added the tentative sdch (fearing that a
251 // proxy stripped it!) and we must now recant (pass through). 255 // proxy stripped it!) and we must now recant (pass through).
252 SdchManager::SdchErrorRecovery(SdchManager::DISCARD_TENTATIVE_SDCH); 256 SdchManager::SdchErrorRecovery(SdchManager::DISCARD_TENTATIVE_SDCH);
253 decoding_status_ = PASS_THROUGH; 257 // However.... just to be sure we don't get burned by proxies that
254 dest_buffer_excess_ = dictionary_hash_; // Send what we scanned. 258 // re-compress with gzip or other system, we can sniff to see if this
259 // is compressed data etc. For now, we do nothing, which gets us into
260 // the meta-refresh result.
261 // TODO(jar): Improve robustness by sniffing for valid text that we can
262 // actual use re: decoding_status_ = PASS_THROUGH;
255 } else if (successful_response && !dictionary_hash_is_plausible_) { 263 } else if (successful_response && !dictionary_hash_is_plausible_) {
256 // One of the first 9 bytes precluded consideration as a hash. 264 // One of the first 9 bytes precluded consideration as a hash.
257 // This can't be an SDCH payload, even though the server said it was. 265 // This can't be an SDCH payload, even though the server said it was.
258 // This is a major error, as the server or proxy tagged this SDCH even 266 // This is a major error, as the server or proxy tagged this SDCH even
259 // though it is not! 267 // though it is not!
260 // The good news is that error recovery is clear...
261 SdchManager::SdchErrorRecovery(SdchManager::PASSING_THROUGH_NON_SDCH); 268 SdchManager::SdchErrorRecovery(SdchManager::PASSING_THROUGH_NON_SDCH);
269 // Meta-refresh won't help... we didn't advertise an SDCH dictionary!!
262 decoding_status_ = PASS_THROUGH; 270 decoding_status_ = PASS_THROUGH;
271 }
272
273 if (decoding_status_ == PASS_THROUGH) {
263 dest_buffer_excess_ = dictionary_hash_; // Send what we scanned. 274 dest_buffer_excess_ = dictionary_hash_; // Send what we scanned.
264 } else { 275 } else {
265 // This is where we try to do the expensive meta-refresh. 276 // This is where we try to do the expensive meta-refresh.
266 // Either this was an error response (probably an error page inserted
267 // by a proxy, as in bug 8916) or else we don't have the dictionary that
268 // was demanded.
269 // With very low probability, random garbage data looked like a
270 // dictionary specifier (8 ASCII characters followed by a null), but
271 // that is sufficiently unlikely that we ignore it.
272 if (std::string::npos == mime_type_.find("text/html")) { 277 if (std::string::npos == mime_type_.find("text/html")) {
273 // Since we can't do a meta-refresh (along with an exponential 278 // Since we can't do a meta-refresh (along with an exponential
274 // backoff), we'll just make sure this NEVER happens again. 279 // backoff), we'll just make sure this NEVER happens again.
275 SdchManager::BlacklistDomainForever(url_); 280 SdchManager::BlacklistDomainForever(url_);
276 if (was_cached_) 281 if (was_cached_)
277 SdchManager::SdchErrorRecovery( 282 SdchManager::SdchErrorRecovery(
278 SdchManager::CACHED_META_REFRESH_UNSUPPORTED); 283 SdchManager::CACHED_META_REFRESH_UNSUPPORTED);
279 else 284 else
280 SdchManager::SdchErrorRecovery( 285 SdchManager::SdchErrorRecovery(
281 SdchManager::META_REFRESH_UNSUPPORTED); 286 SdchManager::META_REFRESH_UNSUPPORTED);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 memcpy(dest_buffer, dest_buffer_excess_.data() + dest_buffer_excess_index_, 431 memcpy(dest_buffer, dest_buffer_excess_.data() + dest_buffer_excess_index_,
427 amount); 432 amount);
428 dest_buffer_excess_index_ += amount; 433 dest_buffer_excess_index_ += amount;
429 if (dest_buffer_excess_.size() <= dest_buffer_excess_index_) { 434 if (dest_buffer_excess_.size() <= dest_buffer_excess_index_) {
430 DCHECK(dest_buffer_excess_.size() == dest_buffer_excess_index_); 435 DCHECK(dest_buffer_excess_.size() == dest_buffer_excess_index_);
431 dest_buffer_excess_.clear(); 436 dest_buffer_excess_.clear();
432 dest_buffer_excess_index_ = 0; 437 dest_buffer_excess_index_ = 0;
433 } 438 }
434 return amount; 439 return amount;
435 } 440 }
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