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 "base/values.h" | |
14 #include "net/base/sdch_manager.h" | 15 #include "net/base/sdch_manager.h" |
16 #include "net/base/sdch_net_log_params.h" | |
15 #include "net/url_request/url_request_context.h" | 17 #include "net/url_request/url_request_context.h" |
16 | 18 |
17 #include "sdch/open-vcdiff/src/google/vcdecoder.h" | 19 #include "sdch/open-vcdiff/src/google/vcdecoder.h" |
18 | 20 |
19 namespace net { | 21 namespace net { |
20 | 22 |
21 namespace { | 23 namespace { |
22 | 24 |
23 // Disambiguate various types of responses that trigger a meta-refresh, | 25 // Disambiguate various types of responses that trigger a meta-refresh, |
24 // failure, or fallback to pass-through. | 26 // failure, or fallback to pass-through. |
(...skipping 18 matching lines...) Expand all Loading... | |
43 // Not an SDCH response but should be. | 45 // Not an SDCH response but should be. |
44 RESPONSE_CORRUPT_SDCH = 6, | 46 RESPONSE_CORRUPT_SDCH = 6, |
45 | 47 |
46 // No dictionary was advertised with the request, the server claims | 48 // No dictionary was advertised with the request, the server claims |
47 // to have encoded with SDCH anyway, but it isn't an SDCH response. | 49 // to have encoded with SDCH anyway, but it isn't an SDCH response. |
48 RESPONSE_ENCODING_LIE = 7, | 50 RESPONSE_ENCODING_LIE = 7, |
49 | 51 |
50 RESPONSE_MAX, | 52 RESPONSE_MAX, |
51 }; | 53 }; |
52 | 54 |
55 const char* ResponseCorruptionDetectionCauseToString( | |
56 ResponseCorruptionDetectionCause cause) { | |
57 switch (cause) { | |
58 case RESPONSE_NONE: | |
59 return "NONE"; | |
60 case RESPONSE_404: | |
61 return "404"; | |
62 case RESPONSE_NOT_200: | |
63 return "NOT_200"; | |
64 case RESPONSE_OLD_UNENCODED: | |
65 return "OLD_UNENCODED"; | |
66 case RESPONSE_TENTATIVE_SDCH: | |
67 return "TENTATIVE_SDCH"; | |
68 case RESPONSE_NO_DICTIONARY: | |
69 return "NO_DICTIONARY"; | |
70 case RESPONSE_CORRUPT_SDCH: | |
71 return "CORRUPT_SDCH"; | |
72 case RESPONSE_ENCODING_LIE: | |
73 return "ENCODING_LIE"; | |
74 default: | |
75 return "<unknown>"; | |
mmenke
2014/11/03 21:01:04
If you remove the default case, and move the retur
baranovich
2014/11/03 22:34:23
Done.
| |
76 } | |
77 } | |
78 | |
79 base::Value* NetLogSdchResponseCorruptionDetectionCallback( | |
80 ResponseCorruptionDetectionCause cause, | |
81 bool cached, | |
82 NetLog::LogLevel log_level) { | |
83 base::DictionaryValue* dict = new base::DictionaryValue(); | |
84 dict->SetString("cause", ResponseCorruptionDetectionCauseToString(cause)); | |
85 dict->SetBoolean("cached", cached); | |
86 dict->SetInteger("net_error", ERR_FAILED); | |
87 return dict; | |
88 } | |
89 | |
53 } // namespace | 90 } // namespace |
54 | 91 |
55 SdchFilter::SdchFilter(const FilterContext& filter_context) | 92 SdchFilter::SdchFilter(const FilterContext& filter_context) |
56 : filter_context_(filter_context), | 93 : filter_context_(filter_context), |
57 decoding_status_(DECODING_UNINITIALIZED), | 94 decoding_status_(DECODING_UNINITIALIZED), |
58 dictionary_hash_(), | 95 dictionary_hash_(), |
59 dictionary_hash_is_plausible_(false), | 96 dictionary_hash_is_plausible_(false), |
60 dictionary_(NULL), | 97 dictionary_(NULL), |
61 url_request_context_(filter_context.GetURLRequestContext()), | 98 url_request_context_(filter_context.GetURLRequestContext()), |
62 dest_buffer_excess_(), | 99 dest_buffer_excess_(), |
(...skipping 14 matching lines...) Expand all Loading... | |
77 | 114 |
78 static int filter_use_count = 0; | 115 static int filter_use_count = 0; |
79 ++filter_use_count; | 116 ++filter_use_count; |
80 if (META_REFRESH_RECOVERY == decoding_status_) { | 117 if (META_REFRESH_RECOVERY == decoding_status_) { |
81 UMA_HISTOGRAM_COUNTS("Sdch3.FilterUseBeforeDisabling", filter_use_count); | 118 UMA_HISTOGRAM_COUNTS("Sdch3.FilterUseBeforeDisabling", filter_use_count); |
82 } | 119 } |
83 | 120 |
84 if (vcdiff_streaming_decoder_.get()) { | 121 if (vcdiff_streaming_decoder_.get()) { |
85 if (!vcdiff_streaming_decoder_->FinishDecoding()) { | 122 if (!vcdiff_streaming_decoder_->FinishDecoding()) { |
86 decoding_status_ = DECODING_ERROR; | 123 decoding_status_ = DECODING_ERROR; |
87 SdchManager::SdchErrorRecovery(SdchManager::INCOMPLETE_SDCH_CONTENT); | 124 LogSdchProblem(SDCH_INCOMPLETE_SDCH_CONTENT); |
88 // Make it possible for the user to hit reload, and get non-sdch content. | 125 // 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 | 126 // Note this will "wear off" quickly enough, and is just meant to assure |
90 // in some rare case that the user is not stuck. | 127 // in some rare case that the user is not stuck. |
91 url_request_context_->sdch_manager()->BlacklistDomain( | 128 url_request_context_->sdch_manager()->BlacklistDomain( |
92 url_, SdchManager::INCOMPLETE_SDCH_CONTENT); | 129 url_, SDCH_INCOMPLETE_SDCH_CONTENT); |
93 UMA_HISTOGRAM_COUNTS("Sdch3.PartialBytesIn", | 130 UMA_HISTOGRAM_COUNTS("Sdch3.PartialBytesIn", |
94 static_cast<int>(filter_context_.GetByteReadCount())); | 131 static_cast<int>(filter_context_.GetByteReadCount())); |
95 UMA_HISTOGRAM_COUNTS("Sdch3.PartialVcdiffIn", source_bytes_); | 132 UMA_HISTOGRAM_COUNTS("Sdch3.PartialVcdiffIn", source_bytes_); |
96 UMA_HISTOGRAM_COUNTS("Sdch3.PartialVcdiffOut", output_bytes_); | 133 UMA_HISTOGRAM_COUNTS("Sdch3.PartialVcdiffOut", output_bytes_); |
97 } | 134 } |
98 } | 135 } |
99 | 136 |
100 if (!dest_buffer_excess_.empty()) { | 137 if (!dest_buffer_excess_.empty()) { |
101 // Filter chaining error, or premature teardown. | 138 // Filter chaining error, or premature teardown. |
102 SdchManager::SdchErrorRecovery(SdchManager::UNFLUSHED_CONTENT); | 139 LogSdchProblem(SDCH_UNFLUSHED_CONTENT); |
103 UMA_HISTOGRAM_COUNTS("Sdch3.UnflushedBytesIn", | 140 UMA_HISTOGRAM_COUNTS("Sdch3.UnflushedBytesIn", |
104 static_cast<int>(filter_context_.GetByteReadCount())); | 141 static_cast<int>(filter_context_.GetByteReadCount())); |
105 UMA_HISTOGRAM_COUNTS("Sdch3.UnflushedBufferSize", | 142 UMA_HISTOGRAM_COUNTS("Sdch3.UnflushedBufferSize", |
106 dest_buffer_excess_.size()); | 143 dest_buffer_excess_.size()); |
107 UMA_HISTOGRAM_COUNTS("Sdch3.UnflushedVcdiffIn", source_bytes_); | 144 UMA_HISTOGRAM_COUNTS("Sdch3.UnflushedVcdiffIn", source_bytes_); |
108 UMA_HISTOGRAM_COUNTS("Sdch3.UnflushedVcdiffOut", output_bytes_); | 145 UMA_HISTOGRAM_COUNTS("Sdch3.UnflushedVcdiffOut", output_bytes_); |
109 } | 146 } |
110 | 147 |
111 if (filter_context_.IsCachedContent()) { | 148 if (filter_context_.IsCachedContent()) { |
112 // Not a real error, but it is useful to have this tally. | 149 // Not a real error, but it is useful to have this tally. |
113 // TODO(jar): Remove this stat after SDCH stability is validated. | 150 // TODO(jar): Remove this stat after SDCH stability is validated. |
114 SdchManager::SdchErrorRecovery(SdchManager::CACHE_DECODED); | 151 LogSdchProblem(SDCH_CACHE_DECODED); |
115 return; // We don't need timing stats, and we aready got ratios. | 152 return; // We don't need timing stats, and we aready got ratios. |
116 } | 153 } |
117 | 154 |
118 switch (decoding_status_) { | 155 switch (decoding_status_) { |
119 case DECODING_IN_PROGRESS: { | 156 case DECODING_IN_PROGRESS: { |
120 if (output_bytes_) | 157 if (output_bytes_) |
121 UMA_HISTOGRAM_PERCENTAGE("Sdch3.Network_Decode_Ratio_a", | 158 UMA_HISTOGRAM_PERCENTAGE("Sdch3.Network_Decode_Ratio_a", |
122 static_cast<int>( | 159 static_cast<int>( |
123 (filter_context_.GetByteReadCount() * 100) / output_bytes_)); | 160 (filter_context_.GetByteReadCount() * 100) / output_bytes_)); |
124 UMA_HISTOGRAM_COUNTS("Sdch3.Network_Decode_Bytes_VcdiffOut_a", | 161 UMA_HISTOGRAM_COUNTS("Sdch3.Network_Decode_Bytes_VcdiffOut_a", |
125 output_bytes_); | 162 output_bytes_); |
126 filter_context_.RecordPacketStats(FilterContext::SDCH_DECODE); | 163 filter_context_.RecordPacketStats(FilterContext::SDCH_DECODE); |
127 | 164 |
128 // Allow latency experiments to proceed. | 165 // Allow latency experiments to proceed. |
129 url_request_context_->sdch_manager()->SetAllowLatencyExperiment( | 166 url_request_context_->sdch_manager()->SetAllowLatencyExperiment( |
130 url_, true); | 167 url_, true); |
131 return; | 168 return; |
132 } | 169 } |
133 case PASS_THROUGH: { | 170 case PASS_THROUGH: { |
134 filter_context_.RecordPacketStats(FilterContext::SDCH_PASSTHROUGH); | 171 filter_context_.RecordPacketStats(FilterContext::SDCH_PASSTHROUGH); |
135 return; | 172 return; |
136 } | 173 } |
137 case DECODING_UNINITIALIZED: { | 174 case DECODING_UNINITIALIZED: { |
138 SdchManager::SdchErrorRecovery(SdchManager::UNINITIALIZED); | 175 LogSdchProblem(SDCH_UNINITIALIZED); |
139 return; | 176 return; |
140 } | 177 } |
141 case WAITING_FOR_DICTIONARY_SELECTION: { | 178 case WAITING_FOR_DICTIONARY_SELECTION: { |
142 SdchManager::SdchErrorRecovery(SdchManager::PRIOR_TO_DICTIONARY); | 179 LogSdchProblem(SDCH_PRIOR_TO_DICTIONARY); |
143 return; | 180 return; |
144 } | 181 } |
145 case DECODING_ERROR: { | 182 case DECODING_ERROR: { |
146 SdchManager::SdchErrorRecovery(SdchManager::DECODE_ERROR); | 183 LogSdchProblem(SDCH_DECODE_ERROR); |
147 return; | 184 return; |
148 } | 185 } |
149 case META_REFRESH_RECOVERY: { | 186 case META_REFRESH_RECOVERY: { |
150 // Already accounted for when set. | 187 // Already accounted for when set. |
151 return; | 188 return; |
152 } | 189 } |
153 } // end of switch. | 190 } // end of switch. |
154 } | 191 } |
155 | 192 |
156 bool SdchFilter::InitDecoding(Filter::FilterType filter_type) { | 193 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). | 240 // advertisement (so that we are sure we're not hurting anything). |
204 // | 241 // |
205 // Watch out for an error page inserted by the proxy as part of a 40x | 242 // 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 | 243 // error response. When we see such content molestation, we certainly |
207 // need to fall into the meta-refresh case. | 244 // need to fall into the meta-refresh case. |
208 ResponseCorruptionDetectionCause cause = RESPONSE_NONE; | 245 ResponseCorruptionDetectionCause cause = RESPONSE_NONE; |
209 if (filter_context_.GetResponseCode() == 404) { | 246 if (filter_context_.GetResponseCode() == 404) { |
210 // We could be more generous, but for now, only a "NOT FOUND" code will | 247 // 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 | 248 // cause a pass through. All other bad codes will fall into a |
212 // meta-refresh. | 249 // meta-refresh. |
213 SdchManager::SdchErrorRecovery(SdchManager::PASS_THROUGH_404_CODE); | 250 LogSdchProblem(SDCH_PASS_THROUGH_404_CODE); |
214 cause = RESPONSE_404; | 251 cause = RESPONSE_404; |
215 decoding_status_ = PASS_THROUGH; | 252 decoding_status_ = PASS_THROUGH; |
216 } else if (filter_context_.GetResponseCode() != 200) { | 253 } else if (filter_context_.GetResponseCode() != 200) { |
217 // We need to meta-refresh, with SDCH disabled. | 254 // We need to meta-refresh, with SDCH disabled. |
218 cause = RESPONSE_NOT_200; | 255 cause = RESPONSE_NOT_200; |
219 } else if (filter_context_.IsCachedContent() | 256 } else if (filter_context_.IsCachedContent() |
220 && !dictionary_hash_is_plausible_) { | 257 && !dictionary_hash_is_plausible_) { |
221 // We must have hit the back button, and gotten content that was fetched | 258 // We must have hit the back button, and gotten content that was fetched |
222 // before we *really* advertised SDCH and a dictionary. | 259 // before we *really* advertised SDCH and a dictionary. |
223 SdchManager::SdchErrorRecovery(SdchManager::PASS_THROUGH_OLD_CACHED); | 260 LogSdchProblem(SDCH_PASS_THROUGH_OLD_CACHED); |
224 decoding_status_ = PASS_THROUGH; | 261 decoding_status_ = PASS_THROUGH; |
225 cause = RESPONSE_OLD_UNENCODED; | 262 cause = RESPONSE_OLD_UNENCODED; |
226 } else if (possible_pass_through_) { | 263 } else if (possible_pass_through_) { |
227 // This is the potentially most graceful response. There really was no | 264 // This is the potentially most graceful response. There really was no |
228 // error. We were just overly cautious when we added a TENTATIVE_SDCH. | 265 // 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. | 266 // We added the sdch coding tag, and it should not have been added. |
230 // This can happen in server experiments, where the server decides | 267 // This can happen in server experiments, where the server decides |
231 // not to use sdch, even though there is a dictionary. To be | 268 // not to use sdch, even though there is a dictionary. To be |
232 // conservative, we locally added the tentative sdch (fearing that a | 269 // conservative, we locally added the tentative sdch (fearing that a |
233 // proxy stripped it!) and we must now recant (pass through). | 270 // 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. | 286 // We'll use a meta-refresh, and get content without asking for SDCH. |
250 // This will also progressively disable SDCH for this domain. | 287 // This will also progressively disable SDCH for this domain. |
251 cause = RESPONSE_CORRUPT_SDCH; | 288 cause = RESPONSE_CORRUPT_SDCH; |
252 } else { | 289 } else { |
253 // One of the first 9 bytes precluded consideration as a hash. | 290 // 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. | 291 // 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 | 292 // This is a major error, as the server or proxy tagged this SDCH even |
256 // though it is not! | 293 // though it is not! |
257 // Meta-refresh won't help, as we didn't advertise an SDCH dictionary!! | 294 // 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. | 295 // Worse yet, meta-refresh could lead to an infinite refresh loop. |
259 SdchManager::SdchErrorRecovery(SdchManager::PASSING_THROUGH_NON_SDCH); | 296 LogSdchProblem(SDCH_PASSING_THROUGH_NON_SDCH); |
260 decoding_status_ = PASS_THROUGH; | 297 decoding_status_ = PASS_THROUGH; |
261 // ... but further back-off on advertising SDCH support. | 298 // ... but further back-off on advertising SDCH support. |
262 url_request_context_->sdch_manager()->BlacklistDomain( | 299 url_request_context_->sdch_manager()->BlacklistDomain( |
263 url_, SdchManager::PASSING_THROUGH_NON_SDCH); | 300 url_, SDCH_PASSING_THROUGH_NON_SDCH); |
264 cause = RESPONSE_ENCODING_LIE; | 301 cause = RESPONSE_ENCODING_LIE; |
265 } | 302 } |
266 DCHECK_NE(RESPONSE_NONE, cause); | 303 DCHECK_NE(RESPONSE_NONE, cause); |
267 | 304 |
268 // Use if statement rather than ?: because UMA_HISTOGRAM_ENUMERATION | 305 // Use if statement rather than ?: because UMA_HISTOGRAM_ENUMERATION |
269 // caches the histogram name based on the call site. | 306 // caches the histogram name based on the call site. |
270 if (filter_context_.IsCachedContent()) { | 307 if (filter_context_.IsCachedContent()) { |
271 UMA_HISTOGRAM_ENUMERATION( | 308 UMA_HISTOGRAM_ENUMERATION( |
272 "Sdch3.ResponseCorruptionDetection.Cached", cause, RESPONSE_MAX); | 309 "Sdch3.ResponseCorruptionDetection.Cached", cause, RESPONSE_MAX); |
273 } else { | 310 } else { |
274 UMA_HISTOGRAM_ENUMERATION( | 311 UMA_HISTOGRAM_ENUMERATION( |
275 "Sdch3.ResponseCorruptionDetection.Uncached", cause, RESPONSE_MAX); | 312 "Sdch3.ResponseCorruptionDetection.Uncached", cause, RESPONSE_MAX); |
276 } | 313 } |
314 filter_context_.GetNetLog().AddEvent( | |
315 NetLog::TYPE_SDCH_RESPONSE_CORRUPTION_DETECTION, | |
316 base::Bind(&NetLogSdchResponseCorruptionDetectionCallback, | |
317 cause, | |
318 filter_context_.IsCachedContent())); | |
277 | 319 |
278 if (decoding_status_ == PASS_THROUGH) { | 320 if (decoding_status_ == PASS_THROUGH) { |
279 dest_buffer_excess_ = dictionary_hash_; // Send what we scanned. | 321 dest_buffer_excess_ = dictionary_hash_; // Send what we scanned. |
280 } else { | 322 } else { |
281 // This is where we try to do the expensive meta-refresh. | 323 // This is where we try to do the expensive meta-refresh. |
282 if (std::string::npos == mime_type_.find("text/html")) { | 324 if (std::string::npos == mime_type_.find("text/html")) { |
283 // Since we can't do a meta-refresh (along with an exponential | 325 // Since we can't do a meta-refresh (along with an exponential |
284 // backoff), we'll just make sure this NEVER happens again. | 326 // backoff), we'll just make sure this NEVER happens again. |
285 SdchManager::ProblemCodes problem = | 327 SdchProblemCode problem = (filter_context_.IsCachedContent() |
286 (filter_context_.IsCachedContent() ? | 328 ? SDCH_CACHED_META_REFRESH_UNSUPPORTED |
287 SdchManager::CACHED_META_REFRESH_UNSUPPORTED : | 329 : SDCH_META_REFRESH_UNSUPPORTED); |
288 SdchManager::META_REFRESH_UNSUPPORTED); | |
289 url_request_context_->sdch_manager()->BlacklistDomainForever( | 330 url_request_context_->sdch_manager()->BlacklistDomainForever( |
290 url_, problem); | 331 url_, problem); |
291 SdchManager::SdchErrorRecovery(problem); | 332 LogSdchProblem(problem); |
292 return FILTER_ERROR; | 333 return FILTER_ERROR; |
293 } | 334 } |
294 // HTML content means we can issue a meta-refresh, and get the content | 335 // HTML content means we can issue a meta-refresh, and get the content |
295 // again, perhaps without SDCH (to be safe). | 336 // again, perhaps without SDCH (to be safe). |
296 if (filter_context_.IsCachedContent()) { | 337 if (filter_context_.IsCachedContent()) { |
297 // Cached content is probably a startup tab, so we'll just get fresh | 338 // Cached content is probably a startup tab, so we'll just get fresh |
298 // content and try again, without disabling sdch. | 339 // content and try again, without disabling sdch. |
299 SdchManager::SdchErrorRecovery( | 340 LogSdchProblem(SDCH_META_REFRESH_CACHED_RECOVERY); |
300 SdchManager::META_REFRESH_CACHED_RECOVERY); | |
301 } else { | 341 } else { |
302 // Since it wasn't in the cache, we definately need at least some | 342 // Since it wasn't in the cache, we definately need at least some |
303 // period of blacklisting to get the correct content. | 343 // period of blacklisting to get the correct content. |
304 url_request_context_->sdch_manager()->BlacklistDomain( | 344 url_request_context_->sdch_manager()->BlacklistDomain( |
305 url_, SdchManager::META_REFRESH_RECOVERY); | 345 url_, SDCH_META_REFRESH_RECOVERY); |
306 SdchManager::SdchErrorRecovery(SdchManager::META_REFRESH_RECOVERY); | 346 LogSdchProblem(SDCH_META_REFRESH_RECOVERY); |
307 } | 347 } |
308 decoding_status_ = META_REFRESH_RECOVERY; | 348 decoding_status_ = META_REFRESH_RECOVERY; |
309 // Issue a meta redirect with SDCH disabled. | 349 // Issue a meta redirect with SDCH disabled. |
310 dest_buffer_excess_ = kDecompressionErrorHtml; | 350 dest_buffer_excess_ = kDecompressionErrorHtml; |
311 } | 351 } |
312 } else { | 352 } else { |
313 DCHECK_EQ(DECODING_IN_PROGRESS, decoding_status_); | 353 DCHECK_EQ(DECODING_IN_PROGRESS, decoding_status_); |
314 } | 354 } |
315 } | 355 } |
316 | 356 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 bool ret = vcdiff_streaming_decoder_->DecodeChunk( | 390 bool ret = vcdiff_streaming_decoder_->DecodeChunk( |
351 next_stream_data_, stream_data_len_, &dest_buffer_excess_); | 391 next_stream_data_, stream_data_len_, &dest_buffer_excess_); |
352 // Assume all data was used in decoding. | 392 // Assume all data was used in decoding. |
353 next_stream_data_ = NULL; | 393 next_stream_data_ = NULL; |
354 source_bytes_ += stream_data_len_; | 394 source_bytes_ += stream_data_len_; |
355 stream_data_len_ = 0; | 395 stream_data_len_ = 0; |
356 output_bytes_ += dest_buffer_excess_.size(); | 396 output_bytes_ += dest_buffer_excess_.size(); |
357 if (!ret) { | 397 if (!ret) { |
358 vcdiff_streaming_decoder_.reset(NULL); // Don't call it again. | 398 vcdiff_streaming_decoder_.reset(NULL); // Don't call it again. |
359 decoding_status_ = DECODING_ERROR; | 399 decoding_status_ = DECODING_ERROR; |
360 SdchManager::SdchErrorRecovery(SdchManager::DECODE_BODY_ERROR); | 400 LogSdchProblem(SDCH_DECODE_BODY_ERROR); |
361 return FILTER_ERROR; | 401 return FILTER_ERROR; |
362 } | 402 } |
363 | 403 |
364 amount = OutputBufferExcess(dest_buffer, available_space); | 404 amount = OutputBufferExcess(dest_buffer, available_space); |
365 *dest_len += amount; | 405 *dest_len += amount; |
366 dest_buffer += amount; | 406 dest_buffer += amount; |
367 available_space -= amount; | 407 available_space -= amount; |
368 if (0 == available_space && !dest_buffer_excess_.empty()) | 408 if (0 == available_space && !dest_buffer_excess_.empty()) |
369 return FILTER_OK; | 409 return FILTER_OK; |
370 return FILTER_NEED_MORE_DATA; | 410 return FILTER_NEED_MORE_DATA; |
(...skipping 16 matching lines...) Expand all Loading... | |
387 stream_data_len_ -= bytes_needed; | 427 stream_data_len_ -= bytes_needed; |
388 DCHECK_LE(0, stream_data_len_); | 428 DCHECK_LE(0, stream_data_len_); |
389 if (stream_data_len_ > 0) | 429 if (stream_data_len_ > 0) |
390 next_stream_data_ += bytes_needed; | 430 next_stream_data_ += bytes_needed; |
391 else | 431 else |
392 next_stream_data_ = NULL; | 432 next_stream_data_ = NULL; |
393 | 433 |
394 DCHECK(!dictionary_.get()); | 434 DCHECK(!dictionary_.get()); |
395 dictionary_hash_is_plausible_ = true; // Assume plausible, but check. | 435 dictionary_hash_is_plausible_ = true; // Assume plausible, but check. |
396 | 436 |
437 SdchProblemCode rv = SDCH_OK; | |
397 if ('\0' == dictionary_hash_[kServerIdLength - 1]) { | 438 if ('\0' == dictionary_hash_[kServerIdLength - 1]) { |
398 SdchManager* manager(url_request_context_->sdch_manager()); | 439 SdchManager* manager(url_request_context_->sdch_manager()); |
399 manager->GetVcdiffDictionary( | 440 rv = manager->GetVcdiffDictionary( |
400 std::string(dictionary_hash_, 0, kServerIdLength - 1), | 441 std::string(dictionary_hash_, 0, kServerIdLength - 1), |
401 url_, &dictionary_); | 442 url_, |
443 &dictionary_); | |
444 if (rv != SDCH_OK) { | |
445 if (rv == SDCH_DICTIONARY_HASH_NOT_FOUND) { | |
446 DCHECK(dictionary_hash_.size() == kServerIdLength); | |
447 // Since dictionary was not found, check to see if hash was even | |
448 // plausible. | |
449 for (size_t i = 0; i < kServerIdLength - 1; ++i) { | |
450 char base64_char = dictionary_hash_[i]; | |
451 if (!isalnum(base64_char) && '-' != base64_char && | |
452 '_' != base64_char) { | |
453 rv = SDCH_DICTIONARY_HASH_MALFORMED; | |
454 dictionary_hash_is_plausible_ = false; | |
455 break; | |
456 } | |
457 } | |
458 } | |
459 } | |
402 } else { | 460 } else { |
403 dictionary_hash_is_plausible_ = false; | 461 dictionary_hash_is_plausible_ = false; |
462 rv = SDCH_DICTIONARY_HASH_MALFORMED; | |
404 } | 463 } |
405 | 464 if (rv != SDCH_OK) { |
406 if (!dictionary_.get()) { | 465 LogSdchProblem(rv); |
407 DCHECK(dictionary_hash_.size() == kServerIdLength); | |
408 // Since dictionary was not found, check to see if hash was even plausible. | |
409 for (size_t i = 0; i < kServerIdLength - 1; ++i) { | |
410 char base64_char = dictionary_hash_[i]; | |
411 if (!isalnum(base64_char) && '-' != base64_char && '_' != base64_char) { | |
412 dictionary_hash_is_plausible_ = false; | |
413 break; | |
414 } | |
415 } | |
416 if (dictionary_hash_is_plausible_) | |
417 SdchManager::SdchErrorRecovery(SdchManager::DICTIONARY_HASH_NOT_FOUND); | |
418 else | |
419 SdchManager::SdchErrorRecovery(SdchManager::DICTIONARY_HASH_MALFORMED); | |
420 decoding_status_ = DECODING_ERROR; | 466 decoding_status_ = DECODING_ERROR; |
421 return FILTER_ERROR; | 467 return FILTER_ERROR; |
422 } | 468 } |
469 DCHECK(dictionary_.get()); | |
423 vcdiff_streaming_decoder_.reset(new open_vcdiff::VCDiffStreamingDecoder); | 470 vcdiff_streaming_decoder_.reset(new open_vcdiff::VCDiffStreamingDecoder); |
424 vcdiff_streaming_decoder_->SetAllowVcdTarget(false); | 471 vcdiff_streaming_decoder_->SetAllowVcdTarget(false); |
425 vcdiff_streaming_decoder_->StartDecoding(dictionary_->text().data(), | 472 vcdiff_streaming_decoder_->StartDecoding(dictionary_->text().data(), |
426 dictionary_->text().size()); | 473 dictionary_->text().size()); |
427 decoding_status_ = DECODING_IN_PROGRESS; | 474 decoding_status_ = DECODING_IN_PROGRESS; |
428 return FILTER_OK; | 475 return FILTER_OK; |
429 } | 476 } |
430 | 477 |
431 int SdchFilter::OutputBufferExcess(char* const dest_buffer, | 478 int SdchFilter::OutputBufferExcess(char* const dest_buffer, |
432 size_t available_space) { | 479 size_t available_space) { |
433 if (dest_buffer_excess_.empty()) | 480 if (dest_buffer_excess_.empty()) |
434 return 0; | 481 return 0; |
435 DCHECK(dest_buffer_excess_.size() > dest_buffer_excess_index_); | 482 DCHECK(dest_buffer_excess_.size() > dest_buffer_excess_index_); |
436 size_t amount = std::min(available_space, | 483 size_t amount = std::min(available_space, |
437 dest_buffer_excess_.size() - dest_buffer_excess_index_); | 484 dest_buffer_excess_.size() - dest_buffer_excess_index_); |
438 memcpy(dest_buffer, dest_buffer_excess_.data() + dest_buffer_excess_index_, | 485 memcpy(dest_buffer, dest_buffer_excess_.data() + dest_buffer_excess_index_, |
439 amount); | 486 amount); |
440 dest_buffer_excess_index_ += amount; | 487 dest_buffer_excess_index_ += amount; |
441 if (dest_buffer_excess_.size() <= dest_buffer_excess_index_) { | 488 if (dest_buffer_excess_.size() <= dest_buffer_excess_index_) { |
442 DCHECK(dest_buffer_excess_.size() == dest_buffer_excess_index_); | 489 DCHECK(dest_buffer_excess_.size() == dest_buffer_excess_index_); |
443 dest_buffer_excess_.clear(); | 490 dest_buffer_excess_.clear(); |
444 dest_buffer_excess_index_ = 0; | 491 dest_buffer_excess_index_ = 0; |
445 } | 492 } |
446 return amount; | 493 return amount; |
447 } | 494 } |
448 | 495 |
496 void SdchFilter::LogSdchProblem(SdchProblemCode problem) { | |
497 SdchManager::SdchErrorRecovery(problem); | |
498 filter_context_.GetNetLog().AddEvent( | |
499 NetLog::TYPE_SDCH_DECODING_ERROR, | |
500 base::Bind(&NetLogSdchResourceProblemCallback, problem)); | |
501 } | |
502 | |
449 } // namespace net | 503 } // namespace net |
OLD | NEW |