Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_protocol.cc |
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_protocol.cc |
similarity index 71% |
rename from components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.cc |
rename to components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_protocol.cc |
index a49db111c322bfbc8c7c7bca9bcb0f2f3c28ee66..81aeceae0b07f7cb25d62e20eef72448d7001a62 100644 |
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.cc |
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_protocol.cc |
@@ -2,9 +2,8 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.h" |
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_protocol.h" |
-#include "base/memory/ref_counted.h" |
#include "base/strings/string_number_conversions.h" |
#include "base/time/time.h" |
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h" |
@@ -37,19 +36,63 @@ bool SetProxyServerFromGURL(const GURL& gurl, |
return true; |
} |
+// Adds non-empty entries in |data_reduction_proxies| to the retry map |
+// maintained by the proxy service of the request. Adds |
+// |data_reduction_proxies.second| to the retry list only if |bypass_all| is |
+// true. |
+void MarkProxiesAsBadUntil( |
+ net::URLRequest* request, |
+ const base::TimeDelta& bypass_duration, |
+ bool bypass_all, |
+ const std::pair<GURL, GURL>& data_reduction_proxies) { |
+ DCHECK(!data_reduction_proxies.first.is_empty()); |
+ // Synthesize a suitable |ProxyInfo| to add the proxies to the |
+ // |ProxyRetryInfoMap| of the proxy service. |
+ net::ProxyList proxy_list; |
+ net::ProxyServer primary; |
+ SetProxyServerFromGURL(data_reduction_proxies.first, &primary); |
+ if (primary.is_valid()) |
+ proxy_list.AddProxyServer(primary); |
+ net::ProxyServer fallback; |
+ if (bypass_all) { |
+ if (!data_reduction_proxies.second.is_empty()) |
+ SetProxyServerFromGURL(data_reduction_proxies.second, &fallback); |
+ if (fallback.is_valid()) |
+ proxy_list.AddProxyServer(fallback); |
+ proxy_list.AddProxyServer(net::ProxyServer::Direct()); |
+ } |
+ net::ProxyInfo proxy_info; |
+ proxy_info.UseProxyList(proxy_list); |
+ DCHECK(request->context()); |
+ net::ProxyService* proxy_service = request->context()->proxy_service(); |
+ DCHECK(proxy_service); |
+ |
+ proxy_service->MarkProxiesAsBadUntil(proxy_info, |
+ bypass_duration, |
+ fallback, |
+ request->net_log()); |
+} |
+ |
} // namespace |
namespace data_reduction_proxy { |
-bool MaybeBypassProxyAndPrepareToRetry( |
- const DataReductionProxyParams* data_reduction_proxy_params, |
+DataReductionProxyBypassProtocol::DataReductionProxyBypassProtocol( |
+ DataReductionProxyParams* params, DataReductionProxyEventStore* event_store) |
+ : params_(params), event_store_(event_store) { |
+ DCHECK(params_); |
+ DCHECK(event_store_); |
+ net::NetworkChangeNotifier::AddIPAddressObserver(this); |
+} |
+ |
+DataReductionProxyBypassProtocol::~DataReductionProxyBypassProtocol() { |
+ net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
+} |
+ |
+bool DataReductionProxyBypassProtocol::MaybeBypassProxyAndPrepareToRetry( |
net::URLRequest* request, |
- DataReductionProxyBypassType* proxy_bypass_type, |
- DataReductionProxyEventStore* event_store) { |
+ DataReductionProxyBypassType* proxy_bypass_type) { |
DCHECK(request); |
- if (!data_reduction_proxy_params) |
- return false; |
- |
const net::HttpResponseHeaders* response_headers = |
request->response_info().headers.get(); |
if (!response_headers) |
@@ -61,7 +104,7 @@ bool MaybeBypassProxyAndPrepareToRetry( |
return false; |
DataReductionProxyTypeInfo data_reduction_proxy_type_info; |
- if (!data_reduction_proxy_params->WasDataReductionProxyUsed( |
+ if (!params_->WasDataReductionProxyUsed( |
request, &data_reduction_proxy_type_info)) { |
return false; |
} |
@@ -78,6 +121,13 @@ bool MaybeBypassProxyAndPrepareToRetry( |
!data_reduction_proxy_type_info.proxy_servers.second.is_empty(), |
response_headers); |
+ if (DataReductionProxyParams:: |
+ IsIncludedInRelaxMissingViaHeaderOtherBypassFieldTrial() && |
+ HasDataReductionProxyViaHeader(response_headers, NULL)) { |
+ DCHECK(params_->IsDataReductionProxy(request->proxy_server(), NULL)); |
+ via_header_producing_proxies_.insert(request->proxy_server()); |
+ } |
+ |
// GetDataReductionProxyBypassType will only log a net_log event if a bypass |
// command was sent via the data reduction proxy headers |
bool event_logged = false; |
@@ -85,14 +135,22 @@ bool MaybeBypassProxyAndPrepareToRetry( |
DataReductionProxyBypassType bypass_type = |
GetDataReductionProxyBypassType( |
response_headers, request->url(), request->net_log(), |
- &data_reduction_proxy_info, event_store, &event_logged); |
- |
- if (bypass_type == BYPASS_EVENT_TYPE_MISSING_VIA_HEADER_OTHER && |
- DataReductionProxyParams:: |
- IsIncludedInRemoveMissingViaHeaderOtherBypassFieldTrial()) { |
- // Ignore MISSING_VIA_HEADER_OTHER proxy bypass events if the client is part |
- // of the field trial to remove these kinds of bypasses. |
- bypass_type = BYPASS_EVENT_TYPE_MAX; |
+ &data_reduction_proxy_info, event_store_, &event_logged); |
+ |
+ if (bypass_type == BYPASS_EVENT_TYPE_MISSING_VIA_HEADER_OTHER) { |
+ if (DataReductionProxyParams:: |
+ IsIncludedInRemoveMissingViaHeaderOtherBypassFieldTrial() || |
+ (DataReductionProxyParams:: |
+ IsIncludedInRelaxMissingViaHeaderOtherBypassFieldTrial() && |
+ via_header_producing_proxies_.find(request->proxy_server()) != |
+ via_header_producing_proxies_.end())) { |
+ // Ignore MISSING_VIA_HEADER_OTHER proxy bypass events if the client is |
+ // part of the field trial to remove these kinds of bypasses, or if the |
+ // client is part of the field trial to relax this bypass rule and Chrome |
+ // has previously seen a data reduction proxy via header on a response |
+ // through this proxy since the last network change. |
+ bypass_type = BYPASS_EVENT_TYPE_MAX; |
+ } |
} |
if (proxy_bypass_type) |
@@ -101,7 +159,7 @@ bool MaybeBypassProxyAndPrepareToRetry( |
return false; |
if (!event_logged) { |
- event_store->AddBypassTypeEvent( |
+ event_store_->AddBypassTypeEvent( |
request->net_log(), bypass_type, request->url(), |
data_reduction_proxy_info.bypass_duration); |
} |
@@ -113,7 +171,7 @@ bool MaybeBypassProxyAndPrepareToRetry( |
data_reduction_proxy_type_info.proxy_servers.first, &proxy_server); |
// Only record UMA if the proxy isn't already on the retry list. |
- if (!data_reduction_proxy_params->IsProxyBypassed( |
+ if (!params_->IsProxyBypassed( |
request->context()->proxy_service()->proxy_retry_info(), |
proxy_server, |
NULL)) { |
@@ -141,40 +199,9 @@ bool MaybeBypassProxyAndPrepareToRetry( |
return true; |
} |
-void OnResolveProxyHandler(const GURL& url, |
- int load_flags, |
- const net::ProxyConfig& data_reduction_proxy_config, |
- const net::ProxyRetryInfoMap& proxy_retry_info, |
- const DataReductionProxyParams* params, |
- net::ProxyInfo* result) { |
- DCHECK(params); |
- DCHECK(result->is_empty() || result->is_direct() || |
- !params->IsDataReductionProxy(result->proxy_server().host_port_pair(), |
- NULL)); |
- if (data_reduction_proxy_config.is_valid() && |
- result->proxy_server().is_direct() && |
- result->proxy_list().size() == 1 && |
- !url.SchemeIsWSOrWSS()) { |
- net::ProxyInfo data_reduction_proxy_info; |
- data_reduction_proxy_config.proxy_rules().Apply( |
- url, &data_reduction_proxy_info); |
- data_reduction_proxy_info.DeprioritizeBadProxies(proxy_retry_info); |
- if (!data_reduction_proxy_info.proxy_server().is_direct()) |
- result->OverrideProxyList(data_reduction_proxy_info.proxy_list()); |
- } |
- |
- if ((load_flags & net::LOAD_BYPASS_DATA_REDUCTION_PROXY) && |
- DataReductionProxyParams::IsIncludedInCriticalPathBypassFieldTrial()) { |
- if (!result->is_empty() && |
- !result->is_direct() && |
- params->IsDataReductionProxy(result->proxy_server().host_port_pair(), |
- NULL)) { |
- result->RemoveProxiesWithoutScheme(net::ProxyServer::SCHEME_DIRECT); |
- } |
- } |
-} |
- |
-bool IsRequestIdempotent(const net::URLRequest* request) { |
+// static |
+bool DataReductionProxyBypassProtocol::IsRequestIdempotent( |
+ const net::URLRequest* request) { |
DCHECK(request); |
if (request->method() == "GET" || |
request->method() == "OPTIONS" || |
@@ -186,37 +213,8 @@ bool IsRequestIdempotent(const net::URLRequest* request) { |
return false; |
} |
-void MarkProxiesAsBadUntil( |
- net::URLRequest* request, |
- const base::TimeDelta& bypass_duration, |
- bool bypass_all, |
- const std::pair<GURL, GURL>& data_reduction_proxies) { |
- DCHECK(!data_reduction_proxies.first.is_empty()); |
- // Synthesize a suitable |ProxyInfo| to add the proxies to the |
- // |ProxyRetryInfoMap| of the proxy service. |
- net::ProxyList proxy_list; |
- net::ProxyServer primary; |
- SetProxyServerFromGURL(data_reduction_proxies.first, &primary); |
- if (primary.is_valid()) |
- proxy_list.AddProxyServer(primary); |
- net::ProxyServer fallback; |
- if (bypass_all) { |
- if (!data_reduction_proxies.second.is_empty()) |
- SetProxyServerFromGURL(data_reduction_proxies.second, &fallback); |
- if (fallback.is_valid()) |
- proxy_list.AddProxyServer(fallback); |
- proxy_list.AddProxyServer(net::ProxyServer::Direct()); |
- } |
- net::ProxyInfo proxy_info; |
- proxy_info.UseProxyList(proxy_list); |
- DCHECK(request->context()); |
- net::ProxyService* proxy_service = request->context()->proxy_service(); |
- DCHECK(proxy_service); |
- |
- proxy_service->MarkProxiesAsBadUntil(proxy_info, |
- bypass_duration, |
- fallback, |
- request->net_log()); |
+void DataReductionProxyBypassProtocol::OnIPAddressChanged() { |
+ via_header_producing_proxies_.clear(); |
} |
} // namespace data_reduction_proxy |