OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/net/spdyproxy/data_saving_metrics.h" | 5 #include "chrome/browser/net/spdyproxy/data_saving_metrics.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/prefs/scoped_user_pref_update.h" | 9 #include "base/prefs/scoped_user_pref_update.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 } | 341 } |
342 } | 342 } |
343 if (delay_seconds != NULL) | 343 if (delay_seconds != NULL) |
344 *delay_seconds = shortest_delay; | 344 *delay_seconds = shortest_delay; |
345 return true; | 345 return true; |
346 #else | 346 #else |
347 return false; | 347 return false; |
348 #endif // defined(OS_ANDROID) || defined(OS_IOS) | 348 #endif // defined(OS_ANDROID) || defined(OS_IOS) |
349 } | 349 } |
350 | 350 |
351 // IsDataReductionProxyReponse returns true if response_headers contains the | |
352 // data reduction proxy Via header value. | |
353 bool IsDataReductionProxyReponse( | |
354 const net::HttpResponseHeaders* response_headers) { | |
355 const char kDatReductionProxyViaValue[] = "1.1 Chrome Compression Proxy"; | |
356 size_t value_len = strlen(kDatReductionProxyViaValue); | |
357 void* iter = NULL; | |
358 std::string temp; | |
359 while (response_headers->EnumerateHeader(&iter, "Via", &temp)) { | |
360 string::const_iterator it = | |
361 std::search(temp.begin(), | |
362 temp.end(), | |
363 kDatReductionProxyViaValue, | |
364 kDatReductionProxyViaValue + value_len, | |
365 base::CaseInsensitiveCompareASCII<char>()); | |
366 if (it != temp.end()) { | |
367 return true; | |
368 } | |
369 } | |
370 return false; | |
371 } | |
372 | |
373 } // namespace | 351 } // namespace |
374 | 352 |
375 namespace spdyproxy { | 353 namespace spdyproxy { |
376 | 354 |
377 DataReductionRequestType GetDataReductionRequestType( | 355 DataReductionRequestType GetDataReductionRequestType( |
378 const net::URLRequest* request) { | 356 const net::URLRequest* request) { |
379 if (request->url().SchemeIs(content::kHttpsScheme)) | 357 if (request->url().SchemeIs(content::kHttpsScheme)) |
380 return HTTPS; | 358 return HTTPS; |
381 if (!request->url().SchemeIs(content::kHttpScheme)) { | 359 if (!request->url().SchemeIs(content::kHttpScheme)) { |
382 NOTREACHED(); | 360 NOTREACHED(); |
383 return UNKNOWN_TYPE; | 361 return UNKNOWN_TYPE; |
384 } | 362 } |
385 int64 bypass_delay = 0; | 363 int64 bypass_delay = 0; |
386 if (IsBypassRequest(request, &bypass_delay)) { | 364 if (IsBypassRequest(request, &bypass_delay)) { |
387 return (bypass_delay > kLongBypassDelayInSeconds) ? | 365 return (bypass_delay > kLongBypassDelayInSeconds) ? |
388 LONG_BYPASS : SHORT_BYPASS; | 366 LONG_BYPASS : SHORT_BYPASS; |
389 } | 367 } |
390 return IsDataReductionProxyReponse(request->response_info().headers) ? | 368 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
391 VIA_DATA_REDUCTION_PROXY: UNKNOWN_TYPE; | 369 if (request->response_info().headers && |
| 370 request->response_info().headers->IsChromeProxyResponse()) { |
| 371 return VIA_DATA_REDUCTION_PROXY; |
| 372 } |
| 373 #endif |
| 374 return UNKNOWN_TYPE; |
392 } | 375 } |
393 | 376 |
394 int64 GetAdjustedOriginalContentLength( | 377 int64 GetAdjustedOriginalContentLength( |
395 DataReductionRequestType data_reduction_type, | 378 DataReductionRequestType data_reduction_type, |
396 int64 original_content_length, | 379 int64 original_content_length, |
397 int64 received_content_length) { | 380 int64 received_content_length) { |
398 // Since there was no indication of the original content length, presume | 381 // Since there was no indication of the original content length, presume |
399 // it is no different from the number of bytes read. | 382 // it is no different from the number of bytes read. |
400 if (original_content_length == -1 || | 383 if (original_content_length == -1 || |
401 data_reduction_type != spdyproxy::VIA_DATA_REDUCTION_PROXY) { | 384 data_reduction_type != spdyproxy::VIA_DATA_REDUCTION_PROXY) { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 original_content_length, | 525 original_content_length, |
543 with_data_reduction_proxy_enabled, | 526 with_data_reduction_proxy_enabled, |
544 data_reduction_type, | 527 data_reduction_type, |
545 base::Time::Now(), | 528 base::Time::Now(), |
546 prefs); | 529 prefs); |
547 #endif // defined(OS_ANDROID) || defined(OS_IOS) | 530 #endif // defined(OS_ANDROID) || defined(OS_IOS) |
548 | 531 |
549 } | 532 } |
550 | 533 |
551 } // namespace spdyproxy | 534 } // namespace spdyproxy |
OLD | NEW |