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

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

Issue 6347033: net: Add namespace net to Sdch* classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 10 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/base/filter.h" 5 #include "net/base/filter.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "net/base/gzip_filter.h" 9 #include "net/base/gzip_filter.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 !net::IsSupportedMimeType(mime_type)) 177 !net::IsSupportedMimeType(mime_type))
178 encoding_types->clear(); 178 encoding_types->clear();
179 } 179 }
180 } 180 }
181 181
182 // If the request was for SDCH content, then we might need additional fixups. 182 // If the request was for SDCH content, then we might need additional fixups.
183 if (!filter_context.IsSdchResponse()) { 183 if (!filter_context.IsSdchResponse()) {
184 // It was not an SDCH request, so we'll just record stats. 184 // It was not an SDCH request, so we'll just record stats.
185 if (1 < encoding_types->size()) { 185 if (1 < encoding_types->size()) {
186 // Multiple filters were intended to only be used for SDCH (thus far!) 186 // Multiple filters were intended to only be used for SDCH (thus far!)
187 SdchManager::SdchErrorRecovery( 187 net::SdchManager::SdchErrorRecovery(
188 SdchManager::MULTIENCODING_FOR_NON_SDCH_REQUEST); 188 net::SdchManager::MULTIENCODING_FOR_NON_SDCH_REQUEST);
189 } 189 }
190 if ((1 == encoding_types->size()) && 190 if ((1 == encoding_types->size()) &&
191 (FILTER_TYPE_SDCH == encoding_types->front())) { 191 (FILTER_TYPE_SDCH == encoding_types->front())) {
192 SdchManager::SdchErrorRecovery( 192 net::SdchManager::SdchErrorRecovery(
193 SdchManager::SDCH_CONTENT_ENCODE_FOR_NON_SDCH_REQUEST); 193 net::SdchManager::SDCH_CONTENT_ENCODE_FOR_NON_SDCH_REQUEST);
194 } 194 }
195 return; 195 return;
196 } 196 }
197 197
198 // The request was tagged as an SDCH request, which means the server supplied 198 // The request was tagged as an SDCH request, which means the server supplied
199 // a dictionary, and we advertised it in the request. Some proxies will do 199 // a dictionary, and we advertised it in the request. Some proxies will do
200 // very strange things to the request, or the response, so we have to handle 200 // very strange things to the request, or the response, so we have to handle
201 // them gracefully. 201 // them gracefully.
202 202
203 // If content encoding included SDCH, then everything is "relatively" fine. 203 // If content encoding included SDCH, then everything is "relatively" fine.
204 if (!encoding_types->empty() && 204 if (!encoding_types->empty() &&
205 (FILTER_TYPE_SDCH == encoding_types->front())) { 205 (FILTER_TYPE_SDCH == encoding_types->front())) {
206 // Some proxies (found currently in Argentina) strip the Content-Encoding 206 // Some proxies (found currently in Argentina) strip the Content-Encoding
207 // text from "sdch,gzip" to a mere "sdch" without modifying the compressed 207 // text from "sdch,gzip" to a mere "sdch" without modifying the compressed
208 // payload. To handle this gracefully, we simulate the "probably" deleted 208 // payload. To handle this gracefully, we simulate the "probably" deleted
209 // ",gzip" by appending a tentative gzip decode, which will default to a 209 // ",gzip" by appending a tentative gzip decode, which will default to a
210 // no-op pass through filter if it doesn't get gzip headers where expected. 210 // no-op pass through filter if it doesn't get gzip headers where expected.
211 if (1 == encoding_types->size()) { 211 if (1 == encoding_types->size()) {
212 encoding_types->push_back(FILTER_TYPE_GZIP_HELPING_SDCH); 212 encoding_types->push_back(FILTER_TYPE_GZIP_HELPING_SDCH);
213 SdchManager::SdchErrorRecovery( 213 net::SdchManager::SdchErrorRecovery(
214 SdchManager::OPTIONAL_GUNZIP_ENCODING_ADDED); 214 net::SdchManager::OPTIONAL_GUNZIP_ENCODING_ADDED);
215 } 215 }
216 return; 216 return;
217 } 217 }
218 218
219 // There are now several cases to handle for an SDCH request. Foremost, if 219 // There are now several cases to handle for an SDCH request. Foremost, if
220 // the outbound request was stripped so as not to advertise support for 220 // the outbound request was stripped so as not to advertise support for
221 // encodings, we might get back content with no encoding, or (for example) 221 // encodings, we might get back content with no encoding, or (for example)
222 // just gzip. We have to be sure that any changes we make allow for such 222 // just gzip. We have to be sure that any changes we make allow for such
223 // minimal coding to work. That issue is why we use TENTATIVE filters if we 223 // minimal coding to work. That issue is why we use TENTATIVE filters if we
224 // add any, as those filters sniff the content, and act as pass-through 224 // add any, as those filters sniff the content, and act as pass-through
(...skipping 13 matching lines...) Expand all
238 // The one unresolved failure mode comes when we advertise a dictionary, and 238 // The one unresolved failure mode comes when we advertise a dictionary, and
239 // the server tries to *send* a gzipped file (not gzip encode content), and 239 // the server tries to *send* a gzipped file (not gzip encode content), and
240 // then we could do a gzip decode :-(. Since SDCH is only (currently) 240 // then we could do a gzip decode :-(. Since SDCH is only (currently)
241 // supported server side on paths that only send HTML content, this mode has 241 // supported server side on paths that only send HTML content, this mode has
242 // never surfaced in the wild (and is unlikely to). 242 // never surfaced in the wild (and is unlikely to).
243 // We will gather a lot of stats as we perform the fixups 243 // We will gather a lot of stats as we perform the fixups
244 if (StartsWithASCII(mime_type, kTextHtml, false)) { 244 if (StartsWithASCII(mime_type, kTextHtml, false)) {
245 // Suspicious case: Advertised dictionary, but server didn't use sdch, and 245 // Suspicious case: Advertised dictionary, but server didn't use sdch, and
246 // we're HTML tagged. 246 // we're HTML tagged.
247 if (encoding_types->empty()) { 247 if (encoding_types->empty()) {
248 SdchManager::SdchErrorRecovery(SdchManager::ADDED_CONTENT_ENCODING); 248 net::SdchManager::SdchErrorRecovery(
249 net::SdchManager::ADDED_CONTENT_ENCODING);
249 } else if (1 == encoding_types->size()) { 250 } else if (1 == encoding_types->size()) {
250 SdchManager::SdchErrorRecovery(SdchManager::FIXED_CONTENT_ENCODING); 251 net::SdchManager::SdchErrorRecovery(
252 net::SdchManager::FIXED_CONTENT_ENCODING);
251 } else { 253 } else {
252 SdchManager::SdchErrorRecovery(SdchManager::FIXED_CONTENT_ENCODINGS); 254 net::SdchManager::SdchErrorRecovery(
255 net::SdchManager::FIXED_CONTENT_ENCODINGS);
253 } 256 }
254 } else { 257 } else {
255 // Remarkable case!?! We advertised an SDCH dictionary, content-encoding 258 // Remarkable case!?! We advertised an SDCH dictionary, content-encoding
256 // was not marked for SDCH processing: Why did the server suggest an SDCH 259 // was not marked for SDCH processing: Why did the server suggest an SDCH
257 // dictionary in the first place??. Also, the content isn't 260 // dictionary in the first place??. Also, the content isn't
258 // tagged as HTML, despite the fact that SDCH encoding is mostly likely for 261 // tagged as HTML, despite the fact that SDCH encoding is mostly likely for
259 // HTML: Did some anti-virus system strip this tag (sometimes they strip 262 // HTML: Did some anti-virus system strip this tag (sometimes they strip
260 // accept-encoding headers on the request)?? Does the content encoding not 263 // accept-encoding headers on the request)?? Does the content encoding not
261 // start with "text/html" for some other reason?? We'll report this as a 264 // start with "text/html" for some other reason?? We'll report this as a
262 // fixup to a binary file, but it probably really is text/html (some how). 265 // fixup to a binary file, but it probably really is text/html (some how).
263 if (encoding_types->empty()) { 266 if (encoding_types->empty()) {
264 SdchManager::SdchErrorRecovery( 267 net::SdchManager::SdchErrorRecovery(
265 SdchManager::BINARY_ADDED_CONTENT_ENCODING); 268 net::SdchManager::BINARY_ADDED_CONTENT_ENCODING);
266 } else if (1 == encoding_types->size()) { 269 } else if (1 == encoding_types->size()) {
267 SdchManager::SdchErrorRecovery( 270 net::SdchManager::SdchErrorRecovery(
268 SdchManager::BINARY_FIXED_CONTENT_ENCODING); 271 net::SdchManager::BINARY_FIXED_CONTENT_ENCODING);
269 } else { 272 } else {
270 SdchManager::SdchErrorRecovery( 273 net::SdchManager::SdchErrorRecovery(
271 SdchManager::BINARY_FIXED_CONTENT_ENCODINGS); 274 net::SdchManager::BINARY_FIXED_CONTENT_ENCODINGS);
272 } 275 }
273 } 276 }
274 277
275 // Leave the existing encoding type to be processed first, and add our 278 // Leave the existing encoding type to be processed first, and add our
276 // tentative decodings to be done afterwards. Vodaphone UK reportedyl will 279 // tentative decodings to be done afterwards. Vodaphone UK reportedyl will
277 // perform a second layer of gzip encoding atop the server's sdch,gzip 280 // perform a second layer of gzip encoding atop the server's sdch,gzip
278 // encoding, and then claim that the content encoding is a mere gzip. As a 281 // encoding, and then claim that the content encoding is a mere gzip. As a
279 // result we'll need (in that case) to do the gunzip, plus our tentative 282 // result we'll need (in that case) to do the gunzip, plus our tentative
280 // gunzip and tentative SDCH decoding. 283 // gunzip and tentative SDCH decoding.
281 // This approach nicely handles the empty() list as well, and should work with 284 // This approach nicely handles the empty() list as well, and should work with
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 new net::GZipFilter(filter_context)); 339 new net::GZipFilter(filter_context));
337 if (gz_filter->InitBuffer()) { 340 if (gz_filter->InitBuffer()) {
338 if (gz_filter->InitDecoding(type_id)) { 341 if (gz_filter->InitDecoding(type_id)) {
339 first_filter = gz_filter.release(); 342 first_filter = gz_filter.release();
340 } 343 }
341 } 344 }
342 break; 345 break;
343 } 346 }
344 case FILTER_TYPE_SDCH: 347 case FILTER_TYPE_SDCH:
345 case FILTER_TYPE_SDCH_POSSIBLE: { 348 case FILTER_TYPE_SDCH_POSSIBLE: {
346 scoped_ptr<SdchFilter> sdch_filter(new SdchFilter(filter_context)); 349 scoped_ptr<net::SdchFilter> sdch_filter(
350 new net::SdchFilter(filter_context));
347 if (sdch_filter->InitBuffer()) { 351 if (sdch_filter->InitBuffer()) {
348 if (sdch_filter->InitDecoding(type_id)) { 352 if (sdch_filter->InitDecoding(type_id)) {
349 first_filter = sdch_filter.release(); 353 first_filter = sdch_filter.release();
350 } 354 }
351 } 355 }
352 break; 356 break;
353 } 357 }
354 default: { 358 default: {
355 break; 359 break;
356 } 360 }
(...skipping 25 matching lines...) Expand all
382 return false; 386 return false;
383 } 387 }
384 388
385 void Filter::PushDataIntoNextFilter() { 389 void Filter::PushDataIntoNextFilter() {
386 net::IOBuffer* next_buffer = next_filter_->stream_buffer(); 390 net::IOBuffer* next_buffer = next_filter_->stream_buffer();
387 int next_size = next_filter_->stream_buffer_size(); 391 int next_size = next_filter_->stream_buffer_size();
388 last_status_ = ReadFilteredData(next_buffer->data(), &next_size); 392 last_status_ = ReadFilteredData(next_buffer->data(), &next_size);
389 if (FILTER_ERROR != last_status_) 393 if (FILTER_ERROR != last_status_)
390 next_filter_->FlushStreamBuffer(next_size); 394 next_filter_->FlushStreamBuffer(next_size);
391 } 395 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698