Commit 85e57d4d authored by bengr@chromium.org's avatar bengr@chromium.org

Added alternative configuration for the data reduction proxy

Added a second configuration that can support two http proxies and one https proxy. In the process, added a new DataReductionProxyParams object to encapsulate static configuration details and made DataReductionSettingsAndroid a BrowserKeyedContextService.

BUG=370039

Review URL: https://codereview.chromium.org/286013002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273810 0039d316-1c4b-4281-b951-d872f2087c98
parent 4fd1906b
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/prefs/pref_service_factory.h" #include "base/prefs/pref_service_factory.h"
#include "components/autofill/core/common/autofill_pref_names.h" #include "components/autofill/core/common/autofill_pref_names.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_config_service.h" #include "components/data_reduction_proxy/browser/data_reduction_proxy_config_service.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_prefs.h" #include "components/data_reduction_proxy/browser/data_reduction_proxy_prefs.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h" #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h"
#include "components/user_prefs/user_prefs.h" #include "components/user_prefs/user_prefs.h"
...@@ -94,21 +95,23 @@ void AwBrowserContext::SetDataReductionProxyEnabled(bool enabled) { ...@@ -94,21 +95,23 @@ void AwBrowserContext::SetDataReductionProxyEnabled(bool enabled) {
void AwBrowserContext::PreMainMessageLoopRun() { void AwBrowserContext::PreMainMessageLoopRun() {
cookie_store_ = CreateCookieStore(this); cookie_store_ = CreateCookieStore(this);
DataReductionProxySettings::SetAllowed(true); #if defined(SPDY_PROXY_AUTH_ORIGIN)
DataReductionProxySettings::SetPromoAllowed(false);
data_reduction_proxy_settings_.reset( data_reduction_proxy_settings_.reset(
new DataReductionProxySettings()); new DataReductionProxySettings(
data_reduction_proxy_settings_->set_fallback_allowed(false); new data_reduction_proxy::DataReductionProxyParams(
data_reduction_proxy::DataReductionProxyParams::kAllowed)));
#endif
url_request_context_getter_ = url_request_context_getter_ =
new AwURLRequestContextGetter(GetPath(), cookie_store_.get()); new AwURLRequestContextGetter(GetPath(), cookie_store_.get());
scoped_ptr<data_reduction_proxy::DataReductionProxyConfigurator> if (data_reduction_proxy_settings_.get()) {
configurator(new data_reduction_proxy::DataReductionProxyConfigTracker( scoped_ptr<data_reduction_proxy::DataReductionProxyConfigurator>
url_request_context_getter_->proxy_config_service(), configurator(new data_reduction_proxy::DataReductionProxyConfigTracker(
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); url_request_context_getter_->proxy_config_service(),
data_reduction_proxy_settings_->SetProxyConfigurator(configurator.Pass()); BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
data_reduction_proxy_settings_->SetProxyConfigurator(configurator.Pass());
}
visitedlink_master_.reset( visitedlink_master_.reset(
new visitedlink::VisitedLinkMaster(this, this, false)); new visitedlink::VisitedLinkMaster(this, this, false));
visitedlink_master_->Init(); visitedlink_master_->Init();
...@@ -183,13 +186,15 @@ void AwBrowserContext::CreateUserPrefServiceIfNecessary() { ...@@ -183,13 +186,15 @@ void AwBrowserContext::CreateUserPrefServiceIfNecessary() {
user_prefs::UserPrefs::Set(this, user_pref_service_.get()); user_prefs::UserPrefs::Set(this, user_pref_service_.get());
data_reduction_proxy_settings_->InitDataReductionProxySettings( if (data_reduction_proxy_settings_.get()) {
user_pref_service_.get(), data_reduction_proxy_settings_->InitDataReductionProxySettings(
user_pref_service_.get(), user_pref_service_.get(),
GetRequestContext()); user_pref_service_.get(),
GetRequestContext());
data_reduction_proxy_settings_->SetDataReductionProxyEnabled( data_reduction_proxy_settings_->SetDataReductionProxyEnabled(
data_reduction_proxy_enabled_); data_reduction_proxy_enabled_);
}
} }
base::FilePath AwBrowserContext::GetPath() const { base::FilePath AwBrowserContext::GetPath() const {
......
...@@ -200,11 +200,14 @@ void AwURLRequestContextGetter::InitializeURLRequestContext() { ...@@ -200,11 +200,14 @@ void AwURLRequestContextGetter::InitializeURLRequestContext() {
AwContentBrowserClient::GetAcceptLangsImpl())); AwContentBrowserClient::GetAcceptLangsImpl()));
ApplyCmdlineOverridesToURLRequestContextBuilder(&builder); ApplyCmdlineOverridesToURLRequestContextBuilder(&builder);
#if defined(SPDY_PROXY_AUTH_ORIGIN)
data_reduction_proxy::DataReductionProxyParams drp_params(
data_reduction_proxy::DataReductionProxyParams::kAllowed);
builder.add_http_auth_handler_factory( builder.add_http_auth_handler_factory(
data_reduction_proxy::HttpAuthHandlerDataReductionProxy::Scheme(), data_reduction_proxy::HttpAuthHandlerDataReductionProxy::Scheme(),
new data_reduction_proxy::HttpAuthHandlerDataReductionProxy::Factory( new data_reduction_proxy::HttpAuthHandlerDataReductionProxy::Factory(
DataReductionProxySettings::GetDataReductionProxies())); drp_params.GetAllowedProxies()));
#endif
url_request_context_.reset(builder.Build()); url_request_context_.reset(builder.Build());
// TODO(mnaganov): Fix URLRequestContextBuilder to use proper threads. // TODO(mnaganov): Fix URLRequestContextBuilder to use proper threads.
...@@ -222,18 +225,21 @@ void AwURLRequestContextGetter::InitializeURLRequestContext() { ...@@ -222,18 +225,21 @@ void AwURLRequestContextGetter::InitializeURLRequestContext() {
20 * 1024 * 1024, // 20M 20 * 1024 * 1024, // 20M
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE))); BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)));
#if defined(SPDY_PROXY_AUTH_ORIGIN)
AwBrowserContext* browser_context = AwBrowserContext::GetDefault(); AwBrowserContext* browser_context = AwBrowserContext::GetDefault();
DCHECK(browser_context); DCHECK(browser_context);
DataReductionProxySettings* drp_settings = DataReductionProxySettings* drp_settings =
browser_context->GetDataReductionProxySettings(); browser_context->GetDataReductionProxySettings();
DCHECK(drp_settings); if (drp_settings) {
std::string drp_key = drp_settings->key(); std::string drp_key = drp_settings->params()->key();
// Only precache credentials if a key is available at URLRequestContext // Only precache credentials if a key is available at URLRequestContext
// initialization. // initialization.
if (!drp_key.empty()) { if (!drp_key.empty()) {
DataReductionProxySettings::InitDataReductionProxySession( DataReductionProxySettings::InitDataReductionProxySession(
main_cache->GetSession(), drp_settings->key()); main_cache->GetSession(), &drp_params);
}
} }
#endif
main_http_factory_.reset(main_cache); main_http_factory_.reset(main_cache);
url_request_context_->set_http_transaction_factory(main_cache); url_request_context_->set_http_transaction_factory(main_cache);
......
...@@ -54,8 +54,8 @@ void SetDataReductionProxyKey(JNIEnv* env, jclass, jstring key) { ...@@ -54,8 +54,8 @@ void SetDataReductionProxyKey(JNIEnv* env, jclass, jstring key) {
DCHECK(browser_context); DCHECK(browser_context);
DataReductionProxySettings* drp_settings = DataReductionProxySettings* drp_settings =
browser_context->GetDataReductionProxySettings(); browser_context->GetDataReductionProxySettings();
DCHECK(drp_settings); if (drp_settings)
drp_settings->set_key(ConvertJavaStringToUTF8(env, key)); drp_settings->params()->set_key(ConvertJavaStringToUTF8(env, key));
} }
// static // static
......
...@@ -550,6 +550,9 @@ ...@@ -550,6 +550,9 @@
'spdy_proxy_auth_property%' : '', 'spdy_proxy_auth_property%' : '',
'spdy_proxy_auth_value%' : '', 'spdy_proxy_auth_value%' : '',
'data_reduction_proxy_probe_url%' : '', 'data_reduction_proxy_probe_url%' : '',
'data_reduction_proxy_ssl_origin%' : '',
'data_reduction_proxy_alt_origin%' : '',
'data_reduction_proxy_alt_fallback_origin%' : '',
'enable_mdns%' : 0, 'enable_mdns%' : 0,
'enable_service_discovery%': 0, 'enable_service_discovery%': 0,
'enable_wifi_bootstrapping%': 0, 'enable_wifi_bootstrapping%': 0,
...@@ -1099,6 +1102,9 @@ ...@@ -1099,6 +1102,9 @@
'spdy_proxy_auth_property%': '<(spdy_proxy_auth_property)', 'spdy_proxy_auth_property%': '<(spdy_proxy_auth_property)',
'spdy_proxy_auth_value%': '<(spdy_proxy_auth_value)', 'spdy_proxy_auth_value%': '<(spdy_proxy_auth_value)',
'data_reduction_proxy_probe_url%': '<(data_reduction_proxy_probe_url)', 'data_reduction_proxy_probe_url%': '<(data_reduction_proxy_probe_url)',
'data_reduction_proxy_ssl_origin%' : '<(data_reduction_proxy_ssl_origin)',
'data_reduction_proxy_alt_origin%' : '<(data_reduction_proxy_alt_origin)',
'data_reduction_proxy_alt_fallback_origin%' : '<(data_reduction_proxy_alt_fallback_origin)',
'enable_mdns%' : '<(enable_mdns)', 'enable_mdns%' : '<(enable_mdns)',
'enable_service_discovery%' : '<(enable_service_discovery)', 'enable_service_discovery%' : '<(enable_service_discovery)',
'enable_wifi_bootstrapping%': '<(enable_wifi_bootstrapping)', 'enable_wifi_bootstrapping%': '<(enable_wifi_bootstrapping)',
...@@ -2718,6 +2724,18 @@ ...@@ -2718,6 +2724,18 @@
'defines': [ 'defines': [
'DATA_REDUCTION_PROXY_PROBE_URL="<(data_reduction_proxy_probe_url)"'], 'DATA_REDUCTION_PROXY_PROBE_URL="<(data_reduction_proxy_probe_url)"'],
}], }],
['data_reduction_proxy_ssl_origin != ""', {
'defines': [
'DATA_REDUCTION_PROXY_SSL_ORIGIN="<(data_reduction_proxy_ssl_origin)"'],
}],
['data_reduction_proxy_alt_origin != ""', {
'defines': [
'DATA_REDUCTION_PROXY_ALT_ORIGIN="<(data_reduction_proxy_alt_origin)"'],
}],
['data_reduction_proxy_alt_fallback_origin != ""', {
'defines': [
'DATA_REDUCTION_PROXY_ALT_FALLBACK_ORIGIN="<(data_reduction_proxy_alt_fallback_origin)"'],
}],
['enable_mdns==1', { ['enable_mdns==1', {
'defines': ['ENABLE_MDNS=1'], 'defines': ['ENABLE_MDNS=1'],
}], }],
......
...@@ -10,8 +10,15 @@ import org.chromium.base.ThreadUtils; ...@@ -10,8 +10,15 @@ import org.chromium.base.ThreadUtils;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.Locale; import java.util.Locale;
/**
* Entry point to manage all data reduction proxy configuration details.
*/
public class DataReductionProxySettings { public class DataReductionProxySettings {
/**
* Data structure to hold the original content length before data reduction and the received
* content length after data reduction.
*/
public static class ContentLengths { public static class ContentLengths {
private final long mOriginal; private final long mOriginal;
private final long mReceived; private final long mReceived;
...@@ -37,6 +44,9 @@ public class DataReductionProxySettings { ...@@ -37,6 +44,9 @@ public class DataReductionProxySettings {
private static DataReductionProxySettings sSettings; private static DataReductionProxySettings sSettings;
/**
* Returns a singleton instance of the settings object.
*/
public static DataReductionProxySettings getInstance() { public static DataReductionProxySettings getInstance() {
ThreadUtils.assertOnUiThread(); ThreadUtils.assertOnUiThread();
if (sSettings == null) { if (sSettings == null) {
...@@ -52,14 +62,6 @@ public class DataReductionProxySettings { ...@@ -52,14 +62,6 @@ public class DataReductionProxySettings {
// DataReductionProxySettings is a singleton that lives forever and there's no clean // DataReductionProxySettings is a singleton that lives forever and there's no clean
// shutdown of Chrome on Android // shutdown of Chrome on Android
mNativeDataReductionProxySettings = nativeInit(); mNativeDataReductionProxySettings = nativeInit();
initDataReductionProxySettings();
}
/**
* Initializes the data reduction proxy at Chrome startup.
*/
public void initDataReductionProxySettings() {
nativeInitDataReductionProxySettings(mNativeDataReductionProxySettings);
} }
/** /**
...@@ -191,8 +193,6 @@ public class DataReductionProxySettings { ...@@ -191,8 +193,6 @@ public class DataReductionProxySettings {
} }
private native long nativeInit(); private native long nativeInit();
private native void nativeInitDataReductionProxySettings(
long nativeDataReductionProxySettingsAndroid);
private native void nativeBypassHostPattern( private native void nativeBypassHostPattern(
long nativeDataReductionProxySettingsAndroid, String pattern); long nativeDataReductionProxySettingsAndroid, String pattern);
private native void nativeBypassURLPattern( private native void nativeBypassURLPattern(
......
...@@ -95,6 +95,7 @@ ...@@ -95,6 +95,7 @@
#endif #endif
#if defined(OS_ANDROID) || defined(OS_IOS) #if defined(OS_ANDROID) || defined(OS_IOS)
#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h" #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h"
#endif #endif
...@@ -106,6 +107,7 @@ ...@@ -106,6 +107,7 @@
using content::BrowserThread; using content::BrowserThread;
#if defined(OS_ANDROID) || defined(OS_IOS) #if defined(OS_ANDROID) || defined(OS_IOS)
using data_reduction_proxy::DataReductionProxyParams;
using data_reduction_proxy::DataReductionProxySettings; using data_reduction_proxy::DataReductionProxySettings;
#endif #endif
...@@ -595,10 +597,17 @@ void IOThread::InitAsync() { ...@@ -595,10 +597,17 @@ void IOThread::InitAsync() {
#endif #endif
globals_->ssl_config_service = GetSSLConfigService(); globals_->ssl_config_service = GetSSLConfigService();
#if defined(OS_ANDROID) || defined(OS_IOS) #if defined(OS_ANDROID) || defined(OS_IOS)
if (DataReductionProxySettings::IsIncludedInFieldTrialOrFlags()) { #if defined(SPDY_PROXY_AUTH_ORIGIN)
spdyproxy_auth_origins_ = int drp_flags = DataReductionProxyParams::kFallbackAllowed;
DataReductionProxySettings::GetDataReductionProxies(); if (DataReductionProxyParams::IsIncludedInFieldTrial())
} drp_flags |= DataReductionProxyParams::kAllowed;
if (DataReductionProxyParams::IsIncludedInAlternativeFieldTrial())
drp_flags |= DataReductionProxyParams::kAlternativeAllowed;
if (DataReductionProxyParams::IsIncludedInPromoFieldTrial())
drp_flags |= DataReductionProxyParams::kPromoAllowed;
globals_->data_reduction_proxy_params.reset(
new DataReductionProxyParams(drp_flags));
#endif // defined(SPDY_PROXY_AUTH_ORIGIN)
#endif // defined(OS_ANDROID) || defined(OS_IOS) #endif // defined(OS_ANDROID) || defined(OS_IOS)
globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory(
globals_->host_resolver.get())); globals_->host_resolver.get()));
...@@ -901,11 +910,15 @@ net::HttpAuthHandlerFactory* IOThread::CreateDefaultAuthHandlerFactory( ...@@ -901,11 +910,15 @@ net::HttpAuthHandlerFactory* IOThread::CreateDefaultAuthHandlerFactory(
resolver, gssapi_library_name_, negotiate_disable_cname_lookup_, resolver, gssapi_library_name_, negotiate_disable_cname_lookup_,
negotiate_enable_port_)); negotiate_enable_port_));
if (!spdyproxy_auth_origins_.empty()) { if (globals_->data_reduction_proxy_params.get()) {
registry_factory->RegisterSchemeFactory( std::vector<GURL> data_reduction_proxies =
"spdyproxy", globals_->data_reduction_proxy_params->GetAllowedProxies();
new data_reduction_proxy::HttpAuthHandlerDataReductionProxy::Factory( if (!data_reduction_proxies.empty()) {
spdyproxy_auth_origins_)); registry_factory->RegisterSchemeFactory(
"spdyproxy",
new data_reduction_proxy::HttpAuthHandlerDataReductionProxy::Factory(
data_reduction_proxies));
}
} }
return registry_factory.release(); return registry_factory.release();
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/prefs/pref_member.h" #include "base/prefs/pref_member.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/net/ssl_config_service_manager.h" #include "chrome/browser/net/ssl_config_service_manager.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/browser_thread_delegate.h" #include "content/public/browser/browser_thread_delegate.h"
#include "net/base/network_change_notifier.h" #include "net/base/network_change_notifier.h"
...@@ -181,6 +182,8 @@ class IOThread : public content::BrowserThreadDelegate { ...@@ -181,6 +182,8 @@ class IOThread : public content::BrowserThreadDelegate {
// main frame load fails with a DNS error in order to provide more useful // main frame load fails with a DNS error in order to provide more useful
// information to the renderer so it can show a more specific error page. // information to the renderer so it can show a more specific error page.
scoped_ptr<chrome_browser_net::DnsProbeService> dns_probe_service; scoped_ptr<chrome_browser_net::DnsProbeService> dns_probe_service;
scoped_ptr<data_reduction_proxy::DataReductionProxyParams>
data_reduction_proxy_params;
}; };
// |net_log| must either outlive the IOThread or be NULL. // |net_log| must either outlive the IOThread or be NULL.
...@@ -348,7 +351,6 @@ class IOThread : public content::BrowserThreadDelegate { ...@@ -348,7 +351,6 @@ class IOThread : public content::BrowserThreadDelegate {
std::string auth_server_whitelist_; std::string auth_server_whitelist_;
std::string auth_delegate_whitelist_; std::string auth_delegate_whitelist_;
std::string gssapi_library_name_; std::string gssapi_library_name_;
std::vector<GURL> spdyproxy_auth_origins_;
// This is an instance of the default SSLConfigServiceManager for the current // This is an instance of the default SSLConfigServiceManager for the current
// platform and it gets SSL preferences from local_state object. // platform and it gets SSL preferences from local_state object.
......
...@@ -337,8 +337,8 @@ void Predictor::InitNetworkPredictor(PrefService* user_prefs, ...@@ -337,8 +337,8 @@ void Predictor::InitNetworkPredictor(PrefService* user_prefs,
// Until then, we may create a proxy advisor when the proxy feature itself // Until then, we may create a proxy advisor when the proxy feature itself
// isn't available, and the advisor instance will never send advisory // isn't available, and the advisor instance will never send advisory
// requests, which is slightly wasteful but not harmful. // requests, which is slightly wasteful but not harmful.
if (data_reduction_proxy::DataReductionProxySettings:: if (data_reduction_proxy::DataReductionProxyParams::
IsPreconnectHintingAllowed()) { IsIncludedInPreconnectHintingFieldTrial()) {
proxy_advisor_.reset(new ProxyAdvisor(user_prefs, getter)); proxy_advisor_.reset(new ProxyAdvisor(user_prefs, getter));
} }
#endif #endif
......
...@@ -18,10 +18,12 @@ DataReductionProxyChromeConfigurator::DataReductionProxyChromeConfigurator( ...@@ -18,10 +18,12 @@ DataReductionProxyChromeConfigurator::DataReductionProxyChromeConfigurator(
DataReductionProxyChromeConfigurator::~DataReductionProxyChromeConfigurator() { DataReductionProxyChromeConfigurator::~DataReductionProxyChromeConfigurator() {
} }
void DataReductionProxyChromeConfigurator::Enable(bool primary_restricted, void DataReductionProxyChromeConfigurator::Enable(
bool fallback_restricted, bool primary_restricted,
const std::string& primary_origin, bool fallback_restricted,
const std::string& fallback_origin) { const std::string& primary_origin,
const std::string& fallback_origin,
const std::string& ssl_origin) {
DCHECK(prefs_); DCHECK(prefs_);
DictionaryPrefUpdate update(prefs_, prefs::kProxy); DictionaryPrefUpdate update(prefs_, prefs::kProxy);
base::DictionaryValue* dict = update.Get(); base::DictionaryValue* dict = update.Get();
...@@ -49,7 +51,13 @@ void DataReductionProxyChromeConfigurator::Enable(bool primary_restricted, ...@@ -49,7 +51,13 @@ void DataReductionProxyChromeConfigurator::Enable(bool primary_restricted,
return; return;
} }
dict->SetString("server", "http=" + JoinString(proxies, ",") + ",direct://;"); std::string trimmed_ssl;
base::TrimString(ssl_origin, "/", &trimmed_ssl);
std::string server = "http=" + JoinString(proxies, ",") + ",direct://;"
+ (ssl_origin.empty() ? "" : ("https=" + trimmed_ssl + ",direct://;"));
dict->SetString("server", server);
dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS)); dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS));
dict->SetString("bypass_list", JoinString(bypass_rules_, ", ")); dict->SetString("bypass_list", JoinString(bypass_rules_, ", "));
} }
......
...@@ -22,7 +22,8 @@ class DataReductionProxyChromeConfigurator ...@@ -22,7 +22,8 @@ class DataReductionProxyChromeConfigurator
virtual void Enable(bool primary_restricted, virtual void Enable(bool primary_restricted,
bool fallback_restricted, bool fallback_restricted,
const std::string& primary_origin, const std::string& primary_origin,
const std::string& fallback_origin) OVERRIDE; const std::string& fallback_origin,
const std::string& ssl_origin) OVERRIDE;
virtual void Disable() OVERRIDE; virtual void Disable() OVERRIDE;
// Add a host pattern to bypass. This should follow the same syntax used // Add a host pattern to bypass. This should follow the same syntax used
......
...@@ -48,19 +48,35 @@ TEST_F(DataReductionProxyConfigTest, TestUnrestricted) { ...@@ -48,19 +48,35 @@ TEST_F(DataReductionProxyConfigTest, TestUnrestricted) {
config_->Enable(false, config_->Enable(false,
false, false,
"https://www.foo.com:443/", "https://www.foo.com:443/",
"http://www.bar.com:80/"); "http://www.bar.com:80/",
"");
CheckProxyConfig( CheckProxyConfig(
"fixed_servers", "fixed_servers",
"http=https://www.foo.com:443,http://www.bar.com:80,direct://;", "http=https://www.foo.com:443,http://www.bar.com:80,direct://;",
""); "");
} }
TEST_F(DataReductionProxyConfigTest, TestUnrestrictedSSL) {
config_->Enable(false,
false,
"https://www.foo.com:443/",
"http://www.bar.com:80/",
"http://www.ssl.com:80/");
CheckProxyConfig(
"fixed_servers",
"http=https://www.foo.com:443,http://www.bar.com:80,direct://;"
"https=http://www.ssl.com:80,direct://;",
"");
}
TEST_F(DataReductionProxyConfigTest, TestUnrestrictedWithBypassRule) { TEST_F(DataReductionProxyConfigTest, TestUnrestrictedWithBypassRule) {
config_->AddHostPatternToBypass("<local>"); config_->AddHostPatternToBypass("<local>");
config_->AddHostPatternToBypass("*.goo.com"); config_->AddHostPatternToBypass("*.goo.com");
config_->Enable(false, config_->Enable(false,
false, false,
"https://www.foo.com:443/", "https://www.foo.com:443/",
"http://www.bar.com:80/"); "http://www.bar.com:80/",
"");
CheckProxyConfig( CheckProxyConfig(
"fixed_servers", "fixed_servers",
"http=https://www.foo.com:443,http://www.bar.com:80,direct://;", "http=https://www.foo.com:443,http://www.bar.com:80,direct://;",
...@@ -68,10 +84,7 @@ TEST_F(DataReductionProxyConfigTest, TestUnrestrictedWithBypassRule) { ...@@ -68,10 +84,7 @@ TEST_F(DataReductionProxyConfigTest, TestUnrestrictedWithBypassRule) {
} }
TEST_F(DataReductionProxyConfigTest, TestUnrestrictedWithoutFallback) { TEST_F(DataReductionProxyConfigTest, TestUnrestrictedWithoutFallback) {
config_->Enable(false, config_->Enable(false, false, "https://www.foo.com:443/", "", "");
false,
"https://www.foo.com:443/",
"");
CheckProxyConfig("fixed_servers", CheckProxyConfig("fixed_servers",
"http=https://www.foo.com:443,direct://;", "http=https://www.foo.com:443,direct://;",
""); "");
...@@ -81,7 +94,8 @@ TEST_F(DataReductionProxyConfigTest, TestRestricted) { ...@@ -81,7 +94,8 @@ TEST_F(DataReductionProxyConfigTest, TestRestricted) {
config_->Enable(true, config_->Enable(true,
false, false,
"https://www.foo.com:443/", "https://www.foo.com:443/",
"http://www.bar.com:80/"); "http://www.bar.com:80/",
"");
CheckProxyConfig("fixed_servers", CheckProxyConfig("fixed_servers",
"http=http://www.bar.com:80,direct://;", "http=http://www.bar.com:80,direct://;",
""); "");
...@@ -91,7 +105,8 @@ TEST_F(DataReductionProxyConfigTest, TestFallbackRestricted) { ...@@ -91,7 +105,8 @@ TEST_F(DataReductionProxyConfigTest, TestFallbackRestricted) {
config_->Enable(false, config_->Enable(false,
true, true,
"https://www.foo.com:443/", "https://www.foo.com:443/",
"http://www.bar.com:80/"); "http://www.bar.com:80/",
"");
CheckProxyConfig("fixed_servers", CheckProxyConfig("fixed_servers",
"http=https://www.foo.com:443,direct://;", "http=https://www.foo.com:443,direct://;",
""); "");
...@@ -101,7 +116,8 @@ TEST_F(DataReductionProxyConfigTest, TestBothRestricted) { ...@@ -101,7 +116,8 @@ TEST_F(DataReductionProxyConfigTest, TestBothRestricted) {
config_->Enable(true, config_->Enable(true,
true, true,
"https://www.foo.com:443/", "https://www.foo.com:443/",
"http://www.bar.com:80/"); "http://www.bar.com:80/",
"");
CheckProxyConfig("system", "", ""); CheckProxyConfig("system", "", "");
} }
......
...@@ -18,12 +18,14 @@ ...@@ -18,12 +18,14 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.h" #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.h"
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings_factory_android.h"
#include "chrome/browser/prefs/proxy_prefs.h" #include "chrome/browser/prefs/proxy_prefs.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_configurator.h" #include "components/data_reduction_proxy/browser/data_reduction_proxy_configurator.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h" #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h"
#include "jni/DataReductionProxySettings_jni.h" #include "jni/DataReductionProxySettings_jni.h"
#include "net/base/auth.h" #include "net/base/auth.h"
...@@ -39,6 +41,7 @@ using base::android::ConvertJavaStringToUTF8; ...@@ -39,6 +41,7 @@ using base::android::ConvertJavaStringToUTF8;
using base::android::ConvertUTF16ToJavaString; using base::android::ConvertUTF16ToJavaString;
using base::android::ConvertUTF8ToJavaString; using base::android::ConvertUTF8ToJavaString;
using base::android::ScopedJavaLocalRef; using base::android::ScopedJavaLocalRef;
using data_reduction_proxy::DataReductionProxyParams;
using data_reduction_proxy::DataReductionProxySettings; using data_reduction_proxy::DataReductionProxySettings;
namespace { namespace {
...@@ -55,33 +58,20 @@ enum { ...@@ -55,33 +58,20 @@ enum {
NUM_SPDY_PROXY_AUTH_STATE NUM_SPDY_PROXY_AUTH_STATE
}; };
const char kEnabled[] = "Enabled";
} // namespace } // namespace
DataReductionProxySettingsAndroid::DataReductionProxySettingsAndroid( DataReductionProxySettingsAndroid::DataReductionProxySettingsAndroid(
JNIEnv* env, jobject obj) : DataReductionProxySettings() { data_reduction_proxy::DataReductionProxyParams* params)
#if defined(SPDY_PROXY_AUTH_VALUE) : DataReductionProxySettings(params) {
set_key(SPDY_PROXY_AUTH_VALUE);
#endif
SetAllowed(IsIncludedInFieldTrialOrFlags());
SetPromoAllowed(base::FieldTrialList::FindFullName(
"DataCompressionProxyPromoVisibility") == kEnabled);
}
DataReductionProxySettingsAndroid::DataReductionProxySettingsAndroid() {
#if defined(SPDY_PROXY_AUTH_VALUE)
set_key(SPDY_PROXY_AUTH_VALUE);
#endif
} }
DataReductionProxySettingsAndroid::~DataReductionProxySettingsAndroid() { DataReductionProxySettingsAndroid::~DataReductionProxySettingsAndroid() {
} }
void DataReductionProxySettingsAndroid::InitDataReductionProxySettings( void DataReductionProxySettingsAndroid::InitDataReductionProxySettings(
JNIEnv* env, Profile* profile) {
jobject obj) { DCHECK(profile);
PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs(); PrefService* prefs = profile->GetPrefs();
scoped_ptr<data_reduction_proxy::DataReductionProxyConfigurator> scoped_ptr<data_reduction_proxy::DataReductionProxyConfigurator>
configurator(new DataReductionProxyChromeConfigurator(prefs)); configurator(new DataReductionProxyChromeConfigurator(prefs));
...@@ -90,33 +80,34 @@ void DataReductionProxySettingsAndroid::InitDataReductionProxySettings( ...@@ -90,33 +80,34 @@ void DataReductionProxySettingsAndroid::InitDataReductionProxySettings(
prefs, prefs,
g_browser_process->local_state(), g_browser_process->local_state(),
ProfileManager::GetActiveUserProfile()->GetRequestContext()); ProfileManager::GetActiveUserProfile()->GetRequestContext());
DataReductionProxySettings::SetDataReductionProxyAlternativeEnabled(
DataReductionProxyParams::IsIncludedInAlternativeFieldTrial());
} }
void DataReductionProxySettingsAndroid::BypassHostPattern( void DataReductionProxySettingsAndroid::BypassHostPattern(
JNIEnv* env, jobject obj, jstring pattern) { JNIEnv* env, jobject obj, jstring pattern) {
config()->AddHostPatternToBypass( configurator()->AddHostPatternToBypass(
ConvertJavaStringToUTF8(env, pattern)); ConvertJavaStringToUTF8(env, pattern));
} }
void DataReductionProxySettingsAndroid::BypassURLPattern( void DataReductionProxySettingsAndroid::BypassURLPattern(
JNIEnv* env, jobject obj, jstring pattern) { JNIEnv* env, jobject obj, jstring pattern) {
config()->AddURLPatternToBypass(ConvertJavaStringToUTF8(env, pattern)); configurator()->AddURLPatternToBypass(ConvertJavaStringToUTF8(env, pattern));
} }
jboolean DataReductionProxySettingsAndroid::IsDataReductionProxyAllowed( jboolean DataReductionProxySettingsAndroid::IsDataReductionProxyAllowed(
JNIEnv* env, jobject obj) { JNIEnv* env, jobject obj) {
return DataReductionProxySettings::IsDataReductionProxyAllowed(); return params()->allowed();
} }
jboolean DataReductionProxySettingsAndroid::IsDataReductionProxyPromoAllowed( jboolean DataReductionProxySettingsAndroid::IsDataReductionProxyPromoAllowed(
JNIEnv* env, jobject obj) { JNIEnv* env, jobject obj) {
return DataReductionProxySettings::IsDataReductionProxyPromoAllowed(); return params()->promo_allowed();
} }
ScopedJavaLocalRef<jstring> ScopedJavaLocalRef<jstring>
DataReductionProxySettingsAndroid::GetDataReductionProxyOrigin( DataReductionProxySettingsAndroid::GetDataReductionProxyOrigin(
JNIEnv* env, jobject obj) { JNIEnv* env, jobject obj) {
return ConvertUTF8ToJavaString( return ConvertUTF8ToJavaString(env, params()->origin().spec());
env, DataReductionProxySettings::GetDataReductionProxyOrigin());
} }
jboolean DataReductionProxySettingsAndroid::IsDataReductionProxyEnabled( jboolean DataReductionProxySettingsAndroid::IsDataReductionProxyEnabled(
...@@ -210,26 +201,38 @@ void DataReductionProxySettingsAndroid::AddDefaultProxyBypassRules() { ...@@ -210,26 +201,38 @@ void DataReductionProxySettingsAndroid::AddDefaultProxyBypassRules() {
DataReductionProxySettings::AddDefaultProxyBypassRules(); DataReductionProxySettings::AddDefaultProxyBypassRules();
// Chrome cannot authenticate with the data reduction proxy when fetching URLs // Chrome cannot authenticate with the data reduction proxy when fetching URLs
// from the settings menu. // from the settings menu.
config()->AddURLPatternToBypass("http://www.google.com/policies/privacy*"); configurator()->AddURLPatternToBypass(
"http://www.google.com/policies/privacy*");
} }
void DataReductionProxySettingsAndroid::SetProxyConfigs(bool enabled, void DataReductionProxySettingsAndroid::SetProxyConfigs(
bool restricted, bool enabled,
bool at_startup) { bool alternative_enabled,
bool restricted,
bool at_startup) {
// Sanity check: If there's no fallback proxy, we can't do a restricted mode. // Sanity check: If there's no fallback proxy, we can't do a restricted mode.
std::string fallback = GetDataReductionProxyFallback(); std::string fallback = params()->fallback_origin().spec();
if (fallback.empty() && enabled && restricted) if (fallback.empty() && enabled && restricted)
enabled = false; enabled = false;
LogProxyState(enabled, restricted, at_startup); LogProxyState(enabled, restricted, at_startup);
if (enabled) { if (enabled) {
config()->Enable(restricted, if (alternative_enabled) {
!fallback_allowed(), configurator()->Enable(restricted,
DataReductionProxySettings::GetDataReductionProxyOrigin(), !params()->fallback_allowed(),
GetDataReductionProxyFallback()); params()->alt_origin().spec(),
params()->alt_fallback_origin().spec(),
params()->ssl_origin().spec());
} else {
configurator()->Enable(restricted,
!params()->fallback_allowed(),
params()->origin().spec(),
params()->fallback_origin().spec(),
std::string());
}
} else { } else {
config()->Disable(); configurator()->Disable();
} }
} }
...@@ -256,6 +259,7 @@ DataReductionProxySettingsAndroid::GetDailyContentLengths( ...@@ -256,6 +259,7 @@ DataReductionProxySettingsAndroid::GetDailyContentLengths(
// Used by generated jni code. // Used by generated jni code.
static jlong Init(JNIEnv* env, jobject obj) { static jlong Init(JNIEnv* env, jobject obj) {
DataReductionProxySettingsAndroid* settings = DataReductionProxySettingsAndroid* settings =
new DataReductionProxySettingsAndroid(env, obj); DataReductionProxySettingsFactoryAndroid::GetForBrowserContext(
ProfileManager::GetActiveUserProfile());
return reinterpret_cast<intptr_t>(settings); return reinterpret_cast<intptr_t>(settings);
} }
...@@ -14,24 +14,31 @@ ...@@ -14,24 +14,31 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/prefs/pref_member.h" #include "base/prefs/pref_member.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h" #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h"
#include "components/keyed_service/core/keyed_service.h"
using base::android::ScopedJavaLocalRef; using base::android::ScopedJavaLocalRef;
class Profile;
namespace data_reduction_proxy {
class DataReductionProxyParams;
}
// Central point for configuring the data reduction proxy on Android. // Central point for configuring the data reduction proxy on Android.
// This object lives on the UI thread and all of its methods are expected to // This object lives on the UI thread and all of its methods are expected to
// be called from there. // be called from there.
class DataReductionProxySettingsAndroid class DataReductionProxySettingsAndroid
: public data_reduction_proxy::DataReductionProxySettings { : public data_reduction_proxy::DataReductionProxySettings,
public KeyedService {
public: public:
DataReductionProxySettingsAndroid(JNIEnv* env, jobject obj); // Factory constructor.
// Parameter-free constructor for C++ unit tests. DataReductionProxySettingsAndroid(
DataReductionProxySettingsAndroid(); data_reduction_proxy::DataReductionProxyParams* params);
virtual ~DataReductionProxySettingsAndroid(); virtual ~DataReductionProxySettingsAndroid();
void InitDataReductionProxySettings(JNIEnv* env, jobject obj); void InitDataReductionProxySettings(Profile* profile);
void BypassHostPattern(JNIEnv* env, jobject obj, jstring pattern); void BypassHostPattern(JNIEnv* env, jobject obj, jstring pattern);
// Add a URL pattern to bypass the proxy. Wildcards // Add a URL pattern to bypass the proxy. Wildcards
...@@ -82,8 +89,10 @@ class DataReductionProxySettingsAndroid ...@@ -82,8 +89,10 @@ class DataReductionProxySettingsAndroid
// Configures the proxy settings by generating a data URL containing a PAC // Configures the proxy settings by generating a data URL containing a PAC
// file. // file.
virtual void SetProxyConfigs( virtual void SetProxyConfigs(bool enabled,
bool enabled, bool restricted, bool at_startup) OVERRIDE; bool alt_enabled,
bool restricted,
bool at_startup) OVERRIDE;
private: private:
friend class DataReductionProxySettingsAndroidTest; friend class DataReductionProxySettingsAndroidTest;
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings_factory_android.h"
#include "base/memory/singleton.h"
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h"
#include "chrome/browser/profiles/profile.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
// static
DataReductionProxySettingsAndroid*
DataReductionProxySettingsFactoryAndroid::GetForBrowserContext(
content::BrowserContext* context) {
return static_cast<DataReductionProxySettingsAndroid*>(
GetInstance()->GetServiceForBrowserContext(context, true));
}
// static
bool DataReductionProxySettingsFactoryAndroid::
HasDataReductionProxySettingsAndroid(
content::BrowserContext* context) {
return GetInstance()->GetServiceForBrowserContext(context, false) != NULL;
}
// static
DataReductionProxySettingsFactoryAndroid*
DataReductionProxySettingsFactoryAndroid::GetInstance() {
return Singleton<DataReductionProxySettingsFactoryAndroid>::get();
}
DataReductionProxySettingsFactoryAndroid::
DataReductionProxySettingsFactoryAndroid()
: BrowserContextKeyedServiceFactory(
"ProfileSyncService",
BrowserContextDependencyManager::GetInstance()) {
}
DataReductionProxySettingsFactoryAndroid::
~DataReductionProxySettingsFactoryAndroid() {
}
KeyedService* DataReductionProxySettingsFactoryAndroid::BuildServiceInstanceFor(
content::BrowserContext* context) const {
Profile* profile = static_cast<Profile*>(context);
int flags = DataReductionProxyParams::kFallbackAllowed;
if (DataReductionProxyParams::IsIncludedInFieldTrial())
flags |= DataReductionProxyParams::kAllowed;
if (DataReductionProxyParams::IsIncludedInAlternativeFieldTrial())
flags |= DataReductionProxyParams::kAlternativeAllowed;
if (DataReductionProxyParams::IsIncludedInPromoFieldTrial())
flags |= DataReductionProxyParams::kPromoAllowed;
DataReductionProxySettingsAndroid* settings =
new DataReductionProxySettingsAndroid(
new DataReductionProxyParams(flags));
settings->InitDataReductionProxySettings(profile);
return settings;
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_FACTORY_ANDROID_H_
#define CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_FACTORY_ANDROID_H_
#include "base/compiler_specific.h"
#include "base/memory/singleton.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
namespace content {
class BrowserContext;
}
using data_reduction_proxy::DataReductionProxyParams;
class DataReductionProxySettingsAndroid;
// BrowserContextKeyedServiceFactory for generating/retrieving
// DataReductionProxyService instances.
class DataReductionProxySettingsFactoryAndroid
: public BrowserContextKeyedServiceFactory {
public:
static DataReductionProxySettingsAndroid* GetForBrowserContext(
content::BrowserContext* context);
static bool HasDataReductionProxySettingsAndroid(
content::BrowserContext* context);
static DataReductionProxySettingsFactoryAndroid* GetInstance();
private:
friend struct DefaultSingletonTraits<
DataReductionProxySettingsFactoryAndroid>;
DataReductionProxySettingsFactoryAndroid();
virtual ~DataReductionProxySettingsFactoryAndroid();
// BrowserContextKeyedServiceFactory:
virtual KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const OVERRIDE;
};
#endif // CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_SETTINGS_FACTORY_ANDROID_H_
...@@ -26,9 +26,19 @@ const char kDataReductionProxyOrigin[] = "https://foo.com:443/"; ...@@ -26,9 +26,19 @@ const char kDataReductionProxyOrigin[] = "https://foo.com:443/";
const char kDataReductionProxyDev[] = "http://foo-dev.com:80"; const char kDataReductionProxyDev[] = "http://foo-dev.com:80";
template <class C> template <class C>
void data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings() { void data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings(
bool allowed, bool fallback_allowed, bool alt_allowed, bool promo_allowed) {
int flags = 0;
if (allowed)
flags |= DataReductionProxyParams::kAllowed;
if (fallback_allowed)
flags |= DataReductionProxyParams::kFallbackAllowed;
if (alt_allowed)
flags |= DataReductionProxyParams::kAlternativeAllowed;
if (promo_allowed)
flags |= DataReductionProxyParams::kPromoAllowed;
MockDataReductionProxySettings<C>* settings = MockDataReductionProxySettings<C>* settings =
new MockDataReductionProxySettings<C>; new MockDataReductionProxySettings<C>(flags);
EXPECT_CALL(*settings, GetOriginalProfilePrefs()) EXPECT_CALL(*settings, GetOriginalProfilePrefs())
.Times(AnyNumber()) .Times(AnyNumber())
.WillRepeatedly(Return(&pref_service_)); .WillRepeatedly(Return(&pref_service_));
...@@ -68,7 +78,10 @@ void data_reduction_proxy::DataReductionProxySettingsTestBase::SetProbeResult( ...@@ -68,7 +78,10 @@ void data_reduction_proxy::DataReductionProxySettingsTestBase::SetProbeResult(
template void template void
data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings< data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings<
DataReductionProxySettingsAndroid>(); DataReductionProxySettingsAndroid>(bool allowed,
bool fallback_allowed,
bool alt_allowed,
bool promo_allowed);
template void template void
data_reduction_proxy::DataReductionProxySettingsTestBase::SetProbeResult< data_reduction_proxy::DataReductionProxySettingsTestBase::SetProbeResult<
...@@ -86,6 +99,7 @@ class DataReductionProxySettingsAndroidTest ...@@ -86,6 +99,7 @@ class DataReductionProxySettingsAndroidTest
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
env_ = base::android::AttachCurrentThread(); env_ = base::android::AttachCurrentThread();
DataReductionProxySettingsAndroid::Register(env_); DataReductionProxySettingsAndroid::Register(env_);
DataReductionProxySettingsTestBase::AddProxyToCommandLine();
DataReductionProxySettingsTestBase::SetUp(); DataReductionProxySettingsTestBase::SetUp();
} }
...@@ -97,26 +111,27 @@ class DataReductionProxySettingsAndroidTest ...@@ -97,26 +111,27 @@ class DataReductionProxySettingsAndroidTest
}; };
TEST_F(DataReductionProxySettingsAndroidTest, TestGetDataReductionProxyOrigin) { TEST_F(DataReductionProxySettingsAndroidTest, TestGetDataReductionProxyOrigin) {
AddProxyToCommandLine();
// SetUp() adds the origin to the command line, which should be returned here. // SetUp() adds the origin to the command line, which should be returned here.
ScopedJavaLocalRef<jstring> result = ScopedJavaLocalRef<jstring> result =
Settings()->GetDataReductionProxyOrigin(env_, NULL); Settings()->GetDataReductionProxyOrigin(env_, NULL);
ASSERT_TRUE(result.obj()); ASSERT_TRUE(result.obj());
const base::android::JavaRef<jstring>& str_ref = result; const base::android::JavaRef<jstring>& str_ref = result;
EXPECT_EQ(kDataReductionProxyOrigin, ConvertJavaStringToUTF8(str_ref)); EXPECT_EQ(GURL(kDataReductionProxyOrigin),
GURL(ConvertJavaStringToUTF8(str_ref)));
} }
TEST_F(DataReductionProxySettingsAndroidTest, TEST_F(DataReductionProxySettingsAndroidTest,
TestGetDataReductionProxyDevOrigin) { TestGetDataReductionProxyDevOrigin) {
AddProxyToCommandLine();
CommandLine::ForCurrentProcess()->AppendSwitchASCII( CommandLine::ForCurrentProcess()->AppendSwitchASCII(
data_reduction_proxy::switches::kDataReductionProxyDev, data_reduction_proxy::switches::kDataReductionProxyDev,
kDataReductionProxyDev); kDataReductionProxyDev);
ResetSettings(true, true, false, true);
ScopedJavaLocalRef<jstring> result = ScopedJavaLocalRef<jstring> result =
Settings()->GetDataReductionProxyOrigin(env_, NULL); Settings()->GetDataReductionProxyOrigin(env_, NULL);
ASSERT_TRUE(result.obj()); ASSERT_TRUE(result.obj());
const base::android::JavaRef<jstring>& str_ref = result; const base::android::JavaRef<jstring>& str_ref = result;
EXPECT_EQ(kDataReductionProxyDev, ConvertJavaStringToUTF8(str_ref)); EXPECT_EQ(GURL(kDataReductionProxyDev),
GURL(ConvertJavaStringToUTF8(str_ref)));
} }
TEST_F(DataReductionProxySettingsAndroidTest, TestGetDailyContentLengths) { TEST_F(DataReductionProxySettingsAndroidTest, TestGetDailyContentLengths) {
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/stl_util.h" #include "base/stl_util.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h" #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "net/base/load_flags.h" #include "net/base/load_flags.h"
...@@ -21,6 +22,8 @@ ...@@ -21,6 +22,8 @@
#include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
// TODO(marq): Remove this class because it is not being used.
// Ensure data reduction features are available. // Ensure data reduction features are available.
#if !defined(OS_ANDROID) && !defined(OS_IOS) #if !defined(OS_ANDROID) && !defined(OS_IOS)
#error proxy_advisor should only be included in Android or iOS builds. #error proxy_advisor should only be included in Android or iOS builds.
...@@ -119,8 +122,12 @@ void ProxyAdvisor::Advise( ...@@ -119,8 +122,12 @@ void ProxyAdvisor::Advise(
std::string motivation_name(MotivationName(motivation, is_preconnect)); std::string motivation_name(MotivationName(motivation, is_preconnect));
std::string header_value = motivation_name + " " + url.spec(); std::string header_value = motivation_name + " " + url.spec();
net::URLRequestContext* context = context_getter_->GetURLRequestContext(); net::URLRequestContext* context = context_getter_->GetURLRequestContext();
data_reduction_proxy::DataReductionProxyParams params(
data_reduction_proxy::DataReductionProxyParams::kAllowed |
data_reduction_proxy::DataReductionProxyParams::kFallbackAllowed |
data_reduction_proxy::DataReductionProxyParams::kPromoAllowed);
std::string endpoint = std::string endpoint =
DataReductionProxySettings::GetDataReductionProxyOrigin() + "preconnect"; params.origin().spec() + "preconnect";
scoped_ptr<net::URLRequest> request = context->CreateRequest( scoped_ptr<net::URLRequest> request = context->CreateRequest(
GURL(endpoint), net::DEFAULT_PRIORITY, this, NULL); GURL(endpoint), net::DEFAULT_PRIORITY, this, NULL);
request->set_method("HEAD"); request->set_method("HEAD");
......
...@@ -484,8 +484,9 @@ void ProfileImplIOData::InitializeInternal( ...@@ -484,8 +484,9 @@ void ProfileImplIOData::InitializeInternal(
#if defined(OS_ANDROID) || defined(OS_IOS) #if defined(OS_ANDROID) || defined(OS_IOS)
#if defined(SPDY_PROXY_AUTH_VALUE) #if defined(SPDY_PROXY_AUTH_VALUE)
data_reduction_proxy::DataReductionProxySettings:: data_reduction_proxy::DataReductionProxySettings::
InitDataReductionProxySession(main_cache->GetSession(), InitDataReductionProxySession(
SPDY_PROXY_AUTH_VALUE); main_cache->GetSession(),
io_thread_globals->data_reduction_proxy_params.get());
#endif #endif
#endif #endif
......
...@@ -1330,6 +1330,8 @@ ...@@ -1330,6 +1330,8 @@
'browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.h', 'browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.h',
'browser/net/spdyproxy/data_reduction_proxy_settings_android.cc', 'browser/net/spdyproxy/data_reduction_proxy_settings_android.cc',
'browser/net/spdyproxy/data_reduction_proxy_settings_android.h', 'browser/net/spdyproxy/data_reduction_proxy_settings_android.h',
'browser/net/spdyproxy/data_reduction_proxy_settings_factory_android.cc',
'browser/net/spdyproxy/data_reduction_proxy_settings_factory_android.h',
'browser/net/spdyproxy/data_reduction_proxy_settings_ios.cc', 'browser/net/spdyproxy/data_reduction_proxy_settings_ios.cc',
'browser/net/spdyproxy/data_reduction_proxy_settings_ios.h', 'browser/net/spdyproxy/data_reduction_proxy_settings_ios.h',
'browser/net/spdyproxy/proxy_advisor.cc', 'browser/net/spdyproxy/proxy_advisor.cc',
......
...@@ -74,6 +74,7 @@ ...@@ -74,6 +74,7 @@
'data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler_unittest.cc', 'data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler_unittest.cc',
'data_reduction_proxy/browser/data_reduction_proxy_config_service_unittest.cc', 'data_reduction_proxy/browser/data_reduction_proxy_config_service_unittest.cc',
'data_reduction_proxy/browser/data_reduction_proxy_metrics_unittest.cc', 'data_reduction_proxy/browser/data_reduction_proxy_metrics_unittest.cc',
'data_reduction_proxy/browser/data_reduction_proxy_params_unittest.cc',
'data_reduction_proxy/browser/data_reduction_proxy_settings_unittest.cc', 'data_reduction_proxy/browser/data_reduction_proxy_settings_unittest.cc',
'data_reduction_proxy/browser/http_auth_handler_data_reduction_proxy_unittest.cc', 'data_reduction_proxy/browser/http_auth_handler_data_reduction_proxy_unittest.cc',
'dom_distiller/core/article_entry_unittest.cc', 'dom_distiller/core/article_entry_unittest.cc',
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
'data_reduction_proxy/browser/data_reduction_proxy_configurator.h', 'data_reduction_proxy/browser/data_reduction_proxy_configurator.h',
'data_reduction_proxy/browser/data_reduction_proxy_metrics.cc', 'data_reduction_proxy/browser/data_reduction_proxy_metrics.cc',
'data_reduction_proxy/browser/data_reduction_proxy_metrics.h', 'data_reduction_proxy/browser/data_reduction_proxy_metrics.h',
'data_reduction_proxy/browser/data_reduction_proxy_params.cc',
'data_reduction_proxy/browser/data_reduction_proxy_params.h',
'data_reduction_proxy/browser/data_reduction_proxy_prefs.cc', 'data_reduction_proxy/browser/data_reduction_proxy_prefs.cc',
'data_reduction_proxy/browser/data_reduction_proxy_prefs.h', 'data_reduction_proxy/browser/data_reduction_proxy_prefs.h',
'data_reduction_proxy/browser/data_reduction_proxy_settings.cc', 'data_reduction_proxy/browser/data_reduction_proxy_settings.cc',
......
...@@ -35,6 +35,7 @@ DataReductionProxyAuthRequestHandler::auth_token_invalidation_timestamp_ = 0; ...@@ -35,6 +35,7 @@ DataReductionProxyAuthRequestHandler::auth_token_invalidation_timestamp_ = 0;
DataReductionProxyAuthRequestHandler::DataReductionProxyAuthRequestHandler( DataReductionProxyAuthRequestHandler::DataReductionProxyAuthRequestHandler(
DataReductionProxySettings* settings) : settings_(settings) { DataReductionProxySettings* settings) : settings_(settings) {
DCHECK(settings);
} }
DataReductionProxyAuthRequestHandler::~DataReductionProxyAuthRequestHandler() { DataReductionProxyAuthRequestHandler::~DataReductionProxyAuthRequestHandler() {
...@@ -104,7 +105,7 @@ DataReductionProxyAuthRequestHandler::TryHandleAuthentication( ...@@ -104,7 +105,7 @@ DataReductionProxyAuthRequestHandler::TryHandleAuthentication(
bool DataReductionProxyAuthRequestHandler::IsAcceptableAuthChallenge( bool DataReductionProxyAuthRequestHandler::IsAcceptableAuthChallenge(
net::AuthChallengeInfo* auth_info) { net::AuthChallengeInfo* auth_info) {
return DataReductionProxySettings::IsAcceptableAuthChallenge(auth_info); return settings_->IsAcceptableAuthChallenge(auth_info);
} }
base::string16 DataReductionProxyAuthRequestHandler::GetTokenForAuthChallenge( base::string16 DataReductionProxyAuthRequestHandler::GetTokenForAuthChallenge(
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h"
namespace net { namespace net {
class AuthChallengeInfo; class AuthChallengeInfo;
......
...@@ -5,9 +5,11 @@ ...@@ -5,9 +5,11 @@
#include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h" #include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.h"
#include "net/base/auth.h" #include "net/base/auth.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -30,8 +32,9 @@ class TestDataReductionProxyAuthRequestHandler ...@@ -30,8 +32,9 @@ class TestDataReductionProxyAuthRequestHandler
: public DataReductionProxyAuthRequestHandler { : public DataReductionProxyAuthRequestHandler {
public: public:
TestDataReductionProxyAuthRequestHandler(int time_step_ms, TestDataReductionProxyAuthRequestHandler(int time_step_ms,
int64 initial_time_ms) int64 initial_time_ms,
: DataReductionProxyAuthRequestHandler(NULL), DataReductionProxySettings* settings)
: DataReductionProxyAuthRequestHandler(settings),
time_step_ms_(time_step_ms), time_step_ms_(time_step_ms),
now_(base::TimeTicks() + now_(base::TimeTicks() +
base::TimeDelta::FromMilliseconds(initial_time_ms)) {} base::TimeDelta::FromMilliseconds(initial_time_ms)) {}
...@@ -63,6 +66,16 @@ class TestDataReductionProxyAuthRequestHandler ...@@ -63,6 +66,16 @@ class TestDataReductionProxyAuthRequestHandler
class DataReductionProxyAuthRequestHandlerTest : public testing::Test { class DataReductionProxyAuthRequestHandlerTest : public testing::Test {
public: public:
virtual void SetUp() OVERRIDE {
DataReductionProxySettingsTestBase::AddTestProxyToCommandLine();
settings_.reset(
new MockDataReductionProxySettings<DataReductionProxySettings>(
DataReductionProxyParams::kAllowed |
DataReductionProxyParams::kFallbackAllowed |
DataReductionProxyParams::kPromoAllowed));
}
// Checks that |PROCEED| was returned with expected user and password. // Checks that |PROCEED| was returned with expected user and password.
void ExpectProceed( void ExpectProceed(
DataReductionProxyAuthRequestHandler::TryHandleResult result, DataReductionProxyAuthRequestHandler::TryHandleResult result,
...@@ -97,6 +110,8 @@ class DataReductionProxyAuthRequestHandlerTest : public testing::Test { ...@@ -97,6 +110,8 @@ class DataReductionProxyAuthRequestHandlerTest : public testing::Test {
EXPECT_EQ(base::string16(), user); EXPECT_EQ(base::string16(), user);
EXPECT_EQ(base::string16(), password); EXPECT_EQ(base::string16(), password);
} }
scoped_ptr<DataReductionProxySettings> settings_;
}; };
TEST_F(DataReductionProxyAuthRequestHandlerTest, TEST_F(DataReductionProxyAuthRequestHandlerTest,
...@@ -107,7 +122,8 @@ TEST_F(DataReductionProxyAuthRequestHandlerTest, ...@@ -107,7 +122,8 @@ TEST_F(DataReductionProxyAuthRequestHandlerTest,
scoped_refptr<net::AuthChallengeInfo> auth_info(new net::AuthChallengeInfo); scoped_refptr<net::AuthChallengeInfo> auth_info(new net::AuthChallengeInfo);
auth_info->realm = kTestRealm; auth_info->realm = kTestRealm;
auth_info->challenger = net::HostPortPair::FromString(kTestChallenger); auth_info->challenger = net::HostPortPair::FromString(kTestChallenger);
TestDataReductionProxyAuthRequestHandler handler(499, 3600001); TestDataReductionProxyAuthRequestHandler handler(
499, 3600001, settings_.get());
base::string16 user, password; base::string16 user, password;
DataReductionProxyAuthRequestHandler::TryHandleResult result = DataReductionProxyAuthRequestHandler::TryHandleResult result =
handler.TryHandleAuthentication(auth_info.get(), &user, &password); handler.TryHandleAuthentication(auth_info.get(), &user, &password);
...@@ -138,7 +154,8 @@ TEST_F(DataReductionProxyAuthRequestHandlerTest, Ignore) { ...@@ -138,7 +154,8 @@ TEST_F(DataReductionProxyAuthRequestHandlerTest, Ignore) {
scoped_refptr<net::AuthChallengeInfo> auth_info(new net::AuthChallengeInfo); scoped_refptr<net::AuthChallengeInfo> auth_info(new net::AuthChallengeInfo);
auth_info->realm = kInvalidTestRealm; auth_info->realm = kInvalidTestRealm;
auth_info->challenger = net::HostPortPair::FromString(kTestChallenger); auth_info->challenger = net::HostPortPair::FromString(kTestChallenger);
TestDataReductionProxyAuthRequestHandler handler(100, 3600001); TestDataReductionProxyAuthRequestHandler handler(
100, 3600001, settings_.get());
base::string16 user, password; base::string16 user, password;
DataReductionProxyAuthRequestHandler::TryHandleResult result = DataReductionProxyAuthRequestHandler::TryHandleResult result =
handler.TryHandleAuthentication(auth_info.get(), &user, &password); handler.TryHandleAuthentication(auth_info.get(), &user, &password);
......
...@@ -130,7 +130,8 @@ void DataReductionProxyConfigTracker::Enable( ...@@ -130,7 +130,8 @@ void DataReductionProxyConfigTracker::Enable(
bool primary_restricted, bool primary_restricted,
bool fallback_restricted, bool fallback_restricted,
const std::string& primary_origin, const std::string& primary_origin,
const std::string& fallback_origin) { const std::string& fallback_origin,
const std::string& ssl_origin) {
std::vector<std::string> proxies; std::vector<std::string> proxies;
if (!primary_restricted) { if (!primary_restricted) {
...@@ -151,9 +152,14 @@ void DataReductionProxyConfigTracker::Enable( ...@@ -151,9 +152,14 @@ void DataReductionProxyConfigTracker::Enable(
return; return;
} }
std::string trimmed_ssl;
base::TrimString(ssl_origin, "/", &trimmed_ssl);
std::string server = "http=" + JoinString(proxies, ",") + ",direct://;"
+ (ssl_origin.empty() ? "" : ("https=" + ssl_origin + ",direct://;"));
net::ProxyConfig config; net::ProxyConfig config;
config.proxy_rules().ParseFromString( config.proxy_rules().ParseFromString(server);
"http=" + JoinString(proxies, ",") + ",direct://;");
config.proxy_rules().bypass_rules.ParseFromString( config.proxy_rules().bypass_rules.ParseFromString(
JoinString(bypass_rules_, ", ")); JoinString(bypass_rules_, ", "));
UpdateProxyConfigOnIOThread(true, config); UpdateProxyConfigOnIOThread(true, config);
......
...@@ -98,7 +98,8 @@ class DataReductionProxyConfigTracker : public DataReductionProxyConfigurator { ...@@ -98,7 +98,8 @@ class DataReductionProxyConfigTracker : public DataReductionProxyConfigurator {
virtual void Enable(bool primary_restricted, virtual void Enable(bool primary_restricted,
bool fallback_restricted, bool fallback_restricted,
const std::string& primary_origin, const std::string& primary_origin,
const std::string& fallback_origin) OVERRIDE; const std::string& fallback_origin,
const std::string& ssl_origin) OVERRIDE;
virtual void Disable() OVERRIDE; virtual void Disable() OVERRIDE;
virtual void AddHostPatternToBypass(const std::string& pattern) OVERRIDE; virtual void AddHostPatternToBypass(const std::string& pattern) OVERRIDE;
virtual void AddURLPatternToBypass(const std::string& pattern) OVERRIDE; virtual void AddURLPatternToBypass(const std::string& pattern) OVERRIDE;
......
...@@ -207,7 +207,8 @@ TEST_F(DataReductionProxyConfigServiceTest, TrackerEnable) { ...@@ -207,7 +207,8 @@ TEST_F(DataReductionProxyConfigServiceTest, TrackerEnable) {
tracker.Enable(false, tracker.Enable(false,
false, false,
"https://foo.com:443", "https://foo.com:443",
"http://bar.com:80"); "http://bar.com:80",
"");
task_runner_->RunUntilIdle(); task_runner_->RunUntilIdle();
Mock::VerifyAndClearExpectations(&observer); Mock::VerifyAndClearExpectations(&observer);
...@@ -231,7 +232,8 @@ TEST_F(DataReductionProxyConfigServiceTest, TrackerEnableRestricted) { ...@@ -231,7 +232,8 @@ TEST_F(DataReductionProxyConfigServiceTest, TrackerEnableRestricted) {
tracker.Enable(true, tracker.Enable(true,
false, false,
"https://foo.com:443", "https://foo.com:443",
"http://bar.com:80"); "http://bar.com:80",
"");
task_runner_->RunUntilIdle(); task_runner_->RunUntilIdle();
Mock::VerifyAndClearExpectations(&observer); Mock::VerifyAndClearExpectations(&observer);
......
...@@ -23,10 +23,12 @@ class DataReductionProxyConfigurator { ...@@ -23,10 +23,12 @@ class DataReductionProxyConfigurator {
// |primary_origin| may not be used. If |fallback_restricted|, the // |primary_origin| may not be used. If |fallback_restricted|, the
// |fallback_origin| may not be used. If both are restricted, then the // |fallback_origin| may not be used. If both are restricted, then the
// proxy configuration will be the same as when |Disable()| is called. // proxy configuration will be the same as when |Disable()| is called.
// If |ssl_origin| is non-empty, it will be used used for HTTPS traffic.
virtual void Enable(bool primary_restricted, virtual void Enable(bool primary_restricted,
bool fallback_restricted, bool fallback_restricted,
const std::string& primary_origin, const std::string& primary_origin,
const std::string& fallback_origin) = 0; const std::string& fallback_origin,
const std::string& ssl_origin) = 0;
// Disable the data reduction proxy. // Disable the data reduction proxy.
virtual void Disable() = 0; virtual void Disable() = 0;
......
...@@ -301,8 +301,14 @@ class DailyDataSavingUpdate { ...@@ -301,8 +301,14 @@ class DailyDataSavingUpdate {
// the request is bypassed by more than one proxy, delay_seconds returns // the request is bypassed by more than one proxy, delay_seconds returns
// shortest delay. // shortest delay.
bool IsBypassRequest(const net::URLRequest* request, int64* delay_seconds) { bool IsBypassRequest(const net::URLRequest* request, int64* delay_seconds) {
DataReductionProxySettings::DataReductionProxyList proxies = // TODO(bengr): Add support for other data reduction proxy configurations.
DataReductionProxySettings::GetDataReductionProxies(); #if defined(SPDY_PROXY_AUTH_ORIGIN)
DataReductionProxyParams params(
DataReductionProxyParams::kAllowed |
DataReductionProxyParams::kFallbackAllowed |
DataReductionProxyParams::kPromoAllowed);
DataReductionProxyParams::DataReductionProxyList proxies =
params.GetAllowedProxies();
if (proxies.size() == 0) if (proxies.size() == 0)
return false; return false;
...@@ -335,6 +341,9 @@ bool IsBypassRequest(const net::URLRequest* request, int64* delay_seconds) { ...@@ -335,6 +341,9 @@ bool IsBypassRequest(const net::URLRequest* request, int64* delay_seconds) {
if (delay_seconds != NULL) if (delay_seconds != NULL)
*delay_seconds = shortest_delay; *delay_seconds = shortest_delay;
return true; return true;
#else
return false;
#endif
} }
} // namespace } // namespace
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// 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/browser/data_reduction_proxy_params.h"
#include "base/command_line.h"
#include "base/metrics/field_trial.h"
#include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h"
using base::FieldTrialList;
namespace {
const char kEnabled[] = "Enabled";
}
namespace data_reduction_proxy {
// static
bool DataReductionProxyParams::IsIncludedInFieldTrial() {
return base::FieldTrialList::FindFullName(
"DataCompressionProxyRollout") == kEnabled;
}
// static
bool DataReductionProxyParams::IsIncludedInAlternativeFieldTrial() {
return base::FieldTrialList::FindFullName(
"DataCompressionProxyAlternativeConfiguration") == kEnabled;
}
// static
bool DataReductionProxyParams::IsIncludedInPromoFieldTrial() {
return FieldTrialList::FindFullName(
"DataCompressionProxyPromoVisibility") == kEnabled;
}
// static
bool DataReductionProxyParams::IsIncludedInPreconnectHintingFieldTrial() {
return IsIncludedInFieldTrial() &&
FieldTrialList::FindFullName(
"DataCompressionProxyPreconnectHints") == kEnabled;
}
// static
bool DataReductionProxyParams::IsKeySetOnCommandLine() {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
return command_line.HasSwitch(
data_reduction_proxy::switches::kEnableDataReductionProxy);
}
DataReductionProxyParams::DataReductionProxyParams(int flags)
: allowed_((flags & kAllowed) == kAllowed),
fallback_allowed_((flags & kFallbackAllowed) == kFallbackAllowed),
alt_allowed_((flags & kAlternativeAllowed) == kAlternativeAllowed),
promo_allowed_((flags & kPromoAllowed) == kPromoAllowed) {
DCHECK(Init(allowed_, fallback_allowed_, alt_allowed_));
}
DataReductionProxyParams::~DataReductionProxyParams() {
}
DataReductionProxyParams::DataReductionProxyList
DataReductionProxyParams::GetAllowedProxies() const {
DataReductionProxyList list;
if (allowed_)
list.push_back(origin_);
if (allowed_ && fallback_allowed_)
list.push_back(fallback_origin_);
if (alt_allowed_) {
list.push_back(alt_origin_);
list.push_back(ssl_origin_);
}
if (alt_allowed_ && fallback_allowed_)
list.push_back(alt_fallback_origin_);
return list;
}
DataReductionProxyParams::DataReductionProxyParams(int flags,
bool should_call_init)
: allowed_((flags & kAllowed) == kAllowed),
fallback_allowed_((flags & kFallbackAllowed) == kFallbackAllowed),
alt_allowed_((flags & kAlternativeAllowed) == kAlternativeAllowed),
promo_allowed_((flags & kPromoAllowed) == kPromoAllowed) {
if (should_call_init)
DCHECK(Init(allowed_, fallback_allowed_, alt_allowed_));
}
bool DataReductionProxyParams::Init(
bool allowed, bool fallback_allowed, bool alt_allowed) {
InitWithoutChecks();
// Verify that all necessary params are set.
if (allowed) {
if (!origin_.is_valid()) {
DVLOG(1) << "Invalid data reduction proxy origin: " << origin_.spec();
return false;
}
}
if (allowed && fallback_allowed) {
if (!fallback_origin_.is_valid()) {
DVLOG(1) << "Invalid data reduction proxy fallback origin: "
<< fallback_origin_.spec();
return false;
}
}
if (alt_allowed) {
if (!allowed) {
DVLOG(1) << "Alternative data reduction proxy configuration cannot "
<< "be allowed if the regular configuration is not allowed";
return false;
}
if (!alt_origin_.is_valid()) {
DVLOG(1) << "Invalid alternative origin:" << alt_origin_.spec();
return false;
}
if (!ssl_origin_.is_valid()) {
DVLOG(1) << "Invalid ssl origin: " << ssl_origin_.spec();
return false;
}
}
if (alt_allowed && fallback_allowed) {
if (!alt_fallback_origin_.is_valid()) {
DVLOG(1) << "Invalid alternative fallback origin:"
<< alt_fallback_origin_.spec();
return false;
}
}
if (allowed && !probe_url_.is_valid()) {
DVLOG(1) << "Invalid probe url: <null>";
return false;
}
if (allowed || alt_allowed) {
if (key_.empty()) {
DVLOG(1) << "Invalid key: <empty>";
return false;
}
}
if (fallback_allowed_ && !allowed_) {
DVLOG(1) << "The data reduction proxy fallback cannot be allowed if "
<< "the data reduction proxy is not allowed";
return false;
}
if (promo_allowed_ && !allowed_) {
DVLOG(1) << "The data reduction proxy promo cannot be allowed if the "
<< "data reduction proxy is not allowed";
return false;
}
return true;
}
void DataReductionProxyParams::InitWithoutChecks() {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
std::string origin =
command_line.GetSwitchValueASCII(switches::kDataReductionProxyDev);
if (origin.empty())
origin = command_line.GetSwitchValueASCII(switches::kDataReductionProxy);
std::string fallback_origin =
command_line.GetSwitchValueASCII(switches::kDataReductionProxyFallback);
std::string ssl_origin =
command_line.GetSwitchValueASCII(switches::kDataReductionSSLProxy);
std::string alt_origin =
command_line.GetSwitchValueASCII(switches::kDataReductionProxyAlt);
std::string alt_fallback_origin = command_line.GetSwitchValueASCII(
switches::kDataReductionProxyAltFallback);
key_ = command_line.GetSwitchValueASCII(switches::kDataReductionProxyKey);
bool configured_on_command_line =
!(origin.empty() && fallback_origin.empty() && ssl_origin.empty() &&
alt_origin.empty() && alt_fallback_origin.empty());
// Configuring the proxy on the command line overrides the values of
// |allowed_| and |alt_allowed_|.
if (configured_on_command_line)
allowed_ = true;
if (!(ssl_origin.empty() &&
alt_origin.empty() &&
alt_fallback_origin.empty()))
alt_allowed_ = true;
// Only use default key if non of the proxies are configured on the command
// line.
if (key_.empty() && !configured_on_command_line)
key_ = GetDefaultKey();
std::string probe_url = command_line.GetSwitchValueASCII(
switches::kDataReductionProxyProbeURL);
// Set from preprocessor constants those params that are not specified on the
// command line.
if (origin.empty())
origin = GetDefaultDevOrigin();
if (origin.empty())
origin = GetDefaultOrigin();
if (fallback_origin.empty())
fallback_origin = GetDefaultFallbackOrigin();
if (ssl_origin.empty())
ssl_origin = GetDefaultSSLOrigin();
if (alt_origin.empty())
alt_origin = GetDefaultAltOrigin();
if (alt_fallback_origin.empty())
alt_fallback_origin = GetDefaultAltFallbackOrigin();
if (probe_url.empty())
probe_url = GetDefaultProbeURL();
origin_ = GURL(origin);
fallback_origin_ = GURL(fallback_origin);
ssl_origin_ = GURL(ssl_origin);
alt_origin_ = GURL(alt_origin);
alt_fallback_origin_ = GURL(alt_fallback_origin);
probe_url_ = GURL(probe_url);
}
std::string DataReductionProxyParams::GetDefaultKey() const {
#if defined(SPDY_PROXY_AUTH_VALUE)
return SPDY_PROXY_AUTH_VALUE;
#endif
return std::string();
}
std::string DataReductionProxyParams::GetDefaultDevOrigin() const {
#if defined(DATA_REDUCTION_DEV_HOST)
if (FieldTrialList::FindFullName("DataCompressionProxyDevRollout") ==
kEnabled) {
return DATA_REDUCTION_DEV_HOST;
}
#endif
return std::string();
}
std::string DataReductionProxyParams::GetDefaultOrigin() const {
#if defined(SPDY_PROXY_AUTH_ORIGIN)
return SPDY_PROXY_AUTH_ORIGIN;
#endif
return std::string();
}
std::string DataReductionProxyParams::GetDefaultFallbackOrigin() const {
#if defined(DATA_REDUCTION_FALLBACK_HOST)
return DATA_REDUCTION_FALLBACK_HOST;
#endif
return std::string();
}
std::string DataReductionProxyParams::GetDefaultSSLOrigin() const {
#if defined(DATA_REDUCTION_PROXY_SSL_ORIGIN)
return DATA_REDUCTION_PROXY_SSL_ORIGIN;
#endif
return std::string();
}
std::string DataReductionProxyParams::GetDefaultAltOrigin() const {
#if defined(DATA_REDUCTION_PROXY_ALT_ORIGIN)
return DATA_REDUCTION_PROXY_ALT_ORIGIN;
#endif
return std::string();
}
std::string DataReductionProxyParams::GetDefaultAltFallbackOrigin() const {
#if defined(DATA_REDUCTION_PROXY_ALT_FALLBACK_ORIGIN)
return DATA_REDUCTION_PROXY_ALT_FALLBACK_ORIGIN;
#endif
return std::string();
}
std::string DataReductionProxyParams::GetDefaultProbeURL() const {
#if defined(DATA_REDUCTION_PROXY_PROBE_URL)
return DATA_REDUCTION_PROXY_PROBE_URL;
#endif
return std::string();
}
} // namespace data_reduction_proxy
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_PARAMS_H_
#define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_PARAMS_H_
#include <vector>
#include "base/macros.h"
#include "url/gurl.h"
namespace data_reduction_proxy {
// Provides initialization parameters. Proxy origins, the probe url, and the
// authentication key are taken from flags if available and from preprocessor
// constants otherwise. Only the key may be changed after construction.
class DataReductionProxyParams {
public:
static const unsigned int kAllowed = (1 << 0);
static const unsigned int kFallbackAllowed = (1 << 1);
static const unsigned int kAlternativeAllowed = (1 << 2);
static const unsigned int kPromoAllowed = (1 << 3);
typedef std::vector<GURL> DataReductionProxyList;
// Returns true if this client is part of the data reduction proxy field
// trial.
static bool IsIncludedInFieldTrial();
// Returns true if this client is part of field trial to use an alternative
// configuration for the data reduction proxy.
static bool IsIncludedInAlternativeFieldTrial();
// Returns true if this client is part of the field trial that should display
// a promotion for the data reduction proxy.
static bool IsIncludedInPromoFieldTrial();
// Returns true if this client is part of a field trial that uses preconnect
// hinting.
static bool IsIncludedInPreconnectHintingFieldTrial();
// Returns true if the authentication key was set on the command line.
static bool IsKeySetOnCommandLine();
// Constructs configuration parameters. If |kAllowed|, then the standard
// data reduction proxy configuration is allowed to be used. If
// |kfallbackAllowed| a fallback proxy can be used if the primary proxy is
// bypassed or disabled. If |kAlternativeAllowed| then an alternative proxy
// configuration is allowed to be used. This alternative configuration would
// replace the primary and fallback proxy configurations if enabled. Finally
// if |kPromoAllowed|, the client may show a promotion for the data
// reduction proxy.
//
// A standard configuration has a primary proxy, and a fallback proxy for
// HTTP traffic. The alternative configuration has a different primary and
// fallback proxy for HTTP traffic, and an SSL proxy.
DataReductionProxyParams(int flags);
virtual ~DataReductionProxyParams();
// Returns the data reduction proxy primary origin.
const GURL& origin() const {
return origin_;
}
// Returns the data reduction proxy fallback origin.
const GURL& fallback_origin() const {
return fallback_origin_;
}
// Returns the data reduction proxy ssl origin that is used with the
// alternative proxy configuration.
const GURL& ssl_origin() const {
return ssl_origin_;
}
// Returns the alternative data reduction proxy primary origin.
const GURL& alt_origin() const {
return alt_origin_;
}
// Returns the alternative data reduction proxy fallback origin.
const GURL& alt_fallback_origin() const {
return alt_fallback_origin_;
}
// Returns the URL to probe to decide if the primary origin should be used.
const GURL& probe_url() const {
return probe_url_;
}
// Set the proxy authentication key.
void set_key(const std::string& key) {
key_ = key;
}
// Returns the proxy authentication key.
const std::string& key() const {
return key_;
}
// Returns true if the data reduction proxy configuration may be used.
bool allowed() const {
return allowed_;
}
// Returns true if the fallback proxy may be used.
bool fallback_allowed() const {
return fallback_allowed_;
}
// Returns true if the alternative data reduction proxy configuration may be
// used.
bool alternative_allowed() const {
return alt_allowed_;
}
// Returns true if the data reduction proxy promo may be shown.
// This is idependent of whether the data reduction proxy is allowed.
// TODO(bengr): maybe tie to whether proxy is allowed.
bool promo_allowed() const {
return promo_allowed_;
}
// Given |allowed_|, |fallback_allowed_|, and |alt_allowed_|, returns the
// list of data reduction proxies that may be used.
DataReductionProxyList GetAllowedProxies() const;
protected:
// Test constructor that optionally won't call Init();
DataReductionProxyParams(int flags,
bool should_call_init);
// Initialize the values of the proxies, probe URL, and key from command
// line flags and preprocessor constants, and check that there are
// corresponding definitions for the allowed configurations.
bool Init(bool allowed, bool fallback_allowed, bool alt_allowed);
// Initialize the values of the proxies, probe URL, and key from command
// line flags and preprocessor constants.
void InitWithoutChecks();
// Returns the corresponding string from preprocessor constants if defined,
// and an empty string otherwise.
virtual std::string GetDefaultKey() const;
virtual std::string GetDefaultDevOrigin() const;
virtual std::string GetDefaultOrigin() const;
virtual std::string GetDefaultFallbackOrigin() const;
virtual std::string GetDefaultSSLOrigin() const;
virtual std::string GetDefaultAltOrigin() const;
virtual std::string GetDefaultAltFallbackOrigin() const;
virtual std::string GetDefaultProbeURL() const;
private:
GURL origin_;
GURL fallback_origin_;
GURL ssl_origin_;
GURL alt_origin_;
GURL alt_fallback_origin_;
GURL probe_url_;
std::string key_;
bool allowed_;
const bool fallback_allowed_;
bool alt_allowed_;
const bool promo_allowed_;
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyParams);
};
} // namespace data_reduction_proxy
#endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_PARAMS_H_
...@@ -15,6 +15,10 @@ void RegisterSyncableProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { ...@@ -15,6 +15,10 @@ void RegisterSyncableProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
data_reduction_proxy::prefs::kDataReductionProxyEnabled, data_reduction_proxy::prefs::kDataReductionProxyEnabled,
false, false,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
registry->RegisterBooleanPref(
data_reduction_proxy::prefs::kDataReductionProxyAltEnabled,
false,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
registry->RegisterBooleanPref( registry->RegisterBooleanPref(
data_reduction_proxy::prefs::kDataReductionProxyWasEnabledBefore, data_reduction_proxy::prefs::kDataReductionProxyWasEnabledBefore,
false, false,
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/prefs/pref_member.h" #include "base/prefs/pref_member.h"
#include "base/threading/thread_checker.h" #include "base/threading/thread_checker.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_configurator.h" #include "components/data_reduction_proxy/browser/data_reduction_proxy_configurator.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
#include "net/base/network_change_notifier.h" #include "net/base/network_change_notifier.h"
#include "net/url_request/url_fetcher_delegate.h" #include "net/url_request/url_fetcher_delegate.h"
...@@ -86,34 +87,14 @@ class DataReductionProxySettings ...@@ -86,34 +87,14 @@ class DataReductionProxySettings
public net::NetworkChangeNotifier::IPAddressObserver { public net::NetworkChangeNotifier::IPAddressObserver {
public: public:
typedef std::vector<long long> ContentLengthList; typedef std::vector<long long> ContentLengthList;
// TODO(marq): Consider instead using a std::pair instead of a vector.
typedef std::vector<GURL> DataReductionProxyList;
// Returns true of the data reduction proxy origin is set on the command line.
static bool IsProxyOriginSetOnCommandLine();
// Returns true if the data reduction proxy key is set on the command line.
static bool IsProxyKeySetOnCommandLine(); static bool IsProxyKeySetOnCommandLine();
// Returns true if this application instance is part of the data reduction DataReductionProxySettings(DataReductionProxyParams* params);
// proxy field trial, or if it a proxy origin is set in flags. This is a
// convenience method for platforms like Chrome on Android and iOS, to
// determine if the data reduction proxy is allowed.
static bool IsIncludedInFieldTrialOrFlags();
static void SetAllowed(bool allowed);
static void SetPromoAllowed(bool promo_allowed);
DataReductionProxySettings();
virtual ~DataReductionProxySettings(); virtual ~DataReductionProxySettings();
// Set and get the key to be used for data reduction proxy authentication. DataReductionProxyParams* params() const {
void set_key(const std::string& key) { return params_.get();
key_ = key;
}
const std::string& key() const {
return key_;
} }
// Initializes the data reduction proxy with profile and local state prefs, // Initializes the data reduction proxy with profile and local state prefs,
...@@ -134,45 +115,22 @@ class DataReductionProxySettings ...@@ -134,45 +115,22 @@ class DataReductionProxySettings
PrefService* prefs, PrefService* prefs,
PrefService* local_state_prefs, PrefService* local_state_prefs,
net::URLRequestContextGetter* url_request_context_getter, net::URLRequestContextGetter* url_request_context_getter,
scoped_ptr<DataReductionProxyConfigurator> config); scoped_ptr<DataReductionProxyConfigurator> configurator);
// Sets the logic the embedder uses to set the networking configuration that // Sets the logic the embedder uses to set the networking configuration that
// causes traffic to be proxied. // causes traffic to be proxied.
void SetProxyConfigurator( void SetProxyConfigurator(
scoped_ptr<DataReductionProxyConfigurator> configurator); scoped_ptr<DataReductionProxyConfigurator> configurator);
// If proxy authentication is compiled in, pre-cache an authentication // If proxy authentication is compiled in, pre-cache authentication
// |key| for all configured proxies in |session|. // keys for all configured proxies in |session|.
static void InitDataReductionProxySession(net::HttpNetworkSession* session, static void InitDataReductionProxySession(
const std::string& key); net::HttpNetworkSession* session,
const DataReductionProxyParams* params);
// Returns true if the data reduction proxy is allowed to be used. This could
// return false, for example, if this instance is not part of the field trial,
// or if the proxy name is not configured via gyp.
static bool IsDataReductionProxyAllowed();
// Returns true if a screen promoting the data reduction proxy is allowed to
// be shown. Logic that decides when to show the promo should check its
// availability. This would return false if not part of a separate field
// trial that governs the use of the promotion.
static bool IsDataReductionProxyPromoAllowed();
// Returns true if preconnect advisory hinting is enabled by command line
// flag or Finch trial.
static bool IsPreconnectHintingAllowed();
// Returns the URL of the data reduction proxy.
static std::string GetDataReductionProxyOrigin();
// Returns the URL of the fallback data reduction proxy.
static std::string GetDataReductionProxyFallback();
// Returns a vector of GURLs for all configured proxies.
static DataReductionProxyList GetDataReductionProxies();
// Returns true if |auth_info| represents an authentication challenge from // Returns true if |auth_info| represents an authentication challenge from
// a compatible, configured proxy. // a compatible, configured proxy.
static bool IsAcceptableAuthChallenge(net::AuthChallengeInfo* auth_info); bool IsAcceptableAuthChallenge(net::AuthChallengeInfo* auth_info);
// Returns a UTF16 string suitable for use as an authentication token in // Returns a UTF16 string suitable for use as an authentication token in
// response to the challenge represented by |auth_info|. If the token can't // response to the challenge represented by |auth_info|. If the token can't
...@@ -182,6 +140,9 @@ class DataReductionProxySettings ...@@ -182,6 +140,9 @@ class DataReductionProxySettings
// Returns true if the proxy is enabled. // Returns true if the proxy is enabled.
bool IsDataReductionProxyEnabled(); bool IsDataReductionProxyEnabled();
// Returns true if the alternative proxy is enabled.
bool IsDataReductionProxyAlternativeEnabled();
// Returns true if the proxy is managed by an adminstrator's policy. // Returns true if the proxy is managed by an adminstrator's policy.
bool IsDataReductionProxyManaged(); bool IsDataReductionProxyManaged();
...@@ -190,15 +151,8 @@ class DataReductionProxySettings ...@@ -190,15 +151,8 @@ class DataReductionProxySettings
// probe succeeds. // probe succeeds.
void SetDataReductionProxyEnabled(bool enabled); void SetDataReductionProxyEnabled(bool enabled);
// If |allowed|, the fallback proxy will be included in the proxy // Enables or disables the alternative data reduction proxy configuration.
// configuration. void SetDataReductionProxyAlternativeEnabled(bool enabled);
void set_fallback_allowed(bool allowed) {
fallback_allowed_ = allowed;
}
bool fallback_allowed() const {
return fallback_allowed_;
}
// Returns the time in microseconds that the last update was made to the // Returns the time in microseconds that the last update was made to the
// daily original and received content lengths. // daily original and received content lengths.
...@@ -232,13 +186,17 @@ class DataReductionProxySettings ...@@ -232,13 +186,17 @@ class DataReductionProxySettings
ContentLengthList GetDailyContentLengths(const char* pref_name); ContentLengthList GetDailyContentLengths(const char* pref_name);
// Sets the proxy configs, enabling or disabling the proxy according to // Sets the proxy configs, enabling or disabling the proxy according to
// the value of |enabled|. If |restricted| is true, only enable the fallback // the value of |enabled| and |alternative_enabled|. Use the alternative
// proxy. |at_startup| is true when this method is called from // configuration only if |enabled| and |alternative_enabled| are true. If
// InitDataReductionProxySettings. // |restricted| is true, only enable the fallback proxy. |at_startup| is true
virtual void SetProxyConfigs(bool enabled, bool restricted, bool at_startup); // when this method is called from InitDataReductionProxySettings.
virtual void SetProxyConfigs(bool enabled,
// Metrics methods. Subclasses should override if they wish to provide bool alternative_enabled,
// alternate methods. bool restricted,
bool at_startup);
// Metrics method. Subclasses should override if they wish to provide
// alternatives.
virtual void RecordDataReductionInit(); virtual void RecordDataReductionInit();
virtual void AddDefaultProxyBypassRules(); virtual void AddDefaultProxyBypassRules();
...@@ -253,10 +211,13 @@ class DataReductionProxySettings ...@@ -253,10 +211,13 @@ class DataReductionProxySettings
virtual void RecordStartupState( virtual void RecordStartupState(
data_reduction_proxy::ProxyStartupState state); data_reduction_proxy::ProxyStartupState state);
DataReductionProxyConfigurator* config() { DataReductionProxyConfigurator* configurator() {
return config_.get(); return configurator_.get();
} }
// Reset params for tests.
void ResetParamsForTest(DataReductionProxyParams* params);
private: private:
friend class DataReductionProxySettingsTestBase; friend class DataReductionProxySettingsTestBase;
friend class DataReductionProxySettingsTest; friend class DataReductionProxySettingsTest;
...@@ -288,16 +249,20 @@ class DataReductionProxySettings ...@@ -288,16 +249,20 @@ class DataReductionProxySettings
TestBypassList); TestBypassList);
FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
CheckInitMetricsWhenNotAllowed); CheckInitMetricsWhenNotAllowed);
FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
TestSetProxyConfigs);
// NetworkChangeNotifier::IPAddressObserver: // NetworkChangeNotifier::IPAddressObserver:
virtual void OnIPAddressChanged() OVERRIDE; virtual void OnIPAddressChanged() OVERRIDE;
// Underlying implementation of InitDataReductionProxySession(), factored // Underlying implementation of InitDataReductionProxySession(), factored
// out to be testable without creating a full HttpNetworkSession. // out to be testable without creating a full HttpNetworkSession.
static void InitDataReductionAuthentication(net::HttpAuthCache* auth_cache, static void InitDataReductionAuthentication(
const std::string& key); net::HttpAuthCache* auth_cache,
const DataReductionProxyParams* params);
void OnProxyEnabledPrefChange(); void OnProxyEnabledPrefChange();
void OnProxyAlternativeEnabledPrefChange();
void ResetDataReductionStatistics(); void ResetDataReductionStatistics();
...@@ -307,15 +272,12 @@ class DataReductionProxySettings ...@@ -307,15 +272,12 @@ class DataReductionProxySettings
// the proxy, if enabled. Otherwise enables the proxy if disabled by a probe // the proxy, if enabled. Otherwise enables the proxy if disabled by a probe
// failure. // failure.
void ProbeWhetherDataReductionProxyIsAvailable(); void ProbeWhetherDataReductionProxyIsAvailable();
std::string GetProxyCheckURL();
// Returns a UTF16 string that's the hash of the configured authentication // Returns a UTF16 string that's the hash of the configured authentication
// |key| and |salt|. Returns an empty UTF16 string if no key is configured or // |key| and |salt|. Returns an empty UTF16 string if no key is configured or
// the data reduction proxy feature isn't available. // the data reduction proxy feature isn't available.
static base::string16 AuthHashForSalt(int64 salt, const std::string& key); static base::string16 AuthHashForSalt(int64 salt,
const std::string& key);
static bool allowed_;
static bool promo_allowed_;
std::string key_; std::string key_;
bool restricted_by_carrier_; bool restricted_by_carrier_;
...@@ -323,17 +285,18 @@ class DataReductionProxySettings ...@@ -323,17 +285,18 @@ class DataReductionProxySettings
scoped_ptr<net::URLFetcher> fetcher_; scoped_ptr<net::URLFetcher> fetcher_;
BooleanPrefMember spdy_proxy_auth_enabled_; BooleanPrefMember spdy_proxy_auth_enabled_;
BooleanPrefMember data_reduction_proxy_alternative_enabled_;
PrefService* prefs_; PrefService* prefs_;
PrefService* local_state_prefs_; PrefService* local_state_prefs_;
net::URLRequestContextGetter* url_request_context_getter_; net::URLRequestContextGetter* url_request_context_getter_;
scoped_ptr<DataReductionProxyConfigurator> config_; scoped_ptr<DataReductionProxyConfigurator> configurator_;
base::ThreadChecker thread_checker_; base::ThreadChecker thread_checker_;
bool fallback_allowed_; scoped_ptr<DataReductionProxyParams> params_;
DISALLOW_COPY_AND_ASSIGN(DataReductionProxySettings); DISALLOW_COPY_AND_ASSIGN(DataReductionProxySettings);
}; };
......
...@@ -19,7 +19,7 @@ using testing::Return; ...@@ -19,7 +19,7 @@ using testing::Return;
namespace { namespace {
const char kDataReductionProxy[] = "https://foo.com:443/"; const char kDataReductionProxy[] = "https://foo.com:443/";
const char kDataReductionProxyFallback[] = "http://bar.com:80"; const char kDataReductionProxyFallback[] = "http://bar.com:80/";
const char kDataReductionProxyKey[] = "12345"; const char kDataReductionProxyKey[] = "12345";
const char kProbeURLWithOKResponse[] = "http://ok.org/"; const char kProbeURLWithOKResponse[] = "http://ok.org/";
...@@ -49,20 +49,44 @@ ProbeURLFetchResult FetchResult(bool enabled, bool success) { ...@@ -49,20 +49,44 @@ ProbeURLFetchResult FetchResult(bool enabled, bool success) {
return FAILED_PROXY_ALREADY_DISABLED; return FAILED_PROXY_ALREADY_DISABLED;
} }
TestDataReductionProxyConfig::TestDataReductionProxyConfig()
: enabled_(false),
restricted_(false),
fallback_restricted_(false) {}
void TestDataReductionProxyConfig::Enable( void TestDataReductionProxyConfig::Enable(
bool restricted, bool restricted,
bool fallback_restricted, bool fallback_restricted,
const std::string& primary_origin, const std::string& primary_origin,
const std::string& fallback_origin) { const std::string& fallback_origin,
const std::string& ssl_origin) {
enabled_ = true; enabled_ = true;
restricted_ = restricted; restricted_ = restricted;
fallback_restricted_ = fallback_restricted; fallback_restricted_ = fallback_restricted;
origin_ = primary_origin;
fallback_origin_ = fallback_origin;
ssl_origin_ = ssl_origin;
} }
void TestDataReductionProxyConfig::Disable() { void TestDataReductionProxyConfig::Disable() {
enabled_ = false; enabled_ = false;
restricted_ = false; restricted_ = false;
fallback_restricted_ = false; fallback_restricted_ = false;
origin_ = "";
fallback_origin_ = "";
ssl_origin_ = "";
}
// static
void DataReductionProxySettingsTestBase::AddTestProxyToCommandLine() {
CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kDataReductionProxy, kDataReductionProxy);
CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kDataReductionProxyFallback, kDataReductionProxyFallback);
CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kDataReductionProxyKey, kDataReductionProxyKey);
CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kDataReductionProxyProbeURL, kProbeURLWithOKResponse);
} }
DataReductionProxySettingsTestBase::DataReductionProxySettingsTestBase() DataReductionProxySettingsTestBase::DataReductionProxySettingsTestBase()
...@@ -72,18 +96,11 @@ DataReductionProxySettingsTestBase::DataReductionProxySettingsTestBase() ...@@ -72,18 +96,11 @@ DataReductionProxySettingsTestBase::DataReductionProxySettingsTestBase()
DataReductionProxySettingsTestBase::~DataReductionProxySettingsTestBase() {} DataReductionProxySettingsTestBase::~DataReductionProxySettingsTestBase() {}
void DataReductionProxySettingsTestBase::AddProxyToCommandLine() { void DataReductionProxySettingsTestBase::AddProxyToCommandLine() {
DataReductionProxySettings::SetAllowed(true); AddTestProxyToCommandLine();
CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kDataReductionProxy, kDataReductionProxy);
CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kDataReductionProxyFallback, kDataReductionProxyFallback);
CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kDataReductionProxyKey, kDataReductionProxyKey);
} }
// testing::Test implementation: // testing::Test implementation:
void DataReductionProxySettingsTestBase::SetUp() { void DataReductionProxySettingsTestBase::SetUp() {
DataReductionProxySettings::SetAllowed(true);
PrefRegistrySimple* registry = pref_service_.registry(); PrefRegistrySimple* registry = pref_service_.registry();
registry->RegisterListPref(prefs::kDailyHttpOriginalContentLength); registry->RegisterListPref(prefs::kDailyHttpOriginalContentLength);
registry->RegisterListPref(prefs::kDailyHttpReceivedContentLength); registry->RegisterListPref(prefs::kDailyHttpReceivedContentLength);
...@@ -91,9 +108,11 @@ void DataReductionProxySettingsTestBase::SetUp() { ...@@ -91,9 +108,11 @@ void DataReductionProxySettingsTestBase::SetUp() {
0L); 0L);
registry->RegisterDictionaryPref(kProxy); registry->RegisterDictionaryPref(kProxy);
registry->RegisterBooleanPref(prefs::kDataReductionProxyEnabled, false); registry->RegisterBooleanPref(prefs::kDataReductionProxyEnabled, false);
registry->RegisterBooleanPref(prefs::kDataReductionProxyAltEnabled, false);
registry->RegisterBooleanPref(prefs::kDataReductionProxyWasEnabledBefore, registry->RegisterBooleanPref(prefs::kDataReductionProxyWasEnabledBefore,
false); false);
ResetSettings(); AddProxyToCommandLine();
ResetSettings(true, true, false, true);
ListPrefUpdate original_update(&pref_service_, ListPrefUpdate original_update(&pref_service_,
prefs::kDailyHttpOriginalContentLength); prefs::kDailyHttpOriginalContentLength);
...@@ -111,9 +130,21 @@ void DataReductionProxySettingsTestBase::SetUp() { ...@@ -111,9 +130,21 @@ void DataReductionProxySettingsTestBase::SetUp() {
} }
template <class C> template <class C>
void DataReductionProxySettingsTestBase::ResetSettings() { void DataReductionProxySettingsTestBase::ResetSettings(bool allowed,
bool fallback_allowed,
bool alt_allowed,
bool promo_allowed) {
int flags = 0;
if (allowed)
flags |= DataReductionProxyParams::kAllowed;
if (fallback_allowed)
flags |= DataReductionProxyParams::kFallbackAllowed;
if (alt_allowed)
flags |= DataReductionProxyParams::kAlternativeAllowed;
if (promo_allowed)
flags |= DataReductionProxyParams::kPromoAllowed;
MockDataReductionProxySettings<C>* settings = MockDataReductionProxySettings<C>* settings =
new MockDataReductionProxySettings<C>(); new MockDataReductionProxySettings<C>(flags);
EXPECT_CALL(*settings, GetOriginalProfilePrefs()) EXPECT_CALL(*settings, GetOriginalProfilePrefs())
.Times(AnyNumber()) .Times(AnyNumber())
.WillRepeatedly(Return(&pref_service_)); .WillRepeatedly(Return(&pref_service_));
...@@ -123,12 +154,13 @@ void DataReductionProxySettingsTestBase::ResetSettings() { ...@@ -123,12 +154,13 @@ void DataReductionProxySettingsTestBase::ResetSettings() {
EXPECT_CALL(*settings, GetURLFetcher()).Times(0); EXPECT_CALL(*settings, GetURLFetcher()).Times(0);
EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0); EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0);
settings_.reset(settings); settings_.reset(settings);
settings_->config_.reset(new TestDataReductionProxyConfig()); settings_->configurator_.reset(new TestDataReductionProxyConfig());
} }
// Explicitly generate required instantiations. // Explicitly generate required instantiations.
template void template void
DataReductionProxySettingsTestBase::ResetSettings<DataReductionProxySettings>(); DataReductionProxySettingsTestBase::ResetSettings<DataReductionProxySettings>(
bool allowed, bool fallback_allowed, bool alt_allowed, bool promo_allowed);
template <class C> template <class C>
void DataReductionProxySettingsTestBase::SetProbeResult( void DataReductionProxySettingsTestBase::SetProbeResult(
...@@ -170,7 +202,8 @@ void DataReductionProxySettingsTestBase::CheckProxyConfigs( ...@@ -170,7 +202,8 @@ void DataReductionProxySettingsTestBase::CheckProxyConfigs(
bool expected_restricted, bool expected_restricted,
bool expected_fallback_restricted) { bool expected_fallback_restricted) {
TestDataReductionProxyConfig* config = TestDataReductionProxyConfig* config =
static_cast<TestDataReductionProxyConfig*>(settings_->config_.get()); static_cast<TestDataReductionProxyConfig*>(
settings_->configurator_.get());
ASSERT_EQ(expected_restricted, config->restricted_); ASSERT_EQ(expected_restricted, config->restricted_);
ASSERT_EQ(expected_fallback_restricted, config->fallback_restricted_); ASSERT_EQ(expected_fallback_restricted, config->fallback_restricted_);
ASSERT_EQ(expected_enabled, config->enabled_); ASSERT_EQ(expected_enabled, config->enabled_);
...@@ -242,7 +275,6 @@ void DataReductionProxySettingsTestBase::CheckOnPrefChange( ...@@ -242,7 +275,6 @@ void DataReductionProxySettingsTestBase::CheckOnPrefChange(
void DataReductionProxySettingsTestBase::CheckInitDataReductionProxy( void DataReductionProxySettingsTestBase::CheckInitDataReductionProxy(
bool enabled_at_startup) { bool enabled_at_startup) {
AddProxyToCommandLine();
base::MessageLoopForUI loop; base::MessageLoopForUI loop;
SetProbeResult(kProbeURLWithOKResponse, SetProbeResult(kProbeURLWithOKResponse,
"OK", "OK",
......
...@@ -21,13 +21,13 @@ namespace data_reduction_proxy { ...@@ -21,13 +21,13 @@ namespace data_reduction_proxy {
class TestDataReductionProxyConfig : public DataReductionProxyConfigurator { class TestDataReductionProxyConfig : public DataReductionProxyConfigurator {
public: public:
TestDataReductionProxyConfig() TestDataReductionProxyConfig();
: enabled_(false), restricted_(false), fallback_restricted_(false) {}
virtual ~TestDataReductionProxyConfig() {} virtual ~TestDataReductionProxyConfig() {}
virtual void Enable(bool restricted, virtual void Enable(bool restricted,
bool fallback_restricted, bool fallback_restricted,
const std::string& primary_origin, const std::string& primary_origin,
const std::string& fallback_origin) OVERRIDE; const std::string& fallback_origin,
const std::string& ssl_origin) OVERRIDE;
virtual void Disable() OVERRIDE; virtual void Disable() OVERRIDE;
virtual void AddHostPatternToBypass(const std::string& pattern) OVERRIDE {} virtual void AddHostPatternToBypass(const std::string& pattern) OVERRIDE {}
virtual void AddURLPatternToBypass(const std::string& pattern) OVERRIDE {} virtual void AddURLPatternToBypass(const std::string& pattern) OVERRIDE {}
...@@ -44,11 +44,23 @@ class TestDataReductionProxyConfig : public DataReductionProxyConfigurator { ...@@ -44,11 +44,23 @@ class TestDataReductionProxyConfig : public DataReductionProxyConfigurator {
// configuration has been disallowed. True if |Enable| is called with // configuration has been disallowed. True if |Enable| is called with
// |fallback_restricted| set to true. Defaults to false. // |fallback_restricted| set to true. Defaults to false.
bool fallback_restricted_; bool fallback_restricted_;
// The origins that are passed to |Enable|.
std::string origin_;
std::string fallback_origin_;
std::string ssl_origin_;
}; };
template <class C> template <class C>
class MockDataReductionProxySettings : public C { class MockDataReductionProxySettings : public C {
public: public:
MockDataReductionProxySettings<C>() : DataReductionProxySettings(
new DataReductionProxyParams(
DataReductionProxyParams::kAllowed |
DataReductionProxyParams::kFallbackAllowed |
DataReductionProxyParams::kPromoAllowed)) {}
MockDataReductionProxySettings<C>(int flags)
: C(new DataReductionProxyParams(flags)) {}
MOCK_METHOD0(GetURLFetcher, net::URLFetcher*()); MOCK_METHOD0(GetURLFetcher, net::URLFetcher*());
MOCK_METHOD0(GetOriginalProfilePrefs, PrefService*()); MOCK_METHOD0(GetOriginalProfilePrefs, PrefService*());
MOCK_METHOD0(GetLocalStatePrefs, PrefService*()); MOCK_METHOD0(GetLocalStatePrefs, PrefService*());
...@@ -60,24 +72,38 @@ class MockDataReductionProxySettings : public C { ...@@ -60,24 +72,38 @@ class MockDataReductionProxySettings : public C {
void(ProxyStartupState state)); void(ProxyStartupState state));
// SetProxyConfigs should always call LogProxyState exactly once. // SetProxyConfigs should always call LogProxyState exactly once.
virtual void SetProxyConfigs( virtual void SetProxyConfigs(bool enabled,
bool enabled, bool restricted, bool at_startup) OVERRIDE { bool alternative_enabled,
bool restricted,
bool at_startup) OVERRIDE {
EXPECT_CALL(*this, LogProxyState(enabled, restricted, at_startup)).Times(1); EXPECT_CALL(*this, LogProxyState(enabled, restricted, at_startup)).Times(1);
C::SetProxyConfigs(enabled, restricted, at_startup); C::SetProxyConfigs(enabled, alternative_enabled, restricted, at_startup);
} }
}; };
class DataReductionProxySettingsTestBase : public testing::Test { class DataReductionProxySettingsTestBase : public testing::Test {
public: public:
static void AddTestProxyToCommandLine();
DataReductionProxySettingsTestBase(); DataReductionProxySettingsTestBase();
DataReductionProxySettingsTestBase(bool allowed,
bool fallback_allowed,
bool alt_allowed,
bool promo_allowed);
virtual ~DataReductionProxySettingsTestBase(); virtual ~DataReductionProxySettingsTestBase();
void AddProxyToCommandLine(); void AddProxyToCommandLine();
virtual void SetUp() OVERRIDE; virtual void SetUp() OVERRIDE;
template <class C> void ResetSettings(); template <class C> void ResetSettings(bool allowed,
virtual void ResetSettings() = 0; bool fallback_allowed,
bool alt_allowed,
bool promo_allowed);
virtual void ResetSettings(bool allowed,
bool fallback_allowed,
bool alt_allowed,
bool promo_allowed) = 0;
template <class C> void SetProbeResult( template <class C> void SetProbeResult(
const std::string& test_url, const std::string& test_url,
...@@ -122,8 +148,12 @@ class ConcreteDataReductionProxySettingsTest ...@@ -122,8 +148,12 @@ class ConcreteDataReductionProxySettingsTest
: public DataReductionProxySettingsTestBase { : public DataReductionProxySettingsTestBase {
public: public:
typedef MockDataReductionProxySettings<C> MockSettings; typedef MockDataReductionProxySettings<C> MockSettings;
virtual void ResetSettings() OVERRIDE { virtual void ResetSettings(bool allowed,
return DataReductionProxySettingsTestBase::ResetSettings<C>(); bool fallback_allowed,
bool alt_allowed,
bool promo_allowed) OVERRIDE {
return DataReductionProxySettingsTestBase::ResetSettings<C>(
allowed, fallback_allowed, alt_allowed, promo_allowed);
} }
virtual void SetProbeResult(const std::string& test_url, virtual void SetProbeResult(const std::string& test_url,
......
...@@ -72,6 +72,9 @@ const char kDataReductionProxy[] = "auth.spdyproxy.origin"; ...@@ -72,6 +72,9 @@ const char kDataReductionProxy[] = "auth.spdyproxy.origin";
// A boolean specifying whether the data reduction proxy is enabled. // A boolean specifying whether the data reduction proxy is enabled.
const char kDataReductionProxyEnabled[] = "spdy_proxy.enabled"; const char kDataReductionProxyEnabled[] = "spdy_proxy.enabled";
// A boolean specifying whether the data reduction proxy alternative is enabled.
const char kDataReductionProxyAltEnabled[] = "data_reduction_alt.enabled";
// A boolean specifying whether the data reduction proxy was ever enabled // A boolean specifying whether the data reduction proxy was ever enabled
// before. // before.
const char kDataReductionProxyWasEnabledBefore[] = const char kDataReductionProxyWasEnabledBefore[] =
......
...@@ -24,6 +24,7 @@ extern const char kDailyOriginalContentLengthViaDataReductionProxy[]; ...@@ -24,6 +24,7 @@ extern const char kDailyOriginalContentLengthViaDataReductionProxy[];
extern const char kDailyOriginalContentLengthWithDataReductionProxyEnabled[]; extern const char kDailyOriginalContentLengthWithDataReductionProxyEnabled[];
extern const char kDataReductionProxy[]; extern const char kDataReductionProxy[];
extern const char kDataReductionProxyEnabled[]; extern const char kDataReductionProxyEnabled[];
extern const char kDataReductionProxyAltEnabled[];
extern const char kDataReductionProxyWasEnabledBefore[]; extern const char kDataReductionProxyWasEnabledBefore[];
extern const char kHttpOriginalContentLength[]; extern const char kHttpOriginalContentLength[];
extern const char kHttpReceivedContentLength[]; extern const char kHttpReceivedContentLength[];
......
...@@ -10,6 +10,13 @@ namespace switches { ...@@ -10,6 +10,13 @@ namespace switches {
// The origin of the data reduction proxy. // The origin of the data reduction proxy.
const char kDataReductionProxy[] = "spdy-proxy-auth-origin"; const char kDataReductionProxy[] = "spdy-proxy-auth-origin";
// The origin of an alternative data reduction proxy.
const char kDataReductionProxyAlt[] = "data-reduction-proxy-alternative";
// The origin of an alternative data reduction proxy fallback.
const char kDataReductionProxyAltFallback[] =
"data-reduction-proxy-alternative-fallback";
// The origin of the data reduction proxy dev. // The origin of the data reduction proxy dev.
const char kDataReductionProxyDev[] = "spdy-proxy-dev-auth-origin"; const char kDataReductionProxyDev[] = "spdy-proxy-dev-auth-origin";
...@@ -23,8 +30,14 @@ const char kDataReductionProxyKey[] = "spdy-proxy-auth-value"; ...@@ -23,8 +30,14 @@ const char kDataReductionProxyKey[] = "spdy-proxy-auth-value";
// proxy. Note this canary does not go through the data reduction proxy. // proxy. Note this canary does not go through the data reduction proxy.
const char kDataReductionProxyProbeURL[] = "data-reduction-proxy-probe-url"; const char kDataReductionProxyProbeURL[] = "data-reduction-proxy-probe-url";
// The origin of the data reduction SSL proxy.
const char kDataReductionSSLProxy[] = "data-reduction-ssl-proxy";
// Enable the data reduction proxy. // Enable the data reduction proxy.
const char kEnableDataReductionProxy[] = "enable-spdy-proxy-auth"; const char kEnableDataReductionProxy[] = "enable-spdy-proxy-auth";
// Enable the alternative data reduction proxy.
const char kEnableDataReductionProxyAlt[] = "enable-data-reduction-proxy-alt";
} // namespace switches } // namespace switches
} // namespace data_reduction_proxy } // namespace data_reduction_proxy
...@@ -12,11 +12,15 @@ namespace switches { ...@@ -12,11 +12,15 @@ namespace switches {
// alongside the definition of their values in the .cc file. // alongside the definition of their values in the .cc file.
extern const char kDataReductionProxy[]; extern const char kDataReductionProxy[];
extern const char kDataReductionProxyAlt[];
extern const char kDataReductionProxyAltFallback[];
extern const char kDataReductionProxyDev[]; extern const char kDataReductionProxyDev[];
extern const char kDataReductionProxyFallback[]; extern const char kDataReductionProxyFallback[];
extern const char kDataReductionProxyKey[]; extern const char kDataReductionProxyKey[];
extern const char kDataReductionProxyProbeURL[]; extern const char kDataReductionProxyProbeURL[];
extern const char kDataReductionSSLProxy[];
extern const char kEnableDataReductionProxy[]; extern const char kEnableDataReductionProxy[];
extern const char kEnableDataReductionProxyAlt[];
} // namespace switches } // namespace switches
} // namespace data_reduction_proxy } // namespace data_reduction_proxy
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment