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

Side by Side Diff: net/filter/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/filter.h ('k') | net/filter/mock_filter_context.h » ('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 // The basic usage of the Filter interface is described in the comment at 5 // The basic usage of the Filter interface is described in the comment at
6 // the beginning of filter.h. If Filter::Factory is passed a vector of 6 // the beginning of filter.h. If Filter::Factory is passed a vector of
7 // size greater than 1, that interface is implemented by a series of filters 7 // size greater than 1, that interface is implemented by a series of filters
8 // connected in a chain. In such a case the first filter 8 // connected in a chain. In such a case the first filter
9 // in the chain proxies calls to ReadData() so that its return values 9 // in the chain proxies calls to ReadData() so that its return values
10 // apply to the entire chain. 10 // apply to the entire chain.
(...skipping 10 matching lines...) Expand all
21 // next filter needs it, a return value of FILTER_NEED_MORE_DATA from the 21 // next filter needs it, a return value of FILTER_NEED_MORE_DATA from the
22 // final filter will apply to the entire chain. 22 // final filter will apply to the entire chain.
23 23
24 #include "net/filter/filter.h" 24 #include "net/filter/filter.h"
25 25
26 #include "base/files/file_path.h" 26 #include "base/files/file_path.h"
27 #include "base/strings/string_util.h" 27 #include "base/strings/string_util.h"
28 #include "net/base/filename_util_unsafe.h" 28 #include "net/base/filename_util_unsafe.h"
29 #include "net/base/io_buffer.h" 29 #include "net/base/io_buffer.h"
30 #include "net/base/mime_util.h" 30 #include "net/base/mime_util.h"
31 #include "net/base/sdch_net_log_params.h"
31 #include "net/filter/gzip_filter.h" 32 #include "net/filter/gzip_filter.h"
32 #include "net/filter/sdch_filter.h" 33 #include "net/filter/sdch_filter.h"
33 #include "net/url_request/url_request_context.h" 34 #include "net/url_request/url_request_context.h"
34 #include "url/gurl.h" 35 #include "url/gurl.h"
35 36
37 namespace net {
38
36 namespace { 39 namespace {
37 40
38 // Filter types (using canonical lower case only): 41 // Filter types (using canonical lower case only):
39 const char kDeflate[] = "deflate"; 42 const char kDeflate[] = "deflate";
40 const char kGZip[] = "gzip"; 43 const char kGZip[] = "gzip";
41 const char kXGZip[] = "x-gzip"; 44 const char kXGZip[] = "x-gzip";
42 const char kSdch[] = "sdch"; 45 const char kSdch[] = "sdch";
43 // compress and x-compress are currently not supported. If we decide to support 46 // compress and x-compress are currently not supported. If we decide to support
44 // them, we'll need the same mime type compatibility hack we have for gzip. For 47 // them, we'll need the same mime type compatibility hack we have for gzip. For
45 // more information, see Firefox's nsHttpChannel::ProcessNormal. 48 // more information, see Firefox's nsHttpChannel::ProcessNormal.
46 49
47 // Mime types: 50 // Mime types:
48 const char kApplicationXGzip[] = "application/x-gzip"; 51 const char kApplicationXGzip[] = "application/x-gzip";
49 const char kApplicationGzip[] = "application/gzip"; 52 const char kApplicationGzip[] = "application/gzip";
50 const char kApplicationXGunzip[] = "application/x-gunzip"; 53 const char kApplicationXGunzip[] = "application/x-gunzip";
51 const char kTextHtml[] = "text/html"; 54 const char kTextHtml[] = "text/html";
52 55
53 // Buffer size allocated when de-compressing data. 56 // Buffer size allocated when de-compressing data.
54 const int kFilterBufSize = 32 * 1024; 57 const int kFilterBufSize = 32 * 1024;
55 58
59 void LogSdchProblem(const FilterContext& filter_context,
60 SdchProblemCode problem) {
61 SdchManager::SdchErrorRecovery(problem);
62 filter_context.GetNetLog().AddEvent(
63 NetLog::TYPE_SDCH_DECODING_ERROR,
64 base::Bind(&NetLogSdchResourceProblemCallback, problem));
65 }
66
56 } // namespace 67 } // namespace
57 68
58 namespace net {
59
60 FilterContext::~FilterContext() { 69 FilterContext::~FilterContext() {
61 } 70 }
62 71
63 Filter::~Filter() {} 72 Filter::~Filter() {}
64 73
65 // static 74 // static
66 Filter* Filter::Factory(const std::vector<FilterType>& filter_types, 75 Filter* Filter::Factory(const std::vector<FilterType>& filter_types,
67 const FilterContext& filter_context) { 76 const FilterContext& filter_context) {
68 if (filter_types.empty()) 77 if (filter_types.empty())
69 return NULL; 78 return NULL;
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 !IsSupportedMimeType(mime_type)) 235 !IsSupportedMimeType(mime_type))
227 encoding_types->clear(); 236 encoding_types->clear();
228 } 237 }
229 } 238 }
230 239
231 // If the request was for SDCH content, then we might need additional fixups. 240 // If the request was for SDCH content, then we might need additional fixups.
232 if (!filter_context.SdchResponseExpected()) { 241 if (!filter_context.SdchResponseExpected()) {
233 // It was not an SDCH request, so we'll just record stats. 242 // It was not an SDCH request, so we'll just record stats.
234 if (1 < encoding_types->size()) { 243 if (1 < encoding_types->size()) {
235 // Multiple filters were intended to only be used for SDCH (thus far!) 244 // Multiple filters were intended to only be used for SDCH (thus far!)
236 SdchManager::SdchErrorRecovery( 245 LogSdchProblem(filter_context, SDCH_MULTIENCODING_FOR_NON_SDCH_REQUEST);
237 SdchManager::MULTIENCODING_FOR_NON_SDCH_REQUEST);
238 } 246 }
239 if ((1 == encoding_types->size()) && 247 if ((1 == encoding_types->size()) &&
240 (FILTER_TYPE_SDCH == encoding_types->front())) { 248 (FILTER_TYPE_SDCH == encoding_types->front())) {
241 SdchManager::SdchErrorRecovery( 249 LogSdchProblem(filter_context,
242 SdchManager::SDCH_CONTENT_ENCODE_FOR_NON_SDCH_REQUEST); 250 SDCH_SDCH_CONTENT_ENCODE_FOR_NON_SDCH_REQUEST);
243 } 251 }
244 return; 252 return;
245 } 253 }
246 254
247 // The request was tagged as an SDCH request, which means the server supplied 255 // The request was tagged as an SDCH request, which means the server supplied
248 // a dictionary, and we advertised it in the request. Some proxies will do 256 // a dictionary, and we advertised it in the request. Some proxies will do
249 // very strange things to the request, or the response, so we have to handle 257 // very strange things to the request, or the response, so we have to handle
250 // them gracefully. 258 // them gracefully.
251 259
252 // If content encoding included SDCH, then everything is "relatively" fine. 260 // If content encoding included SDCH, then everything is "relatively" fine.
253 if (!encoding_types->empty() && 261 if (!encoding_types->empty() &&
254 (FILTER_TYPE_SDCH == encoding_types->front())) { 262 (FILTER_TYPE_SDCH == encoding_types->front())) {
255 // Some proxies (found currently in Argentina) strip the Content-Encoding 263 // Some proxies (found currently in Argentina) strip the Content-Encoding
256 // text from "sdch,gzip" to a mere "sdch" without modifying the compressed 264 // text from "sdch,gzip" to a mere "sdch" without modifying the compressed
257 // payload. To handle this gracefully, we simulate the "probably" deleted 265 // payload. To handle this gracefully, we simulate the "probably" deleted
258 // ",gzip" by appending a tentative gzip decode, which will default to a 266 // ",gzip" by appending a tentative gzip decode, which will default to a
259 // no-op pass through filter if it doesn't get gzip headers where expected. 267 // no-op pass through filter if it doesn't get gzip headers where expected.
260 if (1 == encoding_types->size()) { 268 if (1 == encoding_types->size()) {
261 encoding_types->push_back(FILTER_TYPE_GZIP_HELPING_SDCH); 269 encoding_types->push_back(FILTER_TYPE_GZIP_HELPING_SDCH);
262 SdchManager::SdchErrorRecovery( 270 LogSdchProblem(filter_context, SDCH_OPTIONAL_GUNZIP_ENCODING_ADDED);
263 SdchManager::OPTIONAL_GUNZIP_ENCODING_ADDED);
264 } 271 }
265 return; 272 return;
266 } 273 }
267 274
268 // There are now several cases to handle for an SDCH request. Foremost, if 275 // There are now several cases to handle for an SDCH request. Foremost, if
269 // the outbound request was stripped so as not to advertise support for 276 // the outbound request was stripped so as not to advertise support for
270 // encodings, we might get back content with no encoding, or (for example) 277 // encodings, we might get back content with no encoding, or (for example)
271 // just gzip. We have to be sure that any changes we make allow for such 278 // just gzip. We have to be sure that any changes we make allow for such
272 // minimal coding to work. That issue is why we use TENTATIVE filters if we 279 // minimal coding to work. That issue is why we use TENTATIVE filters if we
273 // add any, as those filters sniff the content, and act as pass-through 280 // add any, as those filters sniff the content, and act as pass-through
(...skipping 13 matching lines...) Expand all
287 // The one unresolved failure mode comes when we advertise a dictionary, and 294 // The one unresolved failure mode comes when we advertise a dictionary, and
288 // the server tries to *send* a gzipped file (not gzip encode content), and 295 // the server tries to *send* a gzipped file (not gzip encode content), and
289 // then we could do a gzip decode :-(. Since SDCH is only (currently) 296 // then we could do a gzip decode :-(. Since SDCH is only (currently)
290 // supported server side on paths that only send HTML content, this mode has 297 // supported server side on paths that only send HTML content, this mode has
291 // never surfaced in the wild (and is unlikely to). 298 // never surfaced in the wild (and is unlikely to).
292 // We will gather a lot of stats as we perform the fixups 299 // We will gather a lot of stats as we perform the fixups
293 if (StartsWithASCII(mime_type, kTextHtml, false)) { 300 if (StartsWithASCII(mime_type, kTextHtml, false)) {
294 // Suspicious case: Advertised dictionary, but server didn't use sdch, and 301 // Suspicious case: Advertised dictionary, but server didn't use sdch, and
295 // we're HTML tagged. 302 // we're HTML tagged.
296 if (encoding_types->empty()) { 303 if (encoding_types->empty()) {
297 SdchManager::SdchErrorRecovery( 304 LogSdchProblem(filter_context, SDCH_ADDED_CONTENT_ENCODING);
298 SdchManager::ADDED_CONTENT_ENCODING);
299 } else if (1 == encoding_types->size()) { 305 } else if (1 == encoding_types->size()) {
300 SdchManager::SdchErrorRecovery( 306 LogSdchProblem(filter_context, SDCH_FIXED_CONTENT_ENCODING);
301 SdchManager::FIXED_CONTENT_ENCODING);
302 } else { 307 } else {
303 SdchManager::SdchErrorRecovery( 308 LogSdchProblem(filter_context, SDCH_FIXED_CONTENT_ENCODINGS);
304 SdchManager::FIXED_CONTENT_ENCODINGS);
305 } 309 }
306 } else { 310 } else {
307 // Remarkable case!?! We advertised an SDCH dictionary, content-encoding 311 // Remarkable case!?! We advertised an SDCH dictionary, content-encoding
308 // was not marked for SDCH processing: Why did the server suggest an SDCH 312 // was not marked for SDCH processing: Why did the server suggest an SDCH
309 // dictionary in the first place??. Also, the content isn't 313 // dictionary in the first place??. Also, the content isn't
310 // tagged as HTML, despite the fact that SDCH encoding is mostly likely for 314 // tagged as HTML, despite the fact that SDCH encoding is mostly likely for
311 // HTML: Did some anti-virus system strip this tag (sometimes they strip 315 // HTML: Did some anti-virus system strip this tag (sometimes they strip
312 // accept-encoding headers on the request)?? Does the content encoding not 316 // accept-encoding headers on the request)?? Does the content encoding not
313 // start with "text/html" for some other reason?? We'll report this as a 317 // start with "text/html" for some other reason?? We'll report this as a
314 // fixup to a binary file, but it probably really is text/html (some how). 318 // fixup to a binary file, but it probably really is text/html (some how).
315 if (encoding_types->empty()) { 319 if (encoding_types->empty()) {
316 SdchManager::SdchErrorRecovery( 320 LogSdchProblem(filter_context, SDCH_BINARY_ADDED_CONTENT_ENCODING);
317 SdchManager::BINARY_ADDED_CONTENT_ENCODING);
318 } else if (1 == encoding_types->size()) { 321 } else if (1 == encoding_types->size()) {
319 SdchManager::SdchErrorRecovery( 322 LogSdchProblem(filter_context, SDCH_BINARY_FIXED_CONTENT_ENCODING);
320 SdchManager::BINARY_FIXED_CONTENT_ENCODING);
321 } else { 323 } else {
322 SdchManager::SdchErrorRecovery( 324 LogSdchProblem(filter_context, SDCH_BINARY_FIXED_CONTENT_ENCODINGS);
323 SdchManager::BINARY_FIXED_CONTENT_ENCODINGS);
324 } 325 }
325 } 326 }
326 327
327 // Leave the existing encoding type to be processed first, and add our 328 // Leave the existing encoding type to be processed first, and add our
328 // tentative decodings to be done afterwards. Vodaphone UK reportedyl will 329 // tentative decodings to be done afterwards. Vodaphone UK reportedyl will
329 // perform a second layer of gzip encoding atop the server's sdch,gzip 330 // perform a second layer of gzip encoding atop the server's sdch,gzip
330 // encoding, and then claim that the content encoding is a mere gzip. As a 331 // encoding, and then claim that the content encoding is a mere gzip. As a
331 // result we'll need (in that case) to do the gunzip, plus our tentative 332 // result we'll need (in that case) to do the gunzip, plus our tentative
332 // gunzip and tentative SDCH decoding. 333 // gunzip and tentative SDCH decoding.
333 // This approach nicely handles the empty() list as well, and should work with 334 // This approach nicely handles the empty() list as well, and should work with
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 424
424 void Filter::PushDataIntoNextFilter() { 425 void Filter::PushDataIntoNextFilter() {
425 IOBuffer* next_buffer = next_filter_->stream_buffer(); 426 IOBuffer* next_buffer = next_filter_->stream_buffer();
426 int next_size = next_filter_->stream_buffer_size(); 427 int next_size = next_filter_->stream_buffer_size();
427 last_status_ = ReadFilteredData(next_buffer->data(), &next_size); 428 last_status_ = ReadFilteredData(next_buffer->data(), &next_size);
428 if (FILTER_ERROR != last_status_) 429 if (FILTER_ERROR != last_status_)
429 next_filter_->FlushStreamBuffer(next_size); 430 next_filter_->FlushStreamBuffer(next_size);
430 } 431 }
431 432
432 } // namespace net 433 } // namespace net
OLDNEW
« no previous file with comments | « net/filter/filter.h ('k') | net/filter/mock_filter_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698