Chromium Code Reviews| 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> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "net/base/sdch_manager.h" | 14 #include "net/base/sdch_manager.h" |
| 15 #include "net/base/sdch_net_log_params.h" | |
| 15 #include "net/url_request/url_request_context.h" | 16 #include "net/url_request/url_request_context.h" |
| 16 | 17 |
| 17 #include "sdch/open-vcdiff/src/google/vcdecoder.h" | 18 #include "sdch/open-vcdiff/src/google/vcdecoder.h" |
| 18 | 19 |
| 19 namespace net { | 20 namespace net { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 // Disambiguate various types of responses that trigger a meta-refresh, | 24 // Disambiguate various types of responses that trigger a meta-refresh, |
| 24 // failure, or fallback to pass-through. | 25 // failure, or fallback to pass-through. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 | 78 |
| 78 static int filter_use_count = 0; | 79 static int filter_use_count = 0; |
| 79 ++filter_use_count; | 80 ++filter_use_count; |
| 80 if (META_REFRESH_RECOVERY == decoding_status_) { | 81 if (META_REFRESH_RECOVERY == decoding_status_) { |
| 81 UMA_HISTOGRAM_COUNTS("Sdch3.FilterUseBeforeDisabling", filter_use_count); | 82 UMA_HISTOGRAM_COUNTS("Sdch3.FilterUseBeforeDisabling", filter_use_count); |
| 82 } | 83 } |
| 83 | 84 |
| 84 if (vcdiff_streaming_decoder_.get()) { | 85 if (vcdiff_streaming_decoder_.get()) { |
| 85 if (!vcdiff_streaming_decoder_->FinishDecoding()) { | 86 if (!vcdiff_streaming_decoder_->FinishDecoding()) { |
| 86 decoding_status_ = DECODING_ERROR; | 87 decoding_status_ = DECODING_ERROR; |
| 87 SdchManager::SdchErrorRecovery(SdchManager::INCOMPLETE_SDCH_CONTENT); | 88 LogSdchProblem(SdchManager::INCOMPLETE_SDCH_CONTENT); |
| 88 // Make it possible for the user to hit reload, and get non-sdch content. | 89 // Make it possible for the user to hit reload, and get non-sdch content. |
| 89 // Note this will "wear off" quickly enough, and is just meant to assure | 90 // Note this will "wear off" quickly enough, and is just meant to assure |
| 90 // in some rare case that the user is not stuck. | 91 // in some rare case that the user is not stuck. |
| 91 url_request_context_->sdch_manager()->BlacklistDomain( | 92 url_request_context_->sdch_manager()->BlacklistDomain( |
| 92 url_, SdchManager::INCOMPLETE_SDCH_CONTENT); | 93 url_, SdchManager::INCOMPLETE_SDCH_CONTENT); |
| 93 UMA_HISTOGRAM_COUNTS("Sdch3.PartialBytesIn", | 94 UMA_HISTOGRAM_COUNTS("Sdch3.PartialBytesIn", |
| 94 static_cast<int>(filter_context_.GetByteReadCount())); | 95 static_cast<int>(filter_context_.GetByteReadCount())); |
| 95 UMA_HISTOGRAM_COUNTS("Sdch3.PartialVcdiffIn", source_bytes_); | 96 UMA_HISTOGRAM_COUNTS("Sdch3.PartialVcdiffIn", source_bytes_); |
| 96 UMA_HISTOGRAM_COUNTS("Sdch3.PartialVcdiffOut", output_bytes_); | 97 UMA_HISTOGRAM_COUNTS("Sdch3.PartialVcdiffOut", output_bytes_); |
| 97 } | 98 } |
| 98 } | 99 } |
| 99 | 100 |
| 100 if (!dest_buffer_excess_.empty()) { | 101 if (!dest_buffer_excess_.empty()) { |
| 101 // Filter chaining error, or premature teardown. | 102 // Filter chaining error, or premature teardown. |
| 102 SdchManager::SdchErrorRecovery(SdchManager::UNFLUSHED_CONTENT); | 103 LogSdchProblem(SdchManager::UNFLUSHED_CONTENT); |
| 103 UMA_HISTOGRAM_COUNTS("Sdch3.UnflushedBytesIn", | 104 UMA_HISTOGRAM_COUNTS("Sdch3.UnflushedBytesIn", |
| 104 static_cast<int>(filter_context_.GetByteReadCount())); | 105 static_cast<int>(filter_context_.GetByteReadCount())); |
| 105 UMA_HISTOGRAM_COUNTS("Sdch3.UnflushedBufferSize", | 106 UMA_HISTOGRAM_COUNTS("Sdch3.UnflushedBufferSize", |
| 106 dest_buffer_excess_.size()); | 107 dest_buffer_excess_.size()); |
| 107 UMA_HISTOGRAM_COUNTS("Sdch3.UnflushedVcdiffIn", source_bytes_); | 108 UMA_HISTOGRAM_COUNTS("Sdch3.UnflushedVcdiffIn", source_bytes_); |
| 108 UMA_HISTOGRAM_COUNTS("Sdch3.UnflushedVcdiffOut", output_bytes_); | 109 UMA_HISTOGRAM_COUNTS("Sdch3.UnflushedVcdiffOut", output_bytes_); |
| 109 } | 110 } |
| 110 | 111 |
| 111 if (filter_context_.IsCachedContent()) { | 112 if (filter_context_.IsCachedContent()) { |
| 112 // Not a real error, but it is useful to have this tally. | 113 // Not a real error, but it is useful to have this tally. |
| 113 // TODO(jar): Remove this stat after SDCH stability is validated. | 114 // TODO(jar): Remove this stat after SDCH stability is validated. |
| 114 SdchManager::SdchErrorRecovery(SdchManager::CACHE_DECODED); | 115 LogSdchProblem(SdchManager::CACHE_DECODED); |
| 115 return; // We don't need timing stats, and we aready got ratios. | 116 return; // We don't need timing stats, and we aready got ratios. |
| 116 } | 117 } |
| 117 | 118 |
| 118 switch (decoding_status_) { | 119 switch (decoding_status_) { |
| 119 case DECODING_IN_PROGRESS: { | 120 case DECODING_IN_PROGRESS: { |
| 120 if (output_bytes_) | 121 if (output_bytes_) |
| 121 UMA_HISTOGRAM_PERCENTAGE("Sdch3.Network_Decode_Ratio_a", | 122 UMA_HISTOGRAM_PERCENTAGE("Sdch3.Network_Decode_Ratio_a", |
| 122 static_cast<int>( | 123 static_cast<int>( |
| 123 (filter_context_.GetByteReadCount() * 100) / output_bytes_)); | 124 (filter_context_.GetByteReadCount() * 100) / output_bytes_)); |
| 124 UMA_HISTOGRAM_COUNTS("Sdch3.Network_Decode_Bytes_VcdiffOut_a", | 125 UMA_HISTOGRAM_COUNTS("Sdch3.Network_Decode_Bytes_VcdiffOut_a", |
| 125 output_bytes_); | 126 output_bytes_); |
| 126 filter_context_.RecordPacketStats(FilterContext::SDCH_DECODE); | 127 filter_context_.RecordPacketStats(FilterContext::SDCH_DECODE); |
| 127 | 128 |
| 128 // Allow latency experiments to proceed. | 129 // Allow latency experiments to proceed. |
| 129 url_request_context_->sdch_manager()->SetAllowLatencyExperiment( | 130 url_request_context_->sdch_manager()->SetAllowLatencyExperiment( |
| 130 url_, true); | 131 url_, true); |
| 131 return; | 132 return; |
| 132 } | 133 } |
| 133 case PASS_THROUGH: { | 134 case PASS_THROUGH: { |
| 134 filter_context_.RecordPacketStats(FilterContext::SDCH_PASSTHROUGH); | 135 filter_context_.RecordPacketStats(FilterContext::SDCH_PASSTHROUGH); |
| 135 return; | 136 return; |
| 136 } | 137 } |
| 137 case DECODING_UNINITIALIZED: { | 138 case DECODING_UNINITIALIZED: { |
| 138 SdchManager::SdchErrorRecovery(SdchManager::UNINITIALIZED); | 139 LogSdchProblem(SdchManager::UNINITIALIZED); |
| 139 return; | 140 return; |
| 140 } | 141 } |
| 141 case WAITING_FOR_DICTIONARY_SELECTION: { | 142 case WAITING_FOR_DICTIONARY_SELECTION: { |
| 142 SdchManager::SdchErrorRecovery(SdchManager::PRIOR_TO_DICTIONARY); | 143 LogSdchProblem(SdchManager::PRIOR_TO_DICTIONARY); |
| 143 return; | 144 return; |
| 144 } | 145 } |
| 145 case DECODING_ERROR: { | 146 case DECODING_ERROR: { |
| 146 SdchManager::SdchErrorRecovery(SdchManager::DECODE_ERROR); | 147 LogSdchProblem(SdchManager::DECODE_ERROR); |
| 147 return; | 148 return; |
| 148 } | 149 } |
| 149 case META_REFRESH_RECOVERY: { | 150 case META_REFRESH_RECOVERY: { |
| 150 // Already accounted for when set. | 151 // Already accounted for when set. |
| 151 return; | 152 return; |
| 152 } | 153 } |
| 153 } // end of switch. | 154 } // end of switch. |
| 154 } | 155 } |
| 155 | 156 |
| 156 bool SdchFilter::InitDecoding(Filter::FilterType filter_type) { | 157 bool SdchFilter::InitDecoding(Filter::FilterType filter_type) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 // advertisement (so that we are sure we're not hurting anything). | 204 // advertisement (so that we are sure we're not hurting anything). |
| 204 // | 205 // |
| 205 // Watch out for an error page inserted by the proxy as part of a 40x | 206 // Watch out for an error page inserted by the proxy as part of a 40x |
| 206 // error response. When we see such content molestation, we certainly | 207 // error response. When we see such content molestation, we certainly |
| 207 // need to fall into the meta-refresh case. | 208 // need to fall into the meta-refresh case. |
| 208 ResponseCorruptionDetectionCause cause = RESPONSE_NONE; | 209 ResponseCorruptionDetectionCause cause = RESPONSE_NONE; |
| 209 if (filter_context_.GetResponseCode() == 404) { | 210 if (filter_context_.GetResponseCode() == 404) { |
| 210 // We could be more generous, but for now, only a "NOT FOUND" code will | 211 // We could be more generous, but for now, only a "NOT FOUND" code will |
| 211 // cause a pass through. All other bad codes will fall into a | 212 // cause a pass through. All other bad codes will fall into a |
| 212 // meta-refresh. | 213 // meta-refresh. |
| 213 SdchManager::SdchErrorRecovery(SdchManager::PASS_THROUGH_404_CODE); | 214 LogSdchProblem(SdchManager::PASS_THROUGH_404_CODE); |
| 214 cause = RESPONSE_404; | 215 cause = RESPONSE_404; |
| 215 decoding_status_ = PASS_THROUGH; | 216 decoding_status_ = PASS_THROUGH; |
| 216 } else if (filter_context_.GetResponseCode() != 200) { | 217 } else if (filter_context_.GetResponseCode() != 200) { |
| 217 // We need to meta-refresh, with SDCH disabled. | 218 // We need to meta-refresh, with SDCH disabled. |
| 218 cause = RESPONSE_NOT_200; | 219 cause = RESPONSE_NOT_200; |
| 219 } else if (filter_context_.IsCachedContent() | 220 } else if (filter_context_.IsCachedContent() |
| 220 && !dictionary_hash_is_plausible_) { | 221 && !dictionary_hash_is_plausible_) { |
| 221 // We must have hit the back button, and gotten content that was fetched | 222 // We must have hit the back button, and gotten content that was fetched |
| 222 // before we *really* advertised SDCH and a dictionary. | 223 // before we *really* advertised SDCH and a dictionary. |
| 223 SdchManager::SdchErrorRecovery(SdchManager::PASS_THROUGH_OLD_CACHED); | 224 LogSdchProblem(SdchManager::PASS_THROUGH_OLD_CACHED); |
| 224 decoding_status_ = PASS_THROUGH; | 225 decoding_status_ = PASS_THROUGH; |
| 225 cause = RESPONSE_OLD_UNENCODED; | 226 cause = RESPONSE_OLD_UNENCODED; |
| 226 } else if (possible_pass_through_) { | 227 } else if (possible_pass_through_) { |
| 227 // This is the potentially most graceful response. There really was no | 228 // This is the potentially most graceful response. There really was no |
| 228 // error. We were just overly cautious when we added a TENTATIVE_SDCH. | 229 // error. We were just overly cautious when we added a TENTATIVE_SDCH. |
| 229 // We added the sdch coding tag, and it should not have been added. | 230 // We added the sdch coding tag, and it should not have been added. |
| 230 // This can happen in server experiments, where the server decides | 231 // This can happen in server experiments, where the server decides |
| 231 // not to use sdch, even though there is a dictionary. To be | 232 // not to use sdch, even though there is a dictionary. To be |
| 232 // conservative, we locally added the tentative sdch (fearing that a | 233 // conservative, we locally added the tentative sdch (fearing that a |
| 233 // proxy stripped it!) and we must now recant (pass through). | 234 // proxy stripped it!) and we must now recant (pass through). |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 249 // We'll use a meta-refresh, and get content without asking for SDCH. | 250 // We'll use a meta-refresh, and get content without asking for SDCH. |
| 250 // This will also progressively disable SDCH for this domain. | 251 // This will also progressively disable SDCH for this domain. |
| 251 cause = RESPONSE_CORRUPT_SDCH; | 252 cause = RESPONSE_CORRUPT_SDCH; |
| 252 } else { | 253 } else { |
| 253 // One of the first 9 bytes precluded consideration as a hash. | 254 // One of the first 9 bytes precluded consideration as a hash. |
| 254 // This can't be an SDCH payload, even though the server said it was. | 255 // This can't be an SDCH payload, even though the server said it was. |
| 255 // This is a major error, as the server or proxy tagged this SDCH even | 256 // This is a major error, as the server or proxy tagged this SDCH even |
| 256 // though it is not! | 257 // though it is not! |
| 257 // Meta-refresh won't help, as we didn't advertise an SDCH dictionary!! | 258 // Meta-refresh won't help, as we didn't advertise an SDCH dictionary!! |
| 258 // Worse yet, meta-refresh could lead to an infinite refresh loop. | 259 // Worse yet, meta-refresh could lead to an infinite refresh loop. |
| 259 SdchManager::SdchErrorRecovery(SdchManager::PASSING_THROUGH_NON_SDCH); | 260 LogSdchProblem(SdchManager::PASSING_THROUGH_NON_SDCH); |
| 260 decoding_status_ = PASS_THROUGH; | 261 decoding_status_ = PASS_THROUGH; |
| 261 // ... but further back-off on advertising SDCH support. | 262 // ... but further back-off on advertising SDCH support. |
| 262 url_request_context_->sdch_manager()->BlacklistDomain( | 263 url_request_context_->sdch_manager()->BlacklistDomain( |
| 263 url_, SdchManager::PASSING_THROUGH_NON_SDCH); | 264 url_, SdchManager::PASSING_THROUGH_NON_SDCH); |
| 264 cause = RESPONSE_ENCODING_LIE; | 265 cause = RESPONSE_ENCODING_LIE; |
| 265 } | 266 } |
| 266 DCHECK_NE(RESPONSE_NONE, cause); | 267 DCHECK_NE(RESPONSE_NONE, cause); |
| 267 | 268 |
| 268 // Use if statement rather than ?: because UMA_HISTOGRAM_ENUMERATION | 269 // Use if statement rather than ?: because UMA_HISTOGRAM_ENUMERATION |
| 269 // caches the histogram name based on the call site. | 270 // caches the histogram name based on the call site. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 281 // This is where we try to do the expensive meta-refresh. | 282 // This is where we try to do the expensive meta-refresh. |
| 282 if (std::string::npos == mime_type_.find("text/html")) { | 283 if (std::string::npos == mime_type_.find("text/html")) { |
| 283 // Since we can't do a meta-refresh (along with an exponential | 284 // Since we can't do a meta-refresh (along with an exponential |
| 284 // backoff), we'll just make sure this NEVER happens again. | 285 // backoff), we'll just make sure this NEVER happens again. |
| 285 SdchManager::ProblemCodes problem = | 286 SdchManager::ProblemCodes problem = |
| 286 (filter_context_.IsCachedContent() ? | 287 (filter_context_.IsCachedContent() ? |
| 287 SdchManager::CACHED_META_REFRESH_UNSUPPORTED : | 288 SdchManager::CACHED_META_REFRESH_UNSUPPORTED : |
| 288 SdchManager::META_REFRESH_UNSUPPORTED); | 289 SdchManager::META_REFRESH_UNSUPPORTED); |
| 289 url_request_context_->sdch_manager()->BlacklistDomainForever( | 290 url_request_context_->sdch_manager()->BlacklistDomainForever( |
| 290 url_, problem); | 291 url_, problem); |
| 291 SdchManager::SdchErrorRecovery(problem); | 292 LogSdchProblem(problem); |
| 292 return FILTER_ERROR; | 293 return FILTER_ERROR; |
| 293 } | 294 } |
| 294 // HTML content means we can issue a meta-refresh, and get the content | 295 // HTML content means we can issue a meta-refresh, and get the content |
| 295 // again, perhaps without SDCH (to be safe). | 296 // again, perhaps without SDCH (to be safe). |
| 296 if (filter_context_.IsCachedContent()) { | 297 if (filter_context_.IsCachedContent()) { |
| 297 // Cached content is probably a startup tab, so we'll just get fresh | 298 // Cached content is probably a startup tab, so we'll just get fresh |
| 298 // content and try again, without disabling sdch. | 299 // content and try again, without disabling sdch. |
| 299 SdchManager::SdchErrorRecovery( | 300 LogSdchProblem(SdchManager::META_REFRESH_CACHED_RECOVERY); |
| 300 SdchManager::META_REFRESH_CACHED_RECOVERY); | |
| 301 } else { | 301 } else { |
| 302 // Since it wasn't in the cache, we definately need at least some | 302 // Since it wasn't in the cache, we definately need at least some |
| 303 // period of blacklisting to get the correct content. | 303 // period of blacklisting to get the correct content. |
| 304 url_request_context_->sdch_manager()->BlacklistDomain( | 304 url_request_context_->sdch_manager()->BlacklistDomain( |
| 305 url_, SdchManager::META_REFRESH_RECOVERY); | 305 url_, SdchManager::META_REFRESH_RECOVERY); |
| 306 SdchManager::SdchErrorRecovery(SdchManager::META_REFRESH_RECOVERY); | 306 LogSdchProblem(SdchManager::META_REFRESH_RECOVERY); |
| 307 } | 307 } |
| 308 decoding_status_ = META_REFRESH_RECOVERY; | 308 decoding_status_ = META_REFRESH_RECOVERY; |
| 309 // Issue a meta redirect with SDCH disabled. | 309 // Issue a meta redirect with SDCH disabled. |
| 310 dest_buffer_excess_ = kDecompressionErrorHtml; | 310 dest_buffer_excess_ = kDecompressionErrorHtml; |
| 311 } | 311 } |
| 312 } else { | 312 } else { |
| 313 DCHECK_EQ(DECODING_IN_PROGRESS, decoding_status_); | 313 DCHECK_EQ(DECODING_IN_PROGRESS, decoding_status_); |
| 314 } | 314 } |
| 315 } | 315 } |
| 316 | 316 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 bool ret = vcdiff_streaming_decoder_->DecodeChunk( | 350 bool ret = vcdiff_streaming_decoder_->DecodeChunk( |
| 351 next_stream_data_, stream_data_len_, &dest_buffer_excess_); | 351 next_stream_data_, stream_data_len_, &dest_buffer_excess_); |
| 352 // Assume all data was used in decoding. | 352 // Assume all data was used in decoding. |
| 353 next_stream_data_ = NULL; | 353 next_stream_data_ = NULL; |
| 354 source_bytes_ += stream_data_len_; | 354 source_bytes_ += stream_data_len_; |
| 355 stream_data_len_ = 0; | 355 stream_data_len_ = 0; |
| 356 output_bytes_ += dest_buffer_excess_.size(); | 356 output_bytes_ += dest_buffer_excess_.size(); |
| 357 if (!ret) { | 357 if (!ret) { |
| 358 vcdiff_streaming_decoder_.reset(NULL); // Don't call it again. | 358 vcdiff_streaming_decoder_.reset(NULL); // Don't call it again. |
| 359 decoding_status_ = DECODING_ERROR; | 359 decoding_status_ = DECODING_ERROR; |
| 360 SdchManager::SdchErrorRecovery(SdchManager::DECODE_BODY_ERROR); | 360 LogSdchProblem(SdchManager::DECODE_BODY_ERROR); |
| 361 return FILTER_ERROR; | 361 return FILTER_ERROR; |
| 362 } | 362 } |
| 363 | 363 |
| 364 amount = OutputBufferExcess(dest_buffer, available_space); | 364 amount = OutputBufferExcess(dest_buffer, available_space); |
| 365 *dest_len += amount; | 365 *dest_len += amount; |
| 366 dest_buffer += amount; | 366 dest_buffer += amount; |
| 367 available_space -= amount; | 367 available_space -= amount; |
| 368 if (0 == available_space && !dest_buffer_excess_.empty()) | 368 if (0 == available_space && !dest_buffer_excess_.empty()) |
| 369 return FILTER_OK; | 369 return FILTER_OK; |
| 370 return FILTER_NEED_MORE_DATA; | 370 return FILTER_NEED_MORE_DATA; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 389 if (stream_data_len_ > 0) | 389 if (stream_data_len_ > 0) |
| 390 next_stream_data_ += bytes_needed; | 390 next_stream_data_ += bytes_needed; |
| 391 else | 391 else |
| 392 next_stream_data_ = NULL; | 392 next_stream_data_ = NULL; |
| 393 | 393 |
| 394 DCHECK(!dictionary_.get()); | 394 DCHECK(!dictionary_.get()); |
| 395 dictionary_hash_is_plausible_ = true; // Assume plausible, but check. | 395 dictionary_hash_is_plausible_ = true; // Assume plausible, but check. |
| 396 | 396 |
| 397 if ('\0' == dictionary_hash_[kServerIdLength - 1]) { | 397 if ('\0' == dictionary_hash_[kServerIdLength - 1]) { |
| 398 SdchManager* manager(url_request_context_->sdch_manager()); | 398 SdchManager* manager(url_request_context_->sdch_manager()); |
| 399 manager->GetVcdiffDictionary( | 399 SdchManager::ProblemCodes rv = manager->GetVcdiffDictionary( |
| 400 std::string(dictionary_hash_, 0, kServerIdLength - 1), | 400 std::string(dictionary_hash_, 0, kServerIdLength - 1), |
| 401 url_, &dictionary_); | 401 url_, |
| 402 &dictionary_); | |
| 403 if (rv != SdchManager::PROBLEM_CODE_OK) | |
| 404 LogSdchProblem(rv); | |
| 402 } else { | 405 } else { |
| 403 dictionary_hash_is_plausible_ = false; | 406 dictionary_hash_is_plausible_ = false; |
| 404 } | 407 } |
| 405 | 408 |
| 406 if (!dictionary_.get()) { | 409 if (!dictionary_.get()) { |
| 407 DCHECK(dictionary_hash_.size() == kServerIdLength); | 410 DCHECK(dictionary_hash_.size() == kServerIdLength); |
| 408 // Since dictionary was not found, check to see if hash was even plausible. | 411 // Since dictionary was not found, check to see if hash was even plausible. |
| 409 for (size_t i = 0; i < kServerIdLength - 1; ++i) { | 412 for (size_t i = 0; i < kServerIdLength - 1; ++i) { |
| 410 char base64_char = dictionary_hash_[i]; | 413 char base64_char = dictionary_hash_[i]; |
| 411 if (!isalnum(base64_char) && '-' != base64_char && '_' != base64_char) { | 414 if (!isalnum(base64_char) && '-' != base64_char && '_' != base64_char) { |
| 412 dictionary_hash_is_plausible_ = false; | 415 dictionary_hash_is_plausible_ = false; |
| 413 break; | 416 break; |
| 414 } | 417 } |
| 415 } | 418 } |
| 416 if (dictionary_hash_is_plausible_) | 419 if (dictionary_hash_is_plausible_) |
| 417 SdchManager::SdchErrorRecovery(SdchManager::DICTIONARY_HASH_NOT_FOUND); | 420 LogSdchProblem(SdchManager::DICTIONARY_HASH_NOT_FOUND); |
| 418 else | 421 else |
| 419 SdchManager::SdchErrorRecovery(SdchManager::DICTIONARY_HASH_MALFORMED); | 422 LogSdchProblem(SdchManager::DICTIONARY_HASH_MALFORMED); |
| 420 decoding_status_ = DECODING_ERROR; | 423 decoding_status_ = DECODING_ERROR; |
| 421 return FILTER_ERROR; | 424 return FILTER_ERROR; |
| 422 } | 425 } |
| 423 vcdiff_streaming_decoder_.reset(new open_vcdiff::VCDiffStreamingDecoder); | 426 vcdiff_streaming_decoder_.reset(new open_vcdiff::VCDiffStreamingDecoder); |
| 424 vcdiff_streaming_decoder_->SetAllowVcdTarget(false); | 427 vcdiff_streaming_decoder_->SetAllowVcdTarget(false); |
| 425 vcdiff_streaming_decoder_->StartDecoding(dictionary_->text().data(), | 428 vcdiff_streaming_decoder_->StartDecoding(dictionary_->text().data(), |
| 426 dictionary_->text().size()); | 429 dictionary_->text().size()); |
| 427 decoding_status_ = DECODING_IN_PROGRESS; | 430 decoding_status_ = DECODING_IN_PROGRESS; |
| 428 return FILTER_OK; | 431 return FILTER_OK; |
| 429 } | 432 } |
| 430 | 433 |
| 431 int SdchFilter::OutputBufferExcess(char* const dest_buffer, | 434 int SdchFilter::OutputBufferExcess(char* const dest_buffer, |
| 432 size_t available_space) { | 435 size_t available_space) { |
| 433 if (dest_buffer_excess_.empty()) | 436 if (dest_buffer_excess_.empty()) |
| 434 return 0; | 437 return 0; |
| 435 DCHECK(dest_buffer_excess_.size() > dest_buffer_excess_index_); | 438 DCHECK(dest_buffer_excess_.size() > dest_buffer_excess_index_); |
| 436 size_t amount = std::min(available_space, | 439 size_t amount = std::min(available_space, |
| 437 dest_buffer_excess_.size() - dest_buffer_excess_index_); | 440 dest_buffer_excess_.size() - dest_buffer_excess_index_); |
| 438 memcpy(dest_buffer, dest_buffer_excess_.data() + dest_buffer_excess_index_, | 441 memcpy(dest_buffer, dest_buffer_excess_.data() + dest_buffer_excess_index_, |
| 439 amount); | 442 amount); |
| 440 dest_buffer_excess_index_ += amount; | 443 dest_buffer_excess_index_ += amount; |
| 441 if (dest_buffer_excess_.size() <= dest_buffer_excess_index_) { | 444 if (dest_buffer_excess_.size() <= dest_buffer_excess_index_) { |
| 442 DCHECK(dest_buffer_excess_.size() == dest_buffer_excess_index_); | 445 DCHECK(dest_buffer_excess_.size() == dest_buffer_excess_index_); |
| 443 dest_buffer_excess_.clear(); | 446 dest_buffer_excess_.clear(); |
| 444 dest_buffer_excess_index_ = 0; | 447 dest_buffer_excess_index_ = 0; |
| 445 } | 448 } |
| 446 return amount; | 449 return amount; |
| 447 } | 450 } |
| 448 | 451 |
| 452 void SdchFilter::LogSdchProblem(SdchManager::ProblemCodes problem) { | |
| 453 SdchManager::SdchErrorRecovery(problem); | |
| 454 // If we were just guessing, we should not display SDCH-decoding problems as | |
| 455 // errors. | |
|
Randy Smith (Not in Mondays)
2014/09/18 20:55:51
Suggestion: Move this comment to right above the !
| |
| 456 filter_context_.GetNetLog().AddEvent( | |
| 457 NetLog::TYPE_SDCH_RESOURCE_ERROR, | |
| 458 base::Bind(&NetLogSdchResourceProblemCallback, | |
| 459 problem, | |
| 460 !possible_pass_through_)); | |
|
Randy Smith (Not in Mondays)
2014/09/18 20:55:51
My read of Filter::FixupEncodingTypes() is that we
baranovich
2014/09/30 13:16:52
You're right. I removed this
| |
| 461 } | |
| 462 | |
| 449 } // namespace net | 463 } // namespace net |
| OLD | NEW |