Chromium Code Reviews| Index: chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.cc |
| diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.cc b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.cc |
| index cb9e788a19141c70da51ee1a9136e3174f006b5a..c8a06ccee51d2fbe5b193df8a98dd8f9173237f2 100644 |
| --- a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.cc |
| +++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.cc |
| @@ -10,8 +10,10 @@ |
| #include "base/strings/string_util.h" |
| #include "chrome/browser/prefs/proxy_prefs.h" |
| #include "chrome/common/pref_names.h" |
| +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_params.h" |
| #include "net/proxy/proxy_config.h" |
| #include "net/proxy/proxy_info.h" |
| +#include "net/proxy/proxy_list.h" |
| #include "net/proxy/proxy_service.h" |
| DataReductionProxyChromeConfigurator::DataReductionProxyChromeConfigurator( |
| @@ -23,6 +25,27 @@ DataReductionProxyChromeConfigurator::DataReductionProxyChromeConfigurator( |
| DataReductionProxyChromeConfigurator::~DataReductionProxyChromeConfigurator() { |
| } |
| +// static |
| +void DataReductionProxyChromeConfigurator::DisableInProxyConfigPref( |
| + PrefService* prefs) { |
| + DCHECK(prefs); |
| + DictionaryPrefUpdate update(prefs, prefs::kProxy); |
| + base::DictionaryValue* dict = update.Get(); |
|
bengr
2014/10/29 23:41:25
#include "base/values.h"
Not at Google. Contact bengr
2014/10/30 00:05:03
Done.
|
| + std::string mode; |
| + dict->GetString("mode", &mode); |
| + std::string server; |
| + dict->GetString("server", &server); |
| + net::ProxyConfig::ProxyRules proxy_rules; |
| + proxy_rules.ParseFromString(server); |
| + if (mode != ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS) |
|
bengr
2014/10/29 23:41:25
Add comment:
The data reduction proxy uses MODE_FI
Not at Google. Contact bengr
2014/10/30 00:05:03
Done.
|
| + || !ContainsDataReductionProxy(proxy_rules)) { |
| + return; |
| + } |
| + dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); |
| + dict->SetString("server", ""); |
| + dict->SetString("bypass_list", ""); |
| +} |
| + |
| void DataReductionProxyChromeConfigurator::Enable( |
| bool primary_restricted, |
| bool fallback_restricted, |
| @@ -85,12 +108,7 @@ void DataReductionProxyChromeConfigurator::Enable( |
| } |
| void DataReductionProxyChromeConfigurator::Disable() { |
| - DCHECK(prefs_); |
| - DictionaryPrefUpdate update(prefs_, prefs::kProxy); |
| - base::DictionaryValue* dict = update.Get(); |
| - dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); |
| - dict->SetString("server", ""); |
| - dict->SetString("bypass_list", ""); |
| + DisableInProxyConfigPref(prefs_); |
| net::ProxyConfig config = net::ProxyConfig::CreateDirect(); |
| network_task_runner_->PostTask( |
| FROM_HERE, |
| @@ -120,6 +138,40 @@ void DataReductionProxyChromeConfigurator::AddURLPatternToBypass( |
| AddHostPatternToBypass(host_pattern); |
| } |
| +// static |
| +bool DataReductionProxyChromeConfigurator::ContainsDataReductionProxy( |
|
bengr
2014/10/29 23:41:25
Again, talk to megjablon@
Not at Google. Contact bengr
2014/10/30 00:05:03
Done.
|
| + const net::ProxyConfig::ProxyRules& proxy_rules) { |
| + data_reduction_proxy::DataReductionProxyParams params( |
|
bengr
2014/10/29 23:41:25
Suggestion (not required): Add a flag for kEveryth
Not at Google. Contact bengr
2014/10/30 00:05:03
Done.
|
| + data_reduction_proxy::DataReductionProxyParams::kAllowed | |
| + data_reduction_proxy::DataReductionProxyParams::kFallbackAllowed | |
| + data_reduction_proxy::DataReductionProxyParams::kAlternativeAllowed | |
| + data_reduction_proxy::DataReductionProxyParams:: |
| + kAlternativeFallbackAllowed); |
| + if (proxy_rules.type != net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME) { |
|
bengr
2014/10/29 23:41:25
Curly braces not needed.
Not at Google. Contact bengr
2014/10/30 00:05:03
Done.
|
| + return false; |
| + } |
| + |
| + const net::ProxyList* https_proxy_list = |
| + proxy_rules.MapUrlSchemeToProxyList("https"); |
| + if (https_proxy_list && !https_proxy_list->IsEmpty() && |
| + // Sufficient to check only the first proxy. |
| + params.IsDataReductionProxy(https_proxy_list->Get().host_port_pair(), |
| + NULL)) { |
| + return true; |
| + } |
| + |
| + const net::ProxyList* http_proxy_list = |
| + proxy_rules.MapUrlSchemeToProxyList("http"); |
| + if (http_proxy_list && !http_proxy_list->IsEmpty() && |
| + // Sufficient to check only the first proxy. |
| + params.IsDataReductionProxy(http_proxy_list->Get().host_port_pair(), |
| + NULL)) { |
| + return true; |
| + } |
| + |
| + return false; |
| +} |
| + |
| void DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO( |
| const net::ProxyConfig& config) { |
| config_ = config; |