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

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

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

Powered by Google App Engine
This is Rietveld 408576698