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) { |
bengr
2014/08/15 17:58:57
I see this form in Chrome more often:
if (is_http
megjablon
2014/08/15 19:04:23
Done.
| |
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 } else { | |
409 NOTREACHED(); | |
410 return false; | |
411 } | |
406 } | 412 } |
407 | 413 |
408 if (allowed_ && ArePrimaryAndFallbackBypassed( | 414 if (allowed_ && ArePrimaryAndFallbackBypassed( |
409 retry_map, origin_, fallback_origin_, min_retry_delay)) { | 415 retry_map, origin_, fallback_origin_, min_retry_delay)) { |
410 return true; | 416 return true; |
411 } | 417 } |
412 | 418 |
413 if (alt_allowed_ && ArePrimaryAndFallbackBypassed( | 419 if (alt_allowed_ && ArePrimaryAndFallbackBypassed( |
414 retry_map, alt_origin_, alt_fallback_origin_, min_retry_delay)) { | 420 retry_map, alt_origin_, alt_fallback_origin_, min_retry_delay)) { |
415 return true; | 421 return true; |
416 } | 422 } |
417 | 423 |
418 return false; | 424 return false; |
419 } | 425 } |
420 | 426 |
421 bool DataReductionProxyParams::ArePrimaryAndFallbackBypassed( | 427 bool DataReductionProxyParams::ArePrimaryAndFallbackBypassed( |
422 const net::ProxyRetryInfoMap& retry_map, | 428 const net::ProxyRetryInfoMap& retry_map, |
423 const GURL& primary, | 429 const GURL& primary, |
424 const GURL& fallback, | 430 const GURL& fallback, |
425 base::TimeDelta* min_retry_delay) const { | 431 base::TimeDelta* min_retry_delay) const { |
432 // Look for the primary proxy in the retry map. This must be done before | |
433 // looking for the fallback in order to assign |min_retry_delay| if the | |
434 // primary proxy has a shorter delay. | |
435 base::TimeDelta delay = base::TimeDelta::Max(); | |
426 net::ProxyRetryInfoMap::const_iterator found = retry_map.find( | 436 net::ProxyRetryInfoMap::const_iterator found = retry_map.find( |
427 net::ProxyServer(primary.SchemeIs(url::kHttpsScheme) ? | 437 net::ProxyServer(primary.SchemeIs(url::kHttpsScheme) ? |
428 net::ProxyServer::SCHEME_HTTPS : net::ProxyServer::SCHEME_HTTP, | 438 net::ProxyServer::SCHEME_HTTPS : |
429 net::HostPortPair::FromURL(primary)).ToURI()); | 439 net::ProxyServer::SCHEME_HTTP, |
430 | 440 net::HostPortPair::FromURL(primary)).ToURI()); |
431 if (found == retry_map.end()) | 441 if (found != retry_map.end()) { |
bengr
2014/08/15 17:58:57
Ah, you don't have to do this work if fallback_all
megjablon
2014/08/15 19:04:23
Done.
| |
432 return false; | 442 delay = found->second.current_delay; |
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 } | 443 } |
440 | 444 |
441 found = retry_map.find( | 445 if (fallback_allowed_ && fallback.is_valid()) { |
442 net::ProxyServer(fallback.SchemeIs(url::kHttpsScheme) ? | 446 // If fallback is allowed, only the fallback proxy needs to be on the retry |
443 net::ProxyServer::SCHEME_HTTPS : net::ProxyServer::SCHEME_HTTP, | 447 // map to know if there was a bypass. We can reset found and forget if the |
444 net::HostPortPair::FromURL(fallback)).ToURI()); | 448 // primary was on the retry map. |
449 found = retry_map.find( | |
450 net::ProxyServer(fallback.SchemeIs(url::kHttpsScheme) ? | |
451 net::ProxyServer::SCHEME_HTTPS : | |
452 net::ProxyServer::SCHEME_HTTP, | |
453 net::HostPortPair::FromURL(fallback)).ToURI()); | |
454 if (found != retry_map.end() && | |
455 delay > found->second.current_delay) { | |
456 delay = found->second.current_delay; | |
457 } | |
458 } | |
445 | 459 |
446 if (found == retry_map.end()) | 460 if (min_retry_delay != NULL && found != retry_map.end()) { |
447 return false; | 461 *min_retry_delay = delay; |
bengr
2014/08/15 17:58:57
nit: you could write to min_retury_delay directly
megjablon
2014/08/15 19:04:23
Done.
| |
462 } | |
448 | 463 |
449 if (min_delay > found->second.current_delay) | 464 return found != retry_map.end(); |
450 min_delay = found->second.current_delay; | |
451 if (min_retry_delay != NULL) | |
452 *min_retry_delay = min_delay; | |
453 return true; | |
454 } | 465 } |
455 | 466 |
456 std::string DataReductionProxyParams::GetDefaultOrigin() const { | 467 std::string DataReductionProxyParams::GetDefaultOrigin() const { |
457 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 468 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
458 return SPDY_PROXY_AUTH_ORIGIN; | 469 return SPDY_PROXY_AUTH_ORIGIN; |
459 #endif | 470 #endif |
460 return std::string(); | 471 return std::string(); |
461 } | 472 } |
462 | 473 |
463 std::string DataReductionProxyParams::GetDefaultFallbackOrigin() const { | 474 std::string DataReductionProxyParams::GetDefaultFallbackOrigin() const { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
496 } | 507 } |
497 | 508 |
498 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { | 509 std::string DataReductionProxyParams::GetDefaultWarmupURL() const { |
499 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL) | 510 #if defined(DATA_REDUCTION_PROXY_WARMUP_URL) |
500 return DATA_REDUCTION_PROXY_WARMUP_URL; | 511 return DATA_REDUCTION_PROXY_WARMUP_URL; |
501 #endif | 512 #endif |
502 return std::string(); | 513 return std::string(); |
503 } | 514 } |
504 | 515 |
505 } // namespace data_reduction_proxy | 516 } // namespace data_reduction_proxy |
OLD | NEW |