| OLD | NEW |
| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "net/base/sdch_filter.h" | 12 #include "net/base/sdch_filter.h" |
| 13 #include "net/base/sdch_manager.h" | 13 #include "net/base/sdch_manager.h" |
| 14 | 14 |
| 15 #include "sdch/open-vcdiff/src/google/vcdecoder.h" | 15 #include "sdch/open-vcdiff/src/google/vcdecoder.h" |
| 16 | 16 |
| 17 SdchFilter::SdchFilter() | 17 SdchFilter::SdchFilter(const FilterContext& filter_context) |
| 18 : decoding_status_(DECODING_UNINITIALIZED), | 18 : Filter(filter_context), |
| 19 decoding_status_(DECODING_UNINITIALIZED), |
| 19 vcdiff_streaming_decoder_(NULL), | 20 vcdiff_streaming_decoder_(NULL), |
| 20 dictionary_hash_(), | 21 dictionary_hash_(), |
| 21 dictionary_hash_is_plausible_(false), | 22 dictionary_hash_is_plausible_(false), |
| 22 dictionary_(NULL), | 23 dictionary_(NULL), |
| 23 dest_buffer_excess_(), | 24 dest_buffer_excess_(), |
| 24 dest_buffer_excess_index_(0), | 25 dest_buffer_excess_index_(0), |
| 25 source_bytes_(0), | 26 source_bytes_(0), |
| 26 output_bytes_(0), | 27 output_bytes_(0), |
| 27 possible_pass_through_(false) { | 28 possible_pass_through_(false) { |
| 28 } | 29 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 SdchManager::SdchErrorRecovery(SdchManager::PASSING_THROUGH_NON_SDCH); | 176 SdchManager::SdchErrorRecovery(SdchManager::PASSING_THROUGH_NON_SDCH); |
| 176 decoding_status_ = PASS_THROUGH; | 177 decoding_status_ = PASS_THROUGH; |
| 177 dest_buffer_excess_ = dictionary_hash_; // Send what we scanned. | 178 dest_buffer_excess_ = dictionary_hash_; // Send what we scanned. |
| 178 } else { | 179 } else { |
| 179 // We don't have the dictionary that was demanded. | 180 // We don't have the dictionary that was demanded. |
| 180 // With very low probability, random garbage data looked like a | 181 // With very low probability, random garbage data looked like a |
| 181 // dictionary specifier (8 ASCII characters followed by a null), but | 182 // dictionary specifier (8 ASCII characters followed by a null), but |
| 182 // that is sufficiently unlikely that we ignore it. | 183 // that is sufficiently unlikely that we ignore it. |
| 183 if (std::string::npos == mime_type().find_first_of("text/html")) { | 184 if (std::string::npos == mime_type().find_first_of("text/html")) { |
| 184 SdchManager::BlacklistDomainForever(url()); | 185 SdchManager::BlacklistDomainForever(url()); |
| 185 if (was_cached_) | 186 if (was_cached()) |
| 186 SdchManager::SdchErrorRecovery( | 187 SdchManager::SdchErrorRecovery( |
| 187 SdchManager::CACHED_META_REFRESH_UNSUPPORTED); | 188 SdchManager::CACHED_META_REFRESH_UNSUPPORTED); |
| 188 else | 189 else |
| 189 SdchManager::SdchErrorRecovery( | 190 SdchManager::SdchErrorRecovery( |
| 190 SdchManager::META_REFRESH_UNSUPPORTED); | 191 SdchManager::META_REFRESH_UNSUPPORTED); |
| 191 return FILTER_ERROR; | 192 return FILTER_ERROR; |
| 192 } | 193 } |
| 193 // HTML content means we can issue a meta-refresh, and get the content | 194 // HTML content means we can issue a meta-refresh, and get the content |
| 194 // again, perhaps without SDCH (to be safe). | 195 // again, perhaps without SDCH (to be safe). |
| 195 if (was_cached_) { | 196 if (was_cached()) { |
| 196 // Cached content is probably a startup tab, so we'll just get fresh | 197 // Cached content is probably a startup tab, so we'll just get fresh |
| 197 // content and try again, without disabling sdch. | 198 // content and try again, without disabling sdch. |
| 198 SdchManager::SdchErrorRecovery( | 199 SdchManager::SdchErrorRecovery( |
| 199 SdchManager::META_REFRESH_CACHED_RECOVERY); | 200 SdchManager::META_REFRESH_CACHED_RECOVERY); |
| 200 } else { | 201 } else { |
| 201 // Since it wasn't in the cache, we definately need at least some | 202 // Since it wasn't in the cache, we definately need at least some |
| 202 // period of blacklisting to get the correct content. | 203 // period of blacklisting to get the correct content. |
| 203 SdchManager::BlacklistDomain(url()); | 204 SdchManager::BlacklistDomain(url()); |
| 204 SdchManager::SdchErrorRecovery(SdchManager::META_REFRESH_RECOVERY); | 205 SdchManager::SdchErrorRecovery(SdchManager::META_REFRESH_RECOVERY); |
| 205 } | 206 } |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 memcpy(dest_buffer, dest_buffer_excess_.data() + dest_buffer_excess_index_, | 334 memcpy(dest_buffer, dest_buffer_excess_.data() + dest_buffer_excess_index_, |
| 334 amount); | 335 amount); |
| 335 dest_buffer_excess_index_ += amount; | 336 dest_buffer_excess_index_ += amount; |
| 336 if (dest_buffer_excess_.size() <= dest_buffer_excess_index_) { | 337 if (dest_buffer_excess_.size() <= dest_buffer_excess_index_) { |
| 337 DCHECK(dest_buffer_excess_.size() == dest_buffer_excess_index_); | 338 DCHECK(dest_buffer_excess_.size() == dest_buffer_excess_index_); |
| 338 dest_buffer_excess_.clear(); | 339 dest_buffer_excess_.clear(); |
| 339 dest_buffer_excess_index_ = 0; | 340 dest_buffer_excess_index_ = 0; |
| 340 } | 341 } |
| 341 return amount; | 342 return amount; |
| 342 } | 343 } |
| OLD | NEW |