Index: components/data_reduction_proxy/browser/data_reduction_proxy_params.cc |
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_params.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_params.cc |
index 64b2ec1040c4cc533310f3826651f2c22525cdbd..e58518cc4c208592ff36b1a335d3a40e85f0e096 100644 |
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_params.cc |
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_params.cc |
@@ -18,6 +18,8 @@ namespace { |
const char kEnabled[] = "Enabled"; |
} |
+using namespace net; |
+ |
namespace data_reduction_proxy { |
// static |
@@ -329,6 +331,82 @@ std::string DataReductionProxyParams::GetDefaultDevOrigin() const { |
return std::string(); |
} |
+bool WerePrimaryAndFallbackBypassed( |
+ const net::ProxyRetryInfoMap& retry_map, |
+ GURL primary, |
+ GURL fallback, |
+ bool fallback_allowed, |
+ int64* delay_seconds) { |
+ int64 shortest_delay = 0; |
+ net::ProxyRetryInfoMap::const_iterator found; |
+ |
+ std::string proxy = net::HostPortPair::FromURL(primary).ToString(); |
+ // The retry list has the scheme prefix for https but not for http. |
+ if (primary.SchemeIs(url::kHttpsScheme)) |
+ proxy = std::string("https://") + proxy; |
+ |
+ found = retry_map.find(proxy); |
+ if (!(found == retry_map.end())) { |
+ shortest_delay = found->second.current_delay.InSeconds(); |
+ if (fallback_allowed) { |
+ proxy = net::HostPortPair::FromURL(fallback).ToString(); |
+ found = retry_map.find(proxy); |
+ if (!(found == retry_map.end())) { |
+ if(shortest_delay > found->second.current_delay.InSeconds()) |
+ shortest_delay = found->second.current_delay.InSeconds(); |
+ if (delay_seconds != NULL) |
+ *delay_seconds = shortest_delay; |
+ return true; |
+ } |
+ } else { |
+ if (delay_seconds != NULL) |
+ *delay_seconds = shortest_delay; |
+ return true; |
+ } |
+ } |
+ |
+ return false; |
+} |
+ |
+bool DataReductionProxyParams::WereDataReductionProxiesBypassed( |
+ const net::URLRequest* request, int64* delay_seconds) const { |
+ DCHECK(request); |
+ DCHECK(request->context()); |
+ DCHECK(request->context()->proxy_service()); |
+ |
+ const net::ProxyRetryInfoMap& retry_map = |
+ request->context()->proxy_service()->proxy_retry_info(); |
+ if (retry_map.size() == 0) |
+ return false; |
+ |
+ if(allowed_) { |
+ if (WerePrimaryAndFallbackBypassed(retry_map, |
+ origin_, |
+ fallback_origin_, |
+ fallback_allowed_, |
+ delay_seconds)) { |
+ return true; |
+ } |
+ } |
+ |
+ if (alt_allowed_) { |
+ if (WerePrimaryAndFallbackBypassed(retry_map, |
+ alt_origin_, |
+ alt_fallback_origin_, |
+ fallback_allowed_, |
+ delay_seconds)) { |
+ return true; |
+ } |
+ |
+ if (WerePrimaryAndFallbackBypassed( |
+ retry_map, ssl_origin_, GURL(), false, delay_seconds)) { |
+ return true; |
+ } |
+ } |
+ |
+ return false; |
+} |
+ |
std::string DataReductionProxyParams::GetDefaultOrigin() const { |
#if defined(SPDY_PROXY_AUTH_ORIGIN) |
return SPDY_PROXY_AUTH_ORIGIN; |