Chromium Code Reviews| 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 (min_retry_delay != NULL) | |
| 404 *min_retry_delay = base::TimeDelta::Max(); | |
| 405 | |
| 406 // If the request is https, we only care about the ssl proxy. | |
|
bengr
2014/08/15 01:15:07
// ... consider only the ssl proxy
megjablon
2014/08/15 02:01:35
Done.
| |
| 403 if (is_https && alt_allowed_) { | 407 if (is_https && alt_allowed_) { |
| 404 return ArePrimaryAndFallbackBypassed( | 408 return ArePrimaryAndFallbackBypassed( |
| 405 retry_map, ssl_origin_, GURL(), min_retry_delay); | 409 retry_map, ssl_origin_, GURL(), min_retry_delay); |
| 406 } | 410 } |
| 407 | 411 |
| 408 if (allowed_ && ArePrimaryAndFallbackBypassed( | 412 bool proxies_bypassed = false; |
| 409 retry_map, origin_, fallback_origin_, min_retry_delay)) { | 413 bool alt_proxies_bypassed = false; |
| 410 return true; | 414 // For http requests, we must look at all proxies on the retry map to get |
| 415 // the |min_retry_delay|. | |
| 416 if (!is_https && allowed_) { | |
| 417 proxies_bypassed = ArePrimaryAndFallbackBypassed( | |
| 418 retry_map, origin_, fallback_origin_, min_retry_delay); | |
| 411 } | 419 } |
| 412 | 420 |
| 413 if (alt_allowed_ && ArePrimaryAndFallbackBypassed( | 421 if (!is_https && alt_allowed_) { |
| 414 retry_map, alt_origin_, alt_fallback_origin_, min_retry_delay)) { | 422 alt_proxies_bypassed = ArePrimaryAndFallbackBypassed( |
| 415 return true; | 423 retry_map, alt_origin_, alt_fallback_origin_, min_retry_delay); |
| 416 } | 424 } |
| 417 | 425 |
| 418 return false; | 426 return proxies_bypassed || alt_proxies_bypassed; |
|
bengr
2014/08/15 01:15:07
I would return before dealing with all proxies if
megjablon
2014/08/15 02:01:35
Fixed as discussed offline.
| |
| 419 } | 427 } |
| 420 | 428 |
| 421 bool DataReductionProxyParams::ArePrimaryAndFallbackBypassed( | 429 bool DataReductionProxyParams::ArePrimaryAndFallbackBypassed( |
| 422 const net::ProxyRetryInfoMap& retry_map, | 430 const net::ProxyRetryInfoMap& retry_map, |
| 423 const GURL& primary, | 431 const GURL& primary, |
| 424 const GURL& fallback, | 432 const GURL& fallback, |
| 425 base::TimeDelta* min_retry_delay) const { | 433 base::TimeDelta* min_retry_delay) const { |
| 434 // We look for the primary proxy in the retry map. This must be done before | |
|
bengr
2014/08/15 01:15:07
Look for...
megjablon
2014/08/15 02:01:35
Done.
| |
| 435 // looking for the fallback in order to assign |min_retry_delay| if the | |
| 436 // primary proxy has a shorter delay. | |
| 426 net::ProxyRetryInfoMap::const_iterator found = retry_map.find( | 437 net::ProxyRetryInfoMap::const_iterator found = retry_map.find( |
| 427 net::ProxyServer(primary.SchemeIs(url::kHttpsScheme) ? | 438 net::ProxyServer(primary.SchemeIs(url::kHttpsScheme) ? |
| 428 net::ProxyServer::SCHEME_HTTPS : net::ProxyServer::SCHEME_HTTP, | 439 net::ProxyServer::SCHEME_HTTPS : net::ProxyServer::SCHEME_HTTP, |
| 429 net::HostPortPair::FromURL(primary)).ToURI()); | 440 net::HostPortPair::FromURL(primary)).ToURI()); |
| 441 // If the primary proxy is found, we check it's delay. If the delay is less | |
|
bengr
2014/08/15 01:15:07
Remove "we" everywhere.
megjablon
2014/08/15 02:01:35
Done.
| |
| 442 // than |min_retry_delay|, we reassign. | |
| 443 if (found != retry_map.end() && | |
| 444 min_retry_delay != NULL && | |
| 445 *min_retry_delay > found->second.current_delay) { | |
| 446 *min_retry_delay = found->second.current_delay; | |
| 447 } | |
| 448 | |
| 449 if (fallback_allowed_ && fallback.is_valid()) { | |
| 450 // If fallback is allowed, we only need to know that the fallback proxy is | |
| 451 // on the retry map to know if there was a bypass. We can reset found and | |
| 452 // forget if the primary was on the retry map. | |
| 453 found = retry_map.find( | |
| 454 net::ProxyServer(fallback.SchemeIs(url::kHttpsScheme) ? | |
| 455 net::ProxyServer::SCHEME_HTTPS : net::ProxyServer::SCHEME_HTTP, | |
|
bengr
2014/08/15 01:15:07
Indentation is a little weird. Maybe break after S
megjablon
2014/08/15 02:01:35
That looked very strange. I tried something differ
| |
| 456 net::HostPortPair::FromURL(fallback)).ToURI()); | |
| 457 // If the fallback proxy is found, we check it's delay. If the delay is less | |
| 458 // than |min_retry_delay|, we reassign. | |
| 459 if (found != retry_map.end() && | |
| 460 min_retry_delay != NULL && | |
| 461 *min_retry_delay > found->second.current_delay) { | |
| 462 *min_retry_delay = found->second.current_delay; | |
| 463 } | |
| 464 } | |
| 430 | 465 |
| 431 if (found == retry_map.end()) | 466 if (found == retry_map.end()) |
| 432 return false; | 467 return false; |
| 433 | |
| 434 base::TimeDelta min_delay = found->second.current_delay; | |
| 435 if (!fallback_allowed_ || !fallback.is_valid()) { | |
| 436 if (min_retry_delay != NULL) | |
| 437 *min_retry_delay = min_delay; | |
| 438 return true; | |
| 439 } | |
| 440 | |
| 441 found = retry_map.find( | |
| 442 net::ProxyServer(fallback.SchemeIs(url::kHttpsScheme) ? | |
| 443 net::ProxyServer::SCHEME_HTTPS : net::ProxyServer::SCHEME_HTTP, | |
| 444 net::HostPortPair::FromURL(fallback)).ToURI()); | |
| 445 | |
| 446 if (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; | 468 return true; |
| 454 } | 469 } |
| 455 | 470 |
| 456 std::string DataReductionProxyParams::GetDefaultOrigin() const { | 471 std::string DataReductionProxyParams::GetDefaultOrigin() const { |
| 457 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 472 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
| 458 return SPDY_PROXY_AUTH_ORIGIN; | 473 return SPDY_PROXY_AUTH_ORIGIN; |
| 459 #endif | 474 #endif |
| 460 return std::string(); | 475 return std::string(); |
| 461 } | 476 } |
| 462 | 477 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 496 } | 511 } |
| 497 | 512 |
| 498 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { | 513 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { |
| 499 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL) | 514 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL) |
| 500 return DATA_REDUCTION_PROXY_WARMUP_URL; | 515 return DATA_REDUCTION_PROXY_WARMUP_URL; |
| 501 #endif | 516 #endif |
| 502 return std::string(); | 517 return std::string(); |
| 503 } | 518 } |
| 504 | 519 |
| 505 } // namespace data_reduction_proxy | 520 } // namespace data_reduction_proxy |
| OLD | NEW |