| 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 "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h
" | 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_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" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" | 12 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" |
| 13 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" | 13 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" |
| 14 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names
.h" | 14 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names
.h" |
| 15 #include "net/base/host_port_pair.h" | 15 #include "net/base/host_port_pair.h" |
| 16 #include "net/http/http_response_headers.h" | 16 #include "net/http/http_response_headers.h" |
| 17 #include "net/proxy/proxy_retry_info.h" | 17 #include "net/proxy/proxy_retry_info.h" |
| 18 #include "net/proxy/proxy_service.h" | 18 #include "net/proxy/proxy_service.h" |
| 19 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
| 20 | 20 |
| 21 namespace data_reduction_proxy { | 21 namespace data_reduction_proxy { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
| 25 // A bypass delay more than this is treated as a long delay. | 26 // A bypass delay more than this is treated as a long delay. |
| 26 const int kLongBypassDelayInSeconds = 30 * 60; | 27 const int kLongBypassDelayInSeconds = 30 * 60; |
| 28 #endif |
| 27 | 29 |
| 28 // Increments an int64, stored as a string, in a ListPref at the specified | 30 // Increments an int64, stored as a string, in a ListPref at the specified |
| 29 // index. The value must already exist and be a string representation of a | 31 // index. The value must already exist and be a string representation of a |
| 30 // number. | 32 // number. |
| 31 void AddInt64ToListPref(size_t index, | 33 void AddInt64ToListPref(size_t index, |
| 32 int64 length, | 34 int64 length, |
| 33 base::ListValue* list_update) { | 35 base::ListValue* list_update) { |
| 34 int64 value = 0; | 36 int64 value = 0; |
| 35 std::string old_string_value; | 37 std::string old_string_value; |
| 36 bool rv = list_update->GetString(index, &old_string_value); | 38 bool rv = list_update->GetString(index, &old_string_value); |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 } | 285 } |
| 284 int64 GetReceivedListPrefValue(size_t index) { | 286 int64 GetReceivedListPrefValue(size_t index) { |
| 285 return received_.GetListPrefValue(index); | 287 return received_.GetListPrefValue(index); |
| 286 } | 288 } |
| 287 | 289 |
| 288 private: | 290 private: |
| 289 DailyContentLengthUpdate original_; | 291 DailyContentLengthUpdate original_; |
| 290 DailyContentLengthUpdate received_; | 292 DailyContentLengthUpdate received_; |
| 291 }; | 293 }; |
| 292 | 294 |
| 293 // Returns true if the request is bypassed by all configured data reduction | |
| 294 // proxies. It returns the bypass delay in delay_seconds (if not NULL). If | |
| 295 // the request is bypassed by more than one proxy, delay_seconds returns | |
| 296 // shortest delay. | |
| 297 bool IsBypassRequest(const net::URLRequest* request, int64* delay_seconds) { | |
| 298 // TODO(bengr): Add support for other data reduction proxy configurations. | |
| 299 #if defined(SPDY_PROXY_AUTH_ORIGIN) | |
| 300 DataReductionProxyParams params( | |
| 301 DataReductionProxyParams::kAllowed | | |
| 302 DataReductionProxyParams::kFallbackAllowed | | |
| 303 DataReductionProxyParams::kPromoAllowed); | |
| 304 DataReductionProxyParams::DataReductionProxyList proxies = | |
| 305 params.GetAllowedProxies(); | |
| 306 if (proxies.size() == 0) | |
| 307 return false; | |
| 308 | |
| 309 if (request == NULL || request->context() == NULL || | |
| 310 request->context()->proxy_service() == NULL) { | |
| 311 return false; | |
| 312 } | |
| 313 | |
| 314 const net::ProxyRetryInfoMap& retry_map = | |
| 315 request->context()->proxy_service()->proxy_retry_info(); | |
| 316 if (retry_map.size() == 0) | |
| 317 return false; | |
| 318 | |
| 319 int64 shortest_delay = 0; | |
| 320 // The request is bypassed if all configured proxies are in the retry map. | |
| 321 for (size_t i = 0; i < proxies.size(); ++i) { | |
| 322 std::string proxy = net::HostPortPair::FromURL(proxies[i]).ToString(); | |
| 323 // The retry list has the scheme prefix for https but not for http. | |
| 324 if (proxies[i].SchemeIs("https")) | |
| 325 proxy = std::string("https://") + proxy; | |
| 326 | |
| 327 net::ProxyRetryInfoMap::const_iterator found = retry_map.find(proxy); | |
| 328 if (found == retry_map.end()) | |
| 329 return false; | |
| 330 if (shortest_delay == 0 || | |
| 331 shortest_delay > found->second.current_delay.InSeconds()) { | |
| 332 shortest_delay = found->second.current_delay.InSeconds(); | |
| 333 } | |
| 334 } | |
| 335 if (delay_seconds != NULL) | |
| 336 *delay_seconds = shortest_delay; | |
| 337 return true; | |
| 338 #else | |
| 339 return false; | |
| 340 #endif | |
| 341 } | |
| 342 | |
| 343 } // namespace | 295 } // namespace |
| 344 | 296 |
| 345 DataReductionProxyRequestType GetDataReductionProxyRequestType( | 297 DataReductionProxyRequestType GetDataReductionProxyRequestType( |
| 346 const net::URLRequest* request) { | 298 const net::URLRequest* request) { |
| 347 if (request->url().SchemeIs("https")) | 299 if (request->url().SchemeIs("https")) |
| 348 return HTTPS; | 300 return HTTPS; |
| 349 if (!request->url().SchemeIs("http")) { | 301 if (!request->url().SchemeIs("http")) { |
| 350 NOTREACHED(); | 302 NOTREACHED(); |
| 351 return UNKNOWN_TYPE; | 303 return UNKNOWN_TYPE; |
| 352 } | 304 } |
| 353 int64 bypass_delay = 0; | 305 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
| 354 if (IsBypassRequest(request, &bypass_delay)) { | 306 DataReductionProxyParams params( |
| 355 return (bypass_delay > kLongBypassDelayInSeconds) ? | 307 DataReductionProxyParams::kAllowed | |
| 356 LONG_BYPASS : SHORT_BYPASS; | 308 DataReductionProxyParams::kFallbackAllowed | |
| 309 DataReductionProxyParams::kPromoAllowed); |
| 310 base::TimeDelta bypass_delay; |
| 311 if (params.AreDataReductionProxiesBypassed(*request, &bypass_delay)) { |
| 312 if (bypass_delay > base::TimeDelta::FromSeconds(kLongBypassDelayInSeconds)) |
| 313 return LONG_BYPASS; |
| 314 return SHORT_BYPASS; |
| 357 } | 315 } |
| 316 #endif |
| 358 if (request->response_info().headers && | 317 if (request->response_info().headers && |
| 359 HasDataReductionProxyViaHeader(request->response_info().headers)) { | 318 HasDataReductionProxyViaHeader(request->response_info().headers)) { |
| 360 return VIA_DATA_REDUCTION_PROXY; | 319 return VIA_DATA_REDUCTION_PROXY; |
| 361 } | 320 } |
| 362 return UNKNOWN_TYPE; | 321 return UNKNOWN_TYPE; |
| 363 } | 322 } |
| 364 | 323 |
| 365 int64 GetAdjustedOriginalContentLength( | 324 int64 GetAdjustedOriginalContentLength( |
| 366 DataReductionProxyRequestType request_type, | 325 DataReductionProxyRequestType request_type, |
| 367 int64 original_content_length, | 326 int64 original_content_length, |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 UpdateContentLengthPrefsForDataReductionProxy( | 493 UpdateContentLengthPrefsForDataReductionProxy( |
| 535 received_content_length, | 494 received_content_length, |
| 536 original_content_length, | 495 original_content_length, |
| 537 with_data_reduction_proxy_enabled, | 496 with_data_reduction_proxy_enabled, |
| 538 request_type, | 497 request_type, |
| 539 base::Time::Now(), | 498 base::Time::Now(), |
| 540 prefs); | 499 prefs); |
| 541 } | 500 } |
| 542 | 501 |
| 543 } // namespace data_reduction_proxy | 502 } // namespace data_reduction_proxy |
| OLD | NEW |