| 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_params.h" | 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 return false; | 393 return false; |
| 394 } | 394 } |
| 395 | 395 |
| 396 bool DataReductionProxyParams::AreProxiesBypassed( | 396 bool DataReductionProxyParams::AreProxiesBypassed( |
| 397 const net::ProxyRetryInfoMap& retry_map, | 397 const net::ProxyRetryInfoMap& retry_map, |
| 398 bool is_https, | 398 bool is_https, |
| 399 base::TimeDelta* min_retry_delay) const { | 399 base::TimeDelta* min_retry_delay) const { |
| 400 if (retry_map.size() == 0) | 400 if (retry_map.size() == 0) |
| 401 return false; | 401 return false; |
| 402 | 402 |
| 403 if (is_https && alt_allowed_) { | 403 // If the request is https, consider only the ssl proxy. |
| 404 return ArePrimaryAndFallbackBypassed( | 404 if (is_https) { |
| 405 retry_map, ssl_origin_, GURL(), min_retry_delay); | 405 if (alt_allowed_) { |
| 406 return ArePrimaryAndFallbackBypassed( |
| 407 retry_map, ssl_origin_, GURL(), min_retry_delay); |
| 408 } |
| 409 NOTREACHED(); |
| 410 return false; |
| 406 } | 411 } |
| 407 | 412 |
| 408 if (allowed_ && ArePrimaryAndFallbackBypassed( | 413 if (allowed_ && ArePrimaryAndFallbackBypassed( |
| 409 retry_map, origin_, fallback_origin_, min_retry_delay)) { | 414 retry_map, origin_, fallback_origin_, min_retry_delay)) { |
| 410 return true; | 415 return true; |
| 411 } | 416 } |
| 412 | 417 |
| 413 if (alt_allowed_ && ArePrimaryAndFallbackBypassed( | 418 if (alt_allowed_ && ArePrimaryAndFallbackBypassed( |
| 414 retry_map, alt_origin_, alt_fallback_origin_, min_retry_delay)) { | 419 retry_map, alt_origin_, alt_fallback_origin_, min_retry_delay)) { |
| 415 return true; | 420 return true; |
| 416 } | 421 } |
| 417 | 422 |
| 418 return false; | 423 return false; |
| 419 } | 424 } |
| 420 | 425 |
| 421 bool DataReductionProxyParams::ArePrimaryAndFallbackBypassed( | 426 bool DataReductionProxyParams::ArePrimaryAndFallbackBypassed( |
| 422 const net::ProxyRetryInfoMap& retry_map, | 427 const net::ProxyRetryInfoMap& retry_map, |
| 423 const GURL& primary, | 428 const GURL& primary, |
| 424 const GURL& fallback, | 429 const GURL& fallback, |
| 425 base::TimeDelta* min_retry_delay) const { | 430 base::TimeDelta* min_retry_delay) const { |
| 426 net::ProxyRetryInfoMap::const_iterator found = retry_map.find( | 431 net::ProxyRetryInfoMap::const_iterator found = retry_map.end(); |
| 427 net::ProxyServer(primary.SchemeIs(url::kHttpsScheme) ? | 432 if (min_retry_delay) |
| 428 net::ProxyServer::SCHEME_HTTPS : net::ProxyServer::SCHEME_HTTP, | 433 *min_retry_delay = base::TimeDelta::Max(); |
| 429 net::HostPortPair::FromURL(primary)).ToURI()); | |
| 430 | 434 |
| 431 if (found == retry_map.end()) | 435 // Look for the primary proxy in the retry map. This must be done before |
| 432 return false; | 436 // looking for the fallback in order to assign |min_retry_delay| if the |
| 433 | 437 // primary proxy has a shorter delay. |
| 434 base::TimeDelta min_delay = found->second.current_delay; | 438 if (!fallback_allowed_ || !fallback.is_valid() || min_retry_delay) { |
| 435 if (!fallback_allowed_ || !fallback.is_valid()) { | 439 found = retry_map.find( |
| 436 if (min_retry_delay != NULL) | 440 net::ProxyServer(primary.SchemeIs(url::kHttpsScheme) ? |
| 437 *min_retry_delay = min_delay; | 441 net::ProxyServer::SCHEME_HTTPS : |
| 438 return true; | 442 net::ProxyServer::SCHEME_HTTP, |
| 443 net::HostPortPair::FromURL(primary)).ToURI()); |
| 444 if (found != retry_map.end() && min_retry_delay) { |
| 445 *min_retry_delay = found->second.current_delay; |
| 446 } |
| 439 } | 447 } |
| 440 | 448 |
| 441 found = retry_map.find( | 449 if (fallback_allowed_ && fallback.is_valid()) { |
| 442 net::ProxyServer(fallback.SchemeIs(url::kHttpsScheme) ? | 450 // If fallback is allowed, only the fallback proxy needs to be on the retry |
| 443 net::ProxyServer::SCHEME_HTTPS : net::ProxyServer::SCHEME_HTTP, | 451 // map to know if there was a bypass. We can reset found and forget if the |
| 444 net::HostPortPair::FromURL(fallback)).ToURI()); | 452 // primary was on the retry map. |
| 453 found = retry_map.find( |
| 454 net::ProxyServer(fallback.SchemeIs(url::kHttpsScheme) ? |
| 455 net::ProxyServer::SCHEME_HTTPS : |
| 456 net::ProxyServer::SCHEME_HTTP, |
| 457 net::HostPortPair::FromURL(fallback)).ToURI()); |
| 458 if (found != retry_map.end() && |
| 459 min_retry_delay && |
| 460 *min_retry_delay > found->second.current_delay) { |
| 461 *min_retry_delay = found->second.current_delay; |
| 462 } |
| 463 } |
| 445 | 464 |
| 446 if (found == retry_map.end()) | 465 return found != retry_map.end(); |
| 447 return false; | |
| 448 | |
| 449 if (min_delay > found->second.current_delay) | |
| 450 min_delay = found->second.current_delay; | |
| 451 if (min_retry_delay != NULL) | |
| 452 *min_retry_delay = min_delay; | |
| 453 return true; | |
| 454 } | 466 } |
| 455 | 467 |
| 456 std::string DataReductionProxyParams::GetDefaultOrigin() const { | 468 std::string DataReductionProxyParams::GetDefaultOrigin() const { |
| 457 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 469 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
| 458 return SPDY_PROXY_AUTH_ORIGIN; | 470 return SPDY_PROXY_AUTH_ORIGIN; |
| 459 #endif | 471 #endif |
| 460 return std::string(); | 472 return std::string(); |
| 461 } | 473 } |
| 462 | 474 |
| 463 std::string DataReductionProxyParams::GetDefaultFallbackOrigin() const { | 475 std::string DataReductionProxyParams::GetDefaultFallbackOrigin() const { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 } | 508 } |
| 497 | 509 |
| 498 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { | 510 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { |
| 499 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL) | 511 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL) |
| 500 return DATA_REDUCTION_PROXY_WARMUP_URL; | 512 return DATA_REDUCTION_PROXY_WARMUP_URL; |
| 501 #endif | 513 #endif |
| 502 return std::string(); | 514 return std::string(); |
| 503 } | 515 } |
| 504 | 516 |
| 505 } // namespace data_reduction_proxy | 517 } // namespace data_reduction_proxy |
| OLD | NEW |