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 #include "net/filter/sdch_filter.h" | 5 #include "net/filter/sdch_filter.h" |
6 | 6 |
7 #include <ctype.h> | 7 #include <ctype.h> |
8 #include <limits.h> | 8 #include <limits.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 } | 48 } |
49 | 49 |
50 if (vcdiff_streaming_decoder_.get()) { | 50 if (vcdiff_streaming_decoder_.get()) { |
51 if (!vcdiff_streaming_decoder_->FinishDecoding()) { | 51 if (!vcdiff_streaming_decoder_->FinishDecoding()) { |
52 decoding_status_ = DECODING_ERROR; | 52 decoding_status_ = DECODING_ERROR; |
53 SdchManager::SdchErrorRecovery(SdchManager::INCOMPLETE_SDCH_CONTENT); | 53 SdchManager::SdchErrorRecovery(SdchManager::INCOMPLETE_SDCH_CONTENT); |
54 // Make it possible for the user to hit reload, and get non-sdch content. | 54 // Make it possible for the user to hit reload, and get non-sdch content. |
55 // Note this will "wear off" quickly enough, and is just meant to assure | 55 // Note this will "wear off" quickly enough, and is just meant to assure |
56 // in some rare case that the user is not stuck. | 56 // in some rare case that the user is not stuck. |
57 url_request_context_->sdch_manager()->BlacklistDomain( | 57 url_request_context_->sdch_manager()->BlacklistDomain( |
58 url_); | 58 url_, SdchManager::INCOMPLETE_SDCH_CONTENT); |
59 UMA_HISTOGRAM_COUNTS("Sdch3.PartialBytesIn", | 59 UMA_HISTOGRAM_COUNTS("Sdch3.PartialBytesIn", |
60 static_cast<int>(filter_context_.GetByteReadCount())); | 60 static_cast<int>(filter_context_.GetByteReadCount())); |
61 UMA_HISTOGRAM_COUNTS("Sdch3.PartialVcdiffIn", source_bytes_); | 61 UMA_HISTOGRAM_COUNTS("Sdch3.PartialVcdiffIn", source_bytes_); |
62 UMA_HISTOGRAM_COUNTS("Sdch3.PartialVcdiffOut", output_bytes_); | 62 UMA_HISTOGRAM_COUNTS("Sdch3.PartialVcdiffOut", output_bytes_); |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 if (!dest_buffer_excess_.empty()) { | 66 if (!dest_buffer_excess_.empty()) { |
67 // Filter chaining error, or premature teardown. | 67 // Filter chaining error, or premature teardown. |
68 SdchManager::SdchErrorRecovery(SdchManager::UNFLUSHED_CONTENT); | 68 SdchManager::SdchErrorRecovery(SdchManager::UNFLUSHED_CONTENT); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 } else { | 211 } else { |
212 // One of the first 9 bytes precluded consideration as a hash. | 212 // One of the first 9 bytes precluded consideration as a hash. |
213 // This can't be an SDCH payload, even though the server said it was. | 213 // This can't be an SDCH payload, even though the server said it was. |
214 // This is a major error, as the server or proxy tagged this SDCH even | 214 // This is a major error, as the server or proxy tagged this SDCH even |
215 // though it is not! | 215 // though it is not! |
216 // Meta-refresh won't help, as we didn't advertise an SDCH dictionary!! | 216 // Meta-refresh won't help, as we didn't advertise an SDCH dictionary!! |
217 // Worse yet, meta-refresh could lead to an infinite refresh loop. | 217 // Worse yet, meta-refresh could lead to an infinite refresh loop. |
218 SdchManager::SdchErrorRecovery(SdchManager::PASSING_THROUGH_NON_SDCH); | 218 SdchManager::SdchErrorRecovery(SdchManager::PASSING_THROUGH_NON_SDCH); |
219 decoding_status_ = PASS_THROUGH; | 219 decoding_status_ = PASS_THROUGH; |
220 // ... but further back-off on advertising SDCH support. | 220 // ... but further back-off on advertising SDCH support. |
221 url_request_context_->sdch_manager()->BlacklistDomain(url_); | 221 url_request_context_->sdch_manager()->BlacklistDomain( |
| 222 url_, SdchManager::PASSING_THROUGH_NON_SDCH); |
222 } | 223 } |
223 | 224 |
224 if (decoding_status_ == PASS_THROUGH) { | 225 if (decoding_status_ == PASS_THROUGH) { |
225 dest_buffer_excess_ = dictionary_hash_; // Send what we scanned. | 226 dest_buffer_excess_ = dictionary_hash_; // Send what we scanned. |
226 } else { | 227 } else { |
227 // This is where we try to do the expensive meta-refresh. | 228 // This is where we try to do the expensive meta-refresh. |
228 if (std::string::npos == mime_type_.find("text/html")) { | 229 if (std::string::npos == mime_type_.find("text/html")) { |
229 // Since we can't do a meta-refresh (along with an exponential | 230 // Since we can't do a meta-refresh (along with an exponential |
230 // backoff), we'll just make sure this NEVER happens again. | 231 // backoff), we'll just make sure this NEVER happens again. |
231 url_request_context_->sdch_manager()->BlacklistDomainForever(url_); | 232 SdchManager::ProblemCodes problem = |
232 if (filter_context_.IsCachedContent()) | 233 (filter_context_.IsCachedContent() ? |
233 SdchManager::SdchErrorRecovery( | 234 SdchManager::CACHED_META_REFRESH_UNSUPPORTED : |
234 SdchManager::CACHED_META_REFRESH_UNSUPPORTED); | 235 SdchManager::META_REFRESH_UNSUPPORTED); |
235 else | 236 url_request_context_->sdch_manager()->BlacklistDomainForever( |
236 SdchManager::SdchErrorRecovery( | 237 url_, problem); |
237 SdchManager::META_REFRESH_UNSUPPORTED); | 238 SdchManager::SdchErrorRecovery(problem); |
238 return FILTER_ERROR; | 239 return FILTER_ERROR; |
239 } | 240 } |
240 // HTML content means we can issue a meta-refresh, and get the content | 241 // HTML content means we can issue a meta-refresh, and get the content |
241 // again, perhaps without SDCH (to be safe). | 242 // again, perhaps without SDCH (to be safe). |
242 if (filter_context_.IsCachedContent()) { | 243 if (filter_context_.IsCachedContent()) { |
243 // Cached content is probably a startup tab, so we'll just get fresh | 244 // Cached content is probably a startup tab, so we'll just get fresh |
244 // content and try again, without disabling sdch. | 245 // content and try again, without disabling sdch. |
245 SdchManager::SdchErrorRecovery( | 246 SdchManager::SdchErrorRecovery( |
246 SdchManager::META_REFRESH_CACHED_RECOVERY); | 247 SdchManager::META_REFRESH_CACHED_RECOVERY); |
247 } else { | 248 } else { |
248 // Since it wasn't in the cache, we definately need at least some | 249 // Since it wasn't in the cache, we definately need at least some |
249 // period of blacklisting to get the correct content. | 250 // period of blacklisting to get the correct content. |
250 url_request_context_->sdch_manager()->BlacklistDomain(url_); | 251 url_request_context_->sdch_manager()->BlacklistDomain( |
| 252 url_, SdchManager::META_REFRESH_RECOVERY); |
251 SdchManager::SdchErrorRecovery(SdchManager::META_REFRESH_RECOVERY); | 253 SdchManager::SdchErrorRecovery(SdchManager::META_REFRESH_RECOVERY); |
252 } | 254 } |
253 decoding_status_ = META_REFRESH_RECOVERY; | 255 decoding_status_ = META_REFRESH_RECOVERY; |
254 // Issue a meta redirect with SDCH disabled. | 256 // Issue a meta redirect with SDCH disabled. |
255 dest_buffer_excess_ = kDecompressionErrorHtml; | 257 dest_buffer_excess_ = kDecompressionErrorHtml; |
256 } | 258 } |
257 } else { | 259 } else { |
258 DCHECK_EQ(DECODING_IN_PROGRESS, decoding_status_); | 260 DCHECK_EQ(DECODING_IN_PROGRESS, decoding_status_); |
259 } | 261 } |
260 } | 262 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 dest_buffer_excess_index_ += amount; | 387 dest_buffer_excess_index_ += amount; |
386 if (dest_buffer_excess_.size() <= dest_buffer_excess_index_) { | 388 if (dest_buffer_excess_.size() <= dest_buffer_excess_index_) { |
387 DCHECK(dest_buffer_excess_.size() == dest_buffer_excess_index_); | 389 DCHECK(dest_buffer_excess_.size() == dest_buffer_excess_index_); |
388 dest_buffer_excess_.clear(); | 390 dest_buffer_excess_.clear(); |
389 dest_buffer_excess_index_ = 0; | 391 dest_buffer_excess_index_ = 0; |
390 } | 392 } |
391 return amount; | 393 return amount; |
392 } | 394 } |
393 | 395 |
394 } // namespace net | 396 } // namespace net |
OLD | NEW |