diff options
42 files changed, 520 insertions, 1506 deletions
diff --git a/android_webview/browser/aw_browser_context.cc b/android_webview/browser/aw_browser_context.cc index 05f68e3..c6c020c 100644 --- a/android_webview/browser/aw_browser_context.cc +++ b/android_webview/browser/aw_browser_context.cc @@ -16,7 +16,6 @@ #include "base/prefs/pref_service_factory.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_params.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/user_prefs/user_prefs.h" @@ -95,23 +94,21 @@ void AwBrowserContext::SetDataReductionProxyEnabled(bool enabled) { void AwBrowserContext::PreMainMessageLoopRun() { cookie_store_ = CreateCookieStore(this); -#if defined(SPDY_PROXY_AUTH_ORIGIN) + DataReductionProxySettings::SetAllowed(true); + DataReductionProxySettings::SetPromoAllowed(false); data_reduction_proxy_settings_.reset( - new DataReductionProxySettings( - new data_reduction_proxy::DataReductionProxyParams( - data_reduction_proxy::DataReductionProxyParams::kAllowed))); -#endif + new DataReductionProxySettings()); + data_reduction_proxy_settings_->set_fallback_allowed(false); url_request_context_getter_ = new AwURLRequestContextGetter(GetPath(), cookie_store_.get()); - if (data_reduction_proxy_settings_.get()) { - scoped_ptr<data_reduction_proxy::DataReductionProxyConfigurator> - configurator(new data_reduction_proxy::DataReductionProxyConfigTracker( - url_request_context_getter_->proxy_config_service(), - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); - data_reduction_proxy_settings_->SetProxyConfigurator(configurator.Pass()); - } + scoped_ptr<data_reduction_proxy::DataReductionProxyConfigurator> + configurator(new data_reduction_proxy::DataReductionProxyConfigTracker( + url_request_context_getter_->proxy_config_service(), + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); + data_reduction_proxy_settings_->SetProxyConfigurator(configurator.Pass()); + visitedlink_master_.reset( new visitedlink::VisitedLinkMaster(this, this, false)); visitedlink_master_->Init(); @@ -186,15 +183,13 @@ void AwBrowserContext::CreateUserPrefServiceIfNecessary() { user_prefs::UserPrefs::Set(this, user_pref_service_.get()); - if (data_reduction_proxy_settings_.get()) { - data_reduction_proxy_settings_->InitDataReductionProxySettings( - user_pref_service_.get(), - user_pref_service_.get(), - GetRequestContext()); + data_reduction_proxy_settings_->InitDataReductionProxySettings( + user_pref_service_.get(), + user_pref_service_.get(), + GetRequestContext()); - data_reduction_proxy_settings_->SetDataReductionProxyEnabled( - data_reduction_proxy_enabled_); - } + data_reduction_proxy_settings_->SetDataReductionProxyEnabled( + data_reduction_proxy_enabled_); } base::FilePath AwBrowserContext::GetPath() const { diff --git a/android_webview/browser/net/aw_url_request_context_getter.cc b/android_webview/browser/net/aw_url_request_context_getter.cc index 9ed9e7e..218f09a 100644 --- a/android_webview/browser/net/aw_url_request_context_getter.cc +++ b/android_webview/browser/net/aw_url_request_context_getter.cc @@ -200,14 +200,11 @@ void AwURLRequestContextGetter::InitializeURLRequestContext() { AwContentBrowserClient::GetAcceptLangsImpl())); 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( data_reduction_proxy::HttpAuthHandlerDataReductionProxy::Scheme(), new data_reduction_proxy::HttpAuthHandlerDataReductionProxy::Factory( - drp_params.GetAllowedProxies())); -#endif + DataReductionProxySettings::GetDataReductionProxies())); url_request_context_.reset(builder.Build()); // TODO(mnaganov): Fix URLRequestContextBuilder to use proper threads. @@ -225,21 +222,18 @@ void AwURLRequestContextGetter::InitializeURLRequestContext() { 20 * 1024 * 1024, // 20M BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE))); -#if defined(SPDY_PROXY_AUTH_ORIGIN) AwBrowserContext* browser_context = AwBrowserContext::GetDefault(); DCHECK(browser_context); DataReductionProxySettings* drp_settings = browser_context->GetDataReductionProxySettings(); - if (drp_settings) { - std::string drp_key = drp_settings->params()->key(); - // Only precache credentials if a key is available at URLRequestContext - // initialization. - if (!drp_key.empty()) { - DataReductionProxySettings::InitDataReductionProxySession( - main_cache->GetSession(), &drp_params); - } + DCHECK(drp_settings); + std::string drp_key = drp_settings->key(); + // Only precache credentials if a key is available at URLRequestContext + // initialization. + if (!drp_key.empty()) { + DataReductionProxySettings::InitDataReductionProxySession( + main_cache->GetSession(), drp_settings->key()); } -#endif main_http_factory_.reset(main_cache); url_request_context_->set_http_transaction_factory(main_cache); diff --git a/android_webview/native/aw_contents_statics.cc b/android_webview/native/aw_contents_statics.cc index 70525af..0cd4964 100644 --- a/android_webview/native/aw_contents_statics.cc +++ b/android_webview/native/aw_contents_statics.cc @@ -54,8 +54,8 @@ void SetDataReductionProxyKey(JNIEnv* env, jclass, jstring key) { DCHECK(browser_context); DataReductionProxySettings* drp_settings = browser_context->GetDataReductionProxySettings(); - if (drp_settings) - drp_settings->params()->set_key(ConvertJavaStringToUTF8(env, key)); + DCHECK(drp_settings); + drp_settings->set_key(ConvertJavaStringToUTF8(env, key)); } // static diff --git a/build/common.gypi b/build/common.gypi index a18f871..0e9cdea 100644 --- a/build/common.gypi +++ b/build/common.gypi @@ -550,9 +550,6 @@ 'spdy_proxy_auth_property%' : '', 'spdy_proxy_auth_value%' : '', '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_service_discovery%': 0, 'enable_wifi_bootstrapping%': 0, @@ -1102,9 +1099,6 @@ '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_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_service_discovery%' : '<(enable_service_discovery)', 'enable_wifi_bootstrapping%': '<(enable_wifi_bootstrapping)', @@ -2724,18 +2718,6 @@ 'defines': [ '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', { 'defines': ['ENABLE_MDNS=1'], }], diff --git a/chrome/android/java/src/org/chromium/chrome/browser/net/spdyproxy/DataReductionProxySettings.java b/chrome/android/java/src/org/chromium/chrome/browser/net/spdyproxy/DataReductionProxySettings.java index 4444a6f..c11c7c8 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/net/spdyproxy/DataReductionProxySettings.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/net/spdyproxy/DataReductionProxySettings.java @@ -10,15 +10,8 @@ import org.chromium.base.ThreadUtils; import java.text.NumberFormat; import java.util.Locale; -/** - * Entry point to manage all data reduction proxy configuration details. - */ 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 { private final long mOriginal; private final long mReceived; @@ -44,9 +37,6 @@ public class DataReductionProxySettings { private static DataReductionProxySettings sSettings; - /** - * Returns a singleton instance of the settings object. - */ public static DataReductionProxySettings getInstance() { ThreadUtils.assertOnUiThread(); if (sSettings == null) { @@ -62,6 +52,14 @@ public class DataReductionProxySettings { // DataReductionProxySettings is a singleton that lives forever and there's no clean // shutdown of Chrome on Android mNativeDataReductionProxySettings = nativeInit(); + initDataReductionProxySettings(); + } + + /** + * Initializes the data reduction proxy at Chrome startup. + */ + public void initDataReductionProxySettings() { + nativeInitDataReductionProxySettings(mNativeDataReductionProxySettings); } /** @@ -193,6 +191,8 @@ public class DataReductionProxySettings { } private native long nativeInit(); + private native void nativeInitDataReductionProxySettings( + long nativeDataReductionProxySettingsAndroid); private native void nativeBypassHostPattern( long nativeDataReductionProxySettingsAndroid, String pattern); private native void nativeBypassURLPattern( diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc index 96e327d..6893de8 100644 --- a/chrome/browser/io_thread.cc +++ b/chrome/browser/io_thread.cc @@ -95,7 +95,6 @@ #endif #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" #endif @@ -107,7 +106,6 @@ using content::BrowserThread; #if defined(OS_ANDROID) || defined(OS_IOS) -using data_reduction_proxy::DataReductionProxyParams; using data_reduction_proxy::DataReductionProxySettings; #endif @@ -597,17 +595,10 @@ void IOThread::InitAsync() { #endif globals_->ssl_config_service = GetSSLConfigService(); #if defined(OS_ANDROID) || defined(OS_IOS) -#if defined(SPDY_PROXY_AUTH_ORIGIN) - int drp_flags = DataReductionProxyParams::kFallbackAllowed; - 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) + if (DataReductionProxySettings::IsIncludedInFieldTrialOrFlags()) { + spdyproxy_auth_origins_ = + DataReductionProxySettings::GetDataReductionProxies(); + } #endif // defined(OS_ANDROID) || defined(OS_IOS) globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( globals_->host_resolver.get())); @@ -910,15 +901,11 @@ net::HttpAuthHandlerFactory* IOThread::CreateDefaultAuthHandlerFactory( resolver, gssapi_library_name_, negotiate_disable_cname_lookup_, negotiate_enable_port_)); - if (globals_->data_reduction_proxy_params.get()) { - std::vector<GURL> data_reduction_proxies = - globals_->data_reduction_proxy_params->GetAllowedProxies(); - if (!data_reduction_proxies.empty()) { - registry_factory->RegisterSchemeFactory( - "spdyproxy", - new data_reduction_proxy::HttpAuthHandlerDataReductionProxy::Factory( - data_reduction_proxies)); - } + if (!spdyproxy_auth_origins_.empty()) { + registry_factory->RegisterSchemeFactory( + "spdyproxy", + new data_reduction_proxy::HttpAuthHandlerDataReductionProxy::Factory( + spdyproxy_auth_origins_)); } return registry_factory.release(); diff --git a/chrome/browser/io_thread.h b/chrome/browser/io_thread.h index 8c991b7..6feb064 100644 --- a/chrome/browser/io_thread.h +++ b/chrome/browser/io_thread.h @@ -16,7 +16,6 @@ #include "base/prefs/pref_member.h" #include "base/time/time.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_delegate.h" #include "net/base/network_change_notifier.h" @@ -182,8 +181,6 @@ class IOThread : public content::BrowserThreadDelegate { // 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. 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. @@ -351,6 +348,7 @@ class IOThread : public content::BrowserThreadDelegate { std::string auth_server_whitelist_; std::string auth_delegate_whitelist_; std::string gssapi_library_name_; + std::vector<GURL> spdyproxy_auth_origins_; // This is an instance of the default SSLConfigServiceManager for the current // platform and it gets SSL preferences from local_state object. diff --git a/chrome/browser/net/predictor.cc b/chrome/browser/net/predictor.cc index 74b1c8a..6c4121f 100644 --- a/chrome/browser/net/predictor.cc +++ b/chrome/browser/net/predictor.cc @@ -337,8 +337,8 @@ void Predictor::InitNetworkPredictor(PrefService* user_prefs, // Until then, we may create a proxy advisor when the proxy feature itself // isn't available, and the advisor instance will never send advisory // requests, which is slightly wasteful but not harmful. - if (data_reduction_proxy::DataReductionProxyParams:: - IsIncludedInPreconnectHintingFieldTrial()) { + if (data_reduction_proxy::DataReductionProxySettings:: + IsPreconnectHintingAllowed()) { proxy_advisor_.reset(new ProxyAdvisor(user_prefs, getter)); } #endif diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.cc b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.cc index 1201cf0..25cc7e4 100644 --- a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.cc +++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.cc @@ -18,12 +18,10 @@ DataReductionProxyChromeConfigurator::DataReductionProxyChromeConfigurator( DataReductionProxyChromeConfigurator::~DataReductionProxyChromeConfigurator() { } -void DataReductionProxyChromeConfigurator::Enable( - bool primary_restricted, - bool fallback_restricted, - const std::string& primary_origin, - const std::string& fallback_origin, - const std::string& ssl_origin) { +void DataReductionProxyChromeConfigurator::Enable(bool primary_restricted, + bool fallback_restricted, + const std::string& primary_origin, + const std::string& fallback_origin) { DCHECK(prefs_); DictionaryPrefUpdate update(prefs_, prefs::kProxy); base::DictionaryValue* dict = update.Get(); @@ -51,13 +49,7 @@ void DataReductionProxyChromeConfigurator::Enable( return; } - 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("server", "http=" + JoinString(proxies, ",") + ",direct://;"); dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS)); dict->SetString("bypass_list", JoinString(bypass_rules_, ", ")); } diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.h b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.h index 8efc3ed..e23efbe 100644 --- a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.h +++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.h @@ -22,8 +22,7 @@ class DataReductionProxyChromeConfigurator virtual void Enable(bool primary_restricted, bool fallback_restricted, const std::string& primary_origin, - const std::string& fallback_origin, - const std::string& ssl_origin) OVERRIDE; + const std::string& fallback_origin) OVERRIDE; virtual void Disable() OVERRIDE; // Add a host pattern to bypass. This should follow the same syntax used diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator_unittest.cc b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator_unittest.cc index eb56ef5..a8ef6dc 100644 --- a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator_unittest.cc +++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator_unittest.cc @@ -48,35 +48,19 @@ TEST_F(DataReductionProxyConfigTest, TestUnrestricted) { config_->Enable(false, false, "https://www.foo.com:443/", - "http://www.bar.com:80/", - ""); + "http://www.bar.com:80/"); CheckProxyConfig( "fixed_servers", "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) { config_->AddHostPatternToBypass("<local>"); config_->AddHostPatternToBypass("*.goo.com"); config_->Enable(false, false, "https://www.foo.com:443/", - "http://www.bar.com:80/", - ""); + "http://www.bar.com:80/"); CheckProxyConfig( "fixed_servers", "http=https://www.foo.com:443,http://www.bar.com:80,direct://;", @@ -84,7 +68,10 @@ TEST_F(DataReductionProxyConfigTest, TestUnrestrictedWithBypassRule) { } TEST_F(DataReductionProxyConfigTest, TestUnrestrictedWithoutFallback) { - config_->Enable(false, false, "https://www.foo.com:443/", "", ""); + config_->Enable(false, + false, + "https://www.foo.com:443/", + ""); CheckProxyConfig("fixed_servers", "http=https://www.foo.com:443,direct://;", ""); @@ -94,8 +81,7 @@ TEST_F(DataReductionProxyConfigTest, TestRestricted) { config_->Enable(true, false, "https://www.foo.com:443/", - "http://www.bar.com:80/", - ""); + "http://www.bar.com:80/"); CheckProxyConfig("fixed_servers", "http=http://www.bar.com:80,direct://;", ""); @@ -105,8 +91,7 @@ TEST_F(DataReductionProxyConfigTest, TestFallbackRestricted) { config_->Enable(false, true, "https://www.foo.com:443/", - "http://www.bar.com:80/", - ""); + "http://www.bar.com:80/"); CheckProxyConfig("fixed_servers", "http=https://www.foo.com:443,direct://;", ""); @@ -116,8 +101,7 @@ TEST_F(DataReductionProxyConfigTest, TestBothRestricted) { config_->Enable(true, true, "https://www.foo.com:443/", - "http://www.bar.com:80/", - ""); + "http://www.bar.com:80/"); CheckProxyConfig("system", "", ""); } diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.cc b/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.cc index 211ff61..7cba6e3 100644 --- a/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.cc +++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.cc @@ -18,14 +18,12 @@ #include "base/strings/utf_string_conversions.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_settings_factory_android.h" #include "chrome/browser/prefs/proxy_prefs.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/common/chrome_switches.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_params.h" #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h" #include "jni/DataReductionProxySettings_jni.h" #include "net/base/auth.h" @@ -41,7 +39,6 @@ using base::android::ConvertJavaStringToUTF8; using base::android::ConvertUTF16ToJavaString; using base::android::ConvertUTF8ToJavaString; using base::android::ScopedJavaLocalRef; -using data_reduction_proxy::DataReductionProxyParams; using data_reduction_proxy::DataReductionProxySettings; namespace { @@ -58,20 +55,33 @@ enum { NUM_SPDY_PROXY_AUTH_STATE }; +const char kEnabled[] = "Enabled"; + } // namespace DataReductionProxySettingsAndroid::DataReductionProxySettingsAndroid( - data_reduction_proxy::DataReductionProxyParams* params) - : DataReductionProxySettings(params) { + JNIEnv* env, jobject obj) : DataReductionProxySettings() { +#if defined(SPDY_PROXY_AUTH_VALUE) + 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() { } void DataReductionProxySettingsAndroid::InitDataReductionProxySettings( - Profile* profile) { - DCHECK(profile); - PrefService* prefs = profile->GetPrefs(); + JNIEnv* env, + jobject obj) { + PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs(); scoped_ptr<data_reduction_proxy::DataReductionProxyConfigurator> configurator(new DataReductionProxyChromeConfigurator(prefs)); @@ -80,34 +90,33 @@ void DataReductionProxySettingsAndroid::InitDataReductionProxySettings( prefs, g_browser_process->local_state(), ProfileManager::GetActiveUserProfile()->GetRequestContext()); - DataReductionProxySettings::SetDataReductionProxyAlternativeEnabled( - DataReductionProxyParams::IsIncludedInAlternativeFieldTrial()); } void DataReductionProxySettingsAndroid::BypassHostPattern( JNIEnv* env, jobject obj, jstring pattern) { - configurator()->AddHostPatternToBypass( + config()->AddHostPatternToBypass( ConvertJavaStringToUTF8(env, pattern)); } void DataReductionProxySettingsAndroid::BypassURLPattern( JNIEnv* env, jobject obj, jstring pattern) { - configurator()->AddURLPatternToBypass(ConvertJavaStringToUTF8(env, pattern)); + config()->AddURLPatternToBypass(ConvertJavaStringToUTF8(env, pattern)); } jboolean DataReductionProxySettingsAndroid::IsDataReductionProxyAllowed( JNIEnv* env, jobject obj) { - return params()->allowed(); + return DataReductionProxySettings::IsDataReductionProxyAllowed(); } jboolean DataReductionProxySettingsAndroid::IsDataReductionProxyPromoAllowed( JNIEnv* env, jobject obj) { - return params()->promo_allowed(); + return DataReductionProxySettings::IsDataReductionProxyPromoAllowed(); } ScopedJavaLocalRef<jstring> DataReductionProxySettingsAndroid::GetDataReductionProxyOrigin( JNIEnv* env, jobject obj) { - return ConvertUTF8ToJavaString(env, params()->origin().spec()); + return ConvertUTF8ToJavaString( + env, DataReductionProxySettings::GetDataReductionProxyOrigin()); } jboolean DataReductionProxySettingsAndroid::IsDataReductionProxyEnabled( @@ -201,38 +210,26 @@ void DataReductionProxySettingsAndroid::AddDefaultProxyBypassRules() { DataReductionProxySettings::AddDefaultProxyBypassRules(); // Chrome cannot authenticate with the data reduction proxy when fetching URLs // from the settings menu. - configurator()->AddURLPatternToBypass( - "http://www.google.com/policies/privacy*"); + config()->AddURLPatternToBypass("http://www.google.com/policies/privacy*"); } -void DataReductionProxySettingsAndroid::SetProxyConfigs( - bool enabled, - bool alternative_enabled, - bool restricted, - bool at_startup) { +void DataReductionProxySettingsAndroid::SetProxyConfigs(bool enabled, + bool restricted, + bool at_startup) { // Sanity check: If there's no fallback proxy, we can't do a restricted mode. - std::string fallback = params()->fallback_origin().spec(); + std::string fallback = GetDataReductionProxyFallback(); if (fallback.empty() && enabled && restricted) enabled = false; LogProxyState(enabled, restricted, at_startup); if (enabled) { - if (alternative_enabled) { - configurator()->Enable(restricted, - !params()->fallback_allowed(), - 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()); - } + config()->Enable(restricted, + !fallback_allowed(), + DataReductionProxySettings::GetDataReductionProxyOrigin(), + GetDataReductionProxyFallback()); } else { - configurator()->Disable(); + config()->Disable(); } } @@ -259,7 +256,6 @@ DataReductionProxySettingsAndroid::GetDailyContentLengths( // Used by generated jni code. static jlong Init(JNIEnv* env, jobject obj) { DataReductionProxySettingsAndroid* settings = - DataReductionProxySettingsFactoryAndroid::GetForBrowserContext( - ProfileManager::GetActiveUserProfile()); + new DataReductionProxySettingsAndroid(env, obj); return reinterpret_cast<intptr_t>(settings); } diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h b/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h index 7df436f..4106192 100644 --- a/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h +++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h @@ -14,31 +14,24 @@ #include "base/memory/scoped_ptr.h" #include "base/prefs/pref_member.h" #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h" -#include "components/keyed_service/core/keyed_service.h" -using base::android::ScopedJavaLocalRef; -class Profile; +using base::android::ScopedJavaLocalRef; -namespace data_reduction_proxy { -class DataReductionProxyParams; -} // 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 // be called from there. class DataReductionProxySettingsAndroid - : public data_reduction_proxy::DataReductionProxySettings, - public KeyedService { + : public data_reduction_proxy::DataReductionProxySettings { public: - // Factory constructor. - DataReductionProxySettingsAndroid( - data_reduction_proxy::DataReductionProxyParams* params); - + DataReductionProxySettingsAndroid(JNIEnv* env, jobject obj); + // Parameter-free constructor for C++ unit tests. + DataReductionProxySettingsAndroid(); virtual ~DataReductionProxySettingsAndroid(); - void InitDataReductionProxySettings(Profile* profile); + void InitDataReductionProxySettings(JNIEnv* env, jobject obj); void BypassHostPattern(JNIEnv* env, jobject obj, jstring pattern); // Add a URL pattern to bypass the proxy. Wildcards @@ -89,10 +82,8 @@ class DataReductionProxySettingsAndroid // Configures the proxy settings by generating a data URL containing a PAC // file. - virtual void SetProxyConfigs(bool enabled, - bool alt_enabled, - bool restricted, - bool at_startup) OVERRIDE; + virtual void SetProxyConfigs( + bool enabled, bool restricted, bool at_startup) OVERRIDE; private: friend class DataReductionProxySettingsAndroidTest; diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_factory_android.cc b/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_factory_android.cc deleted file mode 100644 index 1cda259..0000000 --- a/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_factory_android.cc +++ /dev/null @@ -1,63 +0,0 @@ -// 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; -} - diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_factory_android.h b/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_factory_android.h deleted file mode 100644 index 272f56b..0000000 --- a/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_factory_android.h +++ /dev/null @@ -1,47 +0,0 @@ -// 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_ diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest_android.cc b/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest_android.cc index 65d97d9..0416461 100644 --- a/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest_android.cc +++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest_android.cc @@ -26,19 +26,9 @@ const char kDataReductionProxyOrigin[] = "https://foo.com:443/"; const char kDataReductionProxyDev[] = "http://foo-dev.com:80"; template <class C> -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; +void data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings() { MockDataReductionProxySettings<C>* settings = - new MockDataReductionProxySettings<C>(flags); + new MockDataReductionProxySettings<C>; EXPECT_CALL(*settings, GetOriginalProfilePrefs()) .Times(AnyNumber()) .WillRepeatedly(Return(&pref_service_)); @@ -78,10 +68,7 @@ void data_reduction_proxy::DataReductionProxySettingsTestBase::SetProbeResult( template void data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings< - DataReductionProxySettingsAndroid>(bool allowed, - bool fallback_allowed, - bool alt_allowed, - bool promo_allowed); + DataReductionProxySettingsAndroid>(); template void data_reduction_proxy::DataReductionProxySettingsTestBase::SetProbeResult< @@ -99,7 +86,6 @@ class DataReductionProxySettingsAndroidTest virtual void SetUp() OVERRIDE { env_ = base::android::AttachCurrentThread(); DataReductionProxySettingsAndroid::Register(env_); - DataReductionProxySettingsTestBase::AddProxyToCommandLine(); DataReductionProxySettingsTestBase::SetUp(); } @@ -111,27 +97,26 @@ class DataReductionProxySettingsAndroidTest }; TEST_F(DataReductionProxySettingsAndroidTest, TestGetDataReductionProxyOrigin) { + AddProxyToCommandLine(); // SetUp() adds the origin to the command line, which should be returned here. ScopedJavaLocalRef<jstring> result = Settings()->GetDataReductionProxyOrigin(env_, NULL); ASSERT_TRUE(result.obj()); const base::android::JavaRef<jstring>& str_ref = result; - EXPECT_EQ(GURL(kDataReductionProxyOrigin), - GURL(ConvertJavaStringToUTF8(str_ref))); + EXPECT_EQ(kDataReductionProxyOrigin, ConvertJavaStringToUTF8(str_ref)); } TEST_F(DataReductionProxySettingsAndroidTest, TestGetDataReductionProxyDevOrigin) { + AddProxyToCommandLine(); CommandLine::ForCurrentProcess()->AppendSwitchASCII( data_reduction_proxy::switches::kDataReductionProxyDev, kDataReductionProxyDev); - ResetSettings(true, true, false, true); ScopedJavaLocalRef<jstring> result = Settings()->GetDataReductionProxyOrigin(env_, NULL); ASSERT_TRUE(result.obj()); const base::android::JavaRef<jstring>& str_ref = result; - EXPECT_EQ(GURL(kDataReductionProxyDev), - GURL(ConvertJavaStringToUTF8(str_ref))); + EXPECT_EQ(kDataReductionProxyDev, ConvertJavaStringToUTF8(str_ref)); } TEST_F(DataReductionProxySettingsAndroidTest, TestGetDailyContentLengths) { diff --git a/chrome/browser/net/spdyproxy/proxy_advisor.cc b/chrome/browser/net/spdyproxy/proxy_advisor.cc index 3f219a8..f15851a 100644 --- a/chrome/browser/net/spdyproxy/proxy_advisor.cc +++ b/chrome/browser/net/spdyproxy/proxy_advisor.cc @@ -11,7 +11,6 @@ #include "base/stl_util.h" #include "chrome/common/chrome_switches.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 "content/public/browser/browser_thread.h" #include "net/base/load_flags.h" @@ -22,8 +21,6 @@ #include "net/url_request/url_request_context.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. #if !defined(OS_ANDROID) && !defined(OS_IOS) #error proxy_advisor should only be included in Android or iOS builds. @@ -122,12 +119,8 @@ void ProxyAdvisor::Advise( std::string motivation_name(MotivationName(motivation, is_preconnect)); std::string header_value = motivation_name + " " + url.spec(); 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 = - params.origin().spec() + "preconnect"; + DataReductionProxySettings::GetDataReductionProxyOrigin() + "preconnect"; scoped_ptr<net::URLRequest> request = context->CreateRequest( GURL(endpoint), net::DEFAULT_PRIORITY, this, NULL); request->set_method("HEAD"); diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc index edfcf62..915f5c3 100644 --- a/chrome/browser/profiles/profile_impl_io_data.cc +++ b/chrome/browser/profiles/profile_impl_io_data.cc @@ -484,9 +484,8 @@ void ProfileImplIOData::InitializeInternal( #if defined(OS_ANDROID) || defined(OS_IOS) #if defined(SPDY_PROXY_AUTH_VALUE) data_reduction_proxy::DataReductionProxySettings:: - InitDataReductionProxySession( - main_cache->GetSession(), - io_thread_globals->data_reduction_proxy_params.get()); + InitDataReductionProxySession(main_cache->GetSession(), + SPDY_PROXY_AUTH_VALUE); #endif #endif diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 8163020..23005a5 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1330,8 +1330,6 @@ '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.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.h', 'browser/net/spdyproxy/proxy_advisor.cc', diff --git a/components/components_tests.gyp b/components/components_tests.gyp index 01c99a6..43e1f47 100644 --- a/components/components_tests.gyp +++ b/components/components_tests.gyp @@ -74,7 +74,6 @@ '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_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/http_auth_handler_data_reduction_proxy_unittest.cc', 'dom_distiller/core/article_entry_unittest.cc', diff --git a/components/data_reduction_proxy.gypi b/components/data_reduction_proxy.gypi index bfe50a2..31aa0bd 100644 --- a/components/data_reduction_proxy.gypi +++ b/components/data_reduction_proxy.gypi @@ -26,8 +26,6 @@ '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.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.h', 'data_reduction_proxy/browser/data_reduction_proxy_settings.cc', diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.cc index 590598a..1158748 100644 --- a/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.cc +++ b/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.cc @@ -35,7 +35,6 @@ DataReductionProxyAuthRequestHandler::auth_token_invalidation_timestamp_ = 0; DataReductionProxyAuthRequestHandler::DataReductionProxyAuthRequestHandler( DataReductionProxySettings* settings) : settings_(settings) { - DCHECK(settings); } DataReductionProxyAuthRequestHandler::~DataReductionProxyAuthRequestHandler() { @@ -105,7 +104,7 @@ DataReductionProxyAuthRequestHandler::TryHandleAuthentication( bool DataReductionProxyAuthRequestHandler::IsAcceptableAuthChallenge( net::AuthChallengeInfo* auth_info) { - return settings_->IsAcceptableAuthChallenge(auth_info); + return DataReductionProxySettings::IsAcceptableAuthChallenge(auth_info); } base::string16 DataReductionProxyAuthRequestHandler::GetTokenForAuthChallenge( diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h b/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h index 92128d4..312eed2 100644 --- a/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h +++ b/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h @@ -8,8 +8,6 @@ #include "base/gtest_prod_util.h" #include "base/strings/string16.h" #include "base/time/time.h" -#include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h" - namespace net { class AuthChallengeInfo; diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler_unittest.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler_unittest.cc index 756fd96..ba30403 100644 --- a/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler_unittest.cc +++ b/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler_unittest.cc @@ -5,11 +5,9 @@ #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/utf_string_conversions.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 "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -32,9 +30,8 @@ class TestDataReductionProxyAuthRequestHandler : public DataReductionProxyAuthRequestHandler { public: TestDataReductionProxyAuthRequestHandler(int time_step_ms, - int64 initial_time_ms, - DataReductionProxySettings* settings) - : DataReductionProxyAuthRequestHandler(settings), + int64 initial_time_ms) + : DataReductionProxyAuthRequestHandler(NULL), time_step_ms_(time_step_ms), now_(base::TimeTicks() + base::TimeDelta::FromMilliseconds(initial_time_ms)) {} @@ -66,16 +63,6 @@ class TestDataReductionProxyAuthRequestHandler class DataReductionProxyAuthRequestHandlerTest : public testing::Test { 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. void ExpectProceed( DataReductionProxyAuthRequestHandler::TryHandleResult result, @@ -110,8 +97,6 @@ class DataReductionProxyAuthRequestHandlerTest : public testing::Test { EXPECT_EQ(base::string16(), user); EXPECT_EQ(base::string16(), password); } - - scoped_ptr<DataReductionProxySettings> settings_; }; TEST_F(DataReductionProxyAuthRequestHandlerTest, @@ -122,8 +107,7 @@ TEST_F(DataReductionProxyAuthRequestHandlerTest, scoped_refptr<net::AuthChallengeInfo> auth_info(new net::AuthChallengeInfo); auth_info->realm = kTestRealm; auth_info->challenger = net::HostPortPair::FromString(kTestChallenger); - TestDataReductionProxyAuthRequestHandler handler( - 499, 3600001, settings_.get()); + TestDataReductionProxyAuthRequestHandler handler(499, 3600001); base::string16 user, password; DataReductionProxyAuthRequestHandler::TryHandleResult result = handler.TryHandleAuthentication(auth_info.get(), &user, &password); @@ -154,8 +138,7 @@ TEST_F(DataReductionProxyAuthRequestHandlerTest, Ignore) { scoped_refptr<net::AuthChallengeInfo> auth_info(new net::AuthChallengeInfo); auth_info->realm = kInvalidTestRealm; auth_info->challenger = net::HostPortPair::FromString(kTestChallenger); - TestDataReductionProxyAuthRequestHandler handler( - 100, 3600001, settings_.get()); + TestDataReductionProxyAuthRequestHandler handler(100, 3600001); base::string16 user, password; DataReductionProxyAuthRequestHandler::TryHandleResult result = handler.TryHandleAuthentication(auth_info.get(), &user, &password); diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_config_service.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_config_service.cc index 921a2e4..84b2e56 100644 --- a/components/data_reduction_proxy/browser/data_reduction_proxy_config_service.cc +++ b/components/data_reduction_proxy/browser/data_reduction_proxy_config_service.cc @@ -130,8 +130,7 @@ void DataReductionProxyConfigTracker::Enable( bool primary_restricted, bool fallback_restricted, const std::string& primary_origin, - const std::string& fallback_origin, - const std::string& ssl_origin) { + const std::string& fallback_origin) { std::vector<std::string> proxies; if (!primary_restricted) { @@ -152,14 +151,9 @@ void DataReductionProxyConfigTracker::Enable( 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; - config.proxy_rules().ParseFromString(server); + config.proxy_rules().ParseFromString( + "http=" + JoinString(proxies, ",") + ",direct://;"); config.proxy_rules().bypass_rules.ParseFromString( JoinString(bypass_rules_, ", ")); UpdateProxyConfigOnIOThread(true, config); diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_config_service.h b/components/data_reduction_proxy/browser/data_reduction_proxy_config_service.h index 75addad..28e80e1 100644 --- a/components/data_reduction_proxy/browser/data_reduction_proxy_config_service.h +++ b/components/data_reduction_proxy/browser/data_reduction_proxy_config_service.h @@ -98,8 +98,7 @@ class DataReductionProxyConfigTracker : public DataReductionProxyConfigurator { virtual void Enable(bool primary_restricted, bool fallback_restricted, const std::string& primary_origin, - const std::string& fallback_origin, - const std::string& ssl_origin) OVERRIDE; + const std::string& fallback_origin) OVERRIDE; virtual void Disable() OVERRIDE; virtual void AddHostPatternToBypass(const std::string& pattern) OVERRIDE; virtual void AddURLPatternToBypass(const std::string& pattern) OVERRIDE; diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_config_service_unittest.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_config_service_unittest.cc index d5624f0..657308a 100644 --- a/components/data_reduction_proxy/browser/data_reduction_proxy_config_service_unittest.cc +++ b/components/data_reduction_proxy/browser/data_reduction_proxy_config_service_unittest.cc @@ -207,8 +207,7 @@ TEST_F(DataReductionProxyConfigServiceTest, TrackerEnable) { tracker.Enable(false, false, "https://foo.com:443", - "http://bar.com:80", - ""); + "http://bar.com:80"); task_runner_->RunUntilIdle(); Mock::VerifyAndClearExpectations(&observer); @@ -232,8 +231,7 @@ TEST_F(DataReductionProxyConfigServiceTest, TrackerEnableRestricted) { tracker.Enable(true, false, "https://foo.com:443", - "http://bar.com:80", - ""); + "http://bar.com:80"); task_runner_->RunUntilIdle(); Mock::VerifyAndClearExpectations(&observer); diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_configurator.h b/components/data_reduction_proxy/browser/data_reduction_proxy_configurator.h index 58dcfab..02f8467 100644 --- a/components/data_reduction_proxy/browser/data_reduction_proxy_configurator.h +++ b/components/data_reduction_proxy/browser/data_reduction_proxy_configurator.h @@ -23,12 +23,10 @@ class DataReductionProxyConfigurator { // |primary_origin| may not be used. If |fallback_restricted|, the // |fallback_origin| may not be used. If both are restricted, then the // 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, bool fallback_restricted, const std::string& primary_origin, - const std::string& fallback_origin, - const std::string& ssl_origin) = 0; + const std::string& fallback_origin) = 0; // Disable the data reduction proxy. virtual void Disable() = 0; diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_metrics.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_metrics.cc index 7ad2809..3ecef8a 100644 --- a/components/data_reduction_proxy/browser/data_reduction_proxy_metrics.cc +++ b/components/data_reduction_proxy/browser/data_reduction_proxy_metrics.cc @@ -301,14 +301,8 @@ class DailyDataSavingUpdate { // the request is bypassed by more than one proxy, delay_seconds returns // shortest delay. bool IsBypassRequest(const net::URLRequest* request, int64* delay_seconds) { - // TODO(bengr): Add support for other data reduction proxy configurations. -#if defined(SPDY_PROXY_AUTH_ORIGIN) - DataReductionProxyParams params( - DataReductionProxyParams::kAllowed | - DataReductionProxyParams::kFallbackAllowed | - DataReductionProxyParams::kPromoAllowed); - DataReductionProxyParams::DataReductionProxyList proxies = - params.GetAllowedProxies(); + DataReductionProxySettings::DataReductionProxyList proxies = + DataReductionProxySettings::GetDataReductionProxies(); if (proxies.size() == 0) return false; @@ -341,9 +335,6 @@ bool IsBypassRequest(const net::URLRequest* request, int64* delay_seconds) { if (delay_seconds != NULL) *delay_seconds = shortest_delay; return true; -#else - return false; -#endif } } // namespace diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_params.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_params.cc deleted file mode 100644 index 491ce83..0000000 --- a/components/data_reduction_proxy/browser/data_reduction_proxy_params.cc +++ /dev/null @@ -1,281 +0,0 @@ -// 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 diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_params.h b/components/data_reduction_proxy/browser/data_reduction_proxy_params.h deleted file mode 100644 index 7eaf4a4..0000000 --- a/components/data_reduction_proxy/browser/data_reduction_proxy_params.h +++ /dev/null @@ -1,177 +0,0 @@ -// 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_ diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_params_unittest.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_params_unittest.cc deleted file mode 100644 index 37cb3bb..0000000 --- a/components/data_reduction_proxy/browser/data_reduction_proxy_params_unittest.cc +++ /dev/null @@ -1,295 +0,0 @@ -// 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/logging.h" -#include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { -// Test values to replacethe values specified in preprocessor defines. -static const char kDefaultKey[] = "test-key"; -static const char kDefaultDevOrigin[] = "https://dev.net:443/"; -static const char kDefaultOrigin[] = "https://origin.net:443/"; -static const char kDefaultFallbackOrigin[] = "http://fallback.net:80/"; -static const char kDefaultSSLOrigin[] = "http://ssl.net:1080/"; -static const char kDefaultAltOrigin[] = "https://alt.net:443/"; -static const char kDefaultAltFallbackOrigin[] = "http://altfallback.net:80/"; -static const char kDefaultProbeURL[] = "http://probe.net/"; - -static const char kFlagKey[] = "test-flag-key"; -static const char kFlagOrigin[] = "https://origin.org:443/"; -static const char kFlagFallbackOrigin[] = "http://fallback.org:80/"; -static const char kFlagSSLOrigin[] = "http://ssl.org:1080/"; -static const char kFlagAltOrigin[] = "https://alt.org:443/"; -static const char kFlagAltFallbackOrigin[] = "http://altfallback.org:80/"; -static const char kFlagProbeURL[] = "http://probe.org/"; - -// Used to emulate having constants defined by the preprocessor. -static const unsigned int HAS_NOTHING = 0x0; -static const unsigned int HAS_KEY = 0x1; -static const unsigned int HAS_DEV_ORIGIN = 0x2; -static const unsigned int HAS_ORIGIN = 0x4; -static const unsigned int HAS_FALLBACK_ORIGIN = 0x8; -static const unsigned int HAS_SSL_ORIGIN = 0x10; -static const unsigned int HAS_ALT_ORIGIN = 0x20; -static const unsigned int HAS_ALT_FALLBACK_ORIGIN = 0x40; -static const unsigned int HAS_PROBE_URL = 0x80; -static const unsigned int HAS_EVERYTHING = 0xff; -} // namespace - -namespace data_reduction_proxy { -class TestDataReductionProxyParams : public DataReductionProxyParams { - public: - - TestDataReductionProxyParams(int flags, - unsigned int has_definitions) - : DataReductionProxyParams(flags, - false), - has_definitions_(has_definitions) { - init_result_ = Init(flags & DataReductionProxyParams::kAllowed, - flags & DataReductionProxyParams::kFallbackAllowed, - flags & DataReductionProxyParams::kAlternativeAllowed); - } - - bool init_result() const { - return init_result_; - } - - protected: - virtual std::string GetDefaultKey() const OVERRIDE { - return GetDefinition(HAS_KEY, kDefaultKey); - } - - virtual std::string GetDefaultDevOrigin() const OVERRIDE { - return GetDefinition(HAS_DEV_ORIGIN, kDefaultDevOrigin); - } - - virtual std::string GetDefaultOrigin() const OVERRIDE { - return GetDefinition(HAS_ORIGIN, kDefaultOrigin); - } - - virtual std::string GetDefaultFallbackOrigin() const OVERRIDE { - return GetDefinition(HAS_FALLBACK_ORIGIN, kDefaultFallbackOrigin); - } - - virtual std::string GetDefaultSSLOrigin() const OVERRIDE { - return GetDefinition(HAS_SSL_ORIGIN, kDefaultSSLOrigin); - } - - virtual std::string GetDefaultAltOrigin() const OVERRIDE { - return GetDefinition(HAS_ALT_ORIGIN, kDefaultAltOrigin); - } - - virtual std::string GetDefaultAltFallbackOrigin() const OVERRIDE { - return GetDefinition(HAS_ALT_FALLBACK_ORIGIN, kDefaultAltFallbackOrigin); - } - - virtual std::string GetDefaultProbeURL() const OVERRIDE { - return GetDefinition(HAS_PROBE_URL, kDefaultProbeURL); - } - - private: - std::string GetDefinition(unsigned int has_def, - const std::string& definition) const { - return ((has_definitions_ & has_def) ? definition : std::string()); - } - - unsigned int has_definitions_; - bool init_result_; -}; - -class DataReductionProxyParamsTest : public testing::Test { - public: - void CheckParams(const TestDataReductionProxyParams& params, - bool expected_init_result, - bool expected_allowed, - bool expected_fallback_allowed, - bool expected_alternative_allowed, - bool expected_promo_allowed) { - EXPECT_EQ(expected_init_result, params.init_result()); - EXPECT_EQ(expected_allowed, params.allowed()); - EXPECT_EQ(expected_fallback_allowed, params.fallback_allowed()); - EXPECT_EQ(expected_alternative_allowed, params.alternative_allowed()); - EXPECT_EQ(expected_promo_allowed, params.promo_allowed()); - } - void CheckValues(const TestDataReductionProxyParams& params, - const std::string expected_key, - const std::string& expected_origin, - const std::string& expected_fallback_origin, - const std::string& expected_ssl_origin, - const std::string& expected_alt_origin, - const std::string& expected_alt_fallback_origin, - const std::string& expected_probe_url) { - EXPECT_EQ(expected_key, params.key()); - EXPECT_EQ(GURL(expected_origin), params.origin()); - EXPECT_EQ(GURL(expected_fallback_origin), params.fallback_origin()); - EXPECT_EQ(GURL(expected_ssl_origin), params.ssl_origin()); - EXPECT_EQ(GURL(expected_alt_origin), params.alt_origin()); - EXPECT_EQ(GURL(expected_alt_fallback_origin), params.alt_fallback_origin()); - EXPECT_EQ(GURL(expected_probe_url), params.probe_url()); - } -}; - -TEST_F(DataReductionProxyParamsTest, EverythingDefined) { - TestDataReductionProxyParams params( - DataReductionProxyParams::kAllowed | - DataReductionProxyParams::kFallbackAllowed | - DataReductionProxyParams::kPromoAllowed, HAS_EVERYTHING); - CheckParams(params, true, true, true, false, true); - CheckValues(params, - kDefaultKey, - kDefaultDevOrigin, - kDefaultFallbackOrigin, - kDefaultSSLOrigin, - kDefaultAltOrigin, - kDefaultAltFallbackOrigin, - kDefaultProbeURL); -} - -TEST_F(DataReductionProxyParamsTest, NoDevOrigin) { - TestDataReductionProxyParams params( - DataReductionProxyParams::kAllowed | - DataReductionProxyParams::kFallbackAllowed | - DataReductionProxyParams::kPromoAllowed, - HAS_EVERYTHING & ~HAS_DEV_ORIGIN); - CheckParams(params, true, true, true, false, true); - CheckValues(params, - kDefaultKey, - kDefaultOrigin, - kDefaultFallbackOrigin, - kDefaultSSLOrigin, - kDefaultAltOrigin, - kDefaultAltFallbackOrigin, - kDefaultProbeURL); -} - -TEST_F(DataReductionProxyParamsTest, Flags) { - CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kDataReductionProxyKey, kFlagKey); - CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kDataReductionProxy, kFlagOrigin); - CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kDataReductionProxyFallback, kFlagFallbackOrigin); - CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kDataReductionSSLProxy, kFlagSSLOrigin); - CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kDataReductionProxyAlt, kFlagAltOrigin); - CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kDataReductionProxyAltFallback, kFlagAltFallbackOrigin); - CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kDataReductionProxyProbeURL, kFlagProbeURL); - TestDataReductionProxyParams params( - DataReductionProxyParams::kAllowed | - DataReductionProxyParams::kFallbackAllowed | - DataReductionProxyParams::kAlternativeAllowed | - DataReductionProxyParams::kPromoAllowed, HAS_EVERYTHING); - CheckParams(params, true, true, true, true, true); - CheckValues(params, - kFlagKey, - kFlagOrigin, - kFlagFallbackOrigin, - kFlagSSLOrigin, - kFlagAltOrigin, - kFlagAltFallbackOrigin, - kFlagProbeURL); -} - -TEST_F(DataReductionProxyParamsTest, FlagsNoKey) { - CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kDataReductionProxy, kFlagOrigin); - CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kDataReductionProxyFallback, kFlagFallbackOrigin); - CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kDataReductionSSLProxy, kFlagSSLOrigin); - CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kDataReductionProxyAlt, kFlagAltOrigin); - CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kDataReductionProxyAltFallback, kFlagAltFallbackOrigin); - CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kDataReductionProxyProbeURL, kFlagProbeURL); - TestDataReductionProxyParams params( - DataReductionProxyParams::kAllowed | - DataReductionProxyParams::kFallbackAllowed | - DataReductionProxyParams::kAlternativeAllowed | - DataReductionProxyParams::kPromoAllowed, HAS_EVERYTHING); - EXPECT_FALSE(params.init_result()); -} - -TEST_F(DataReductionProxyParamsTest, InvalidConfigurations) { - const struct { - bool allowed; - bool fallback_allowed; - bool alternative_allowed; - bool promo_allowed; - unsigned int missing_definitions; - bool expected_result; - } tests[] = { - { true, true, true, true, HAS_NOTHING, true }, - { true, true, true, true, HAS_KEY, false }, - { true, true, true, true, HAS_DEV_ORIGIN, true }, - { true, true, true, true, HAS_ORIGIN, true }, - { true, true, true, true, HAS_ORIGIN | HAS_DEV_ORIGIN, false }, - { true, true, true, true, HAS_FALLBACK_ORIGIN, false }, - { true, true, true, true, HAS_SSL_ORIGIN, false }, - { true, true, true, true, HAS_ALT_ORIGIN, false }, - { true, true, true, true, HAS_ALT_FALLBACK_ORIGIN, false }, - { true, true, true, true, HAS_PROBE_URL, false }, - - { true, false, true, true, HAS_NOTHING, true }, - { true, false, true, true, HAS_KEY, false }, - { true, false, true, true, HAS_ORIGIN | HAS_DEV_ORIGIN, false }, - { true, false, true, true, HAS_FALLBACK_ORIGIN, true }, - { true, false, true, true, HAS_SSL_ORIGIN, false }, - { true, false, true, true, HAS_ALT_ORIGIN, false }, - { true, false, true, true, HAS_ALT_FALLBACK_ORIGIN, true }, - { true, false, true, true, HAS_PROBE_URL, false }, - - { true, true, false, true, HAS_NOTHING, true }, - { true, true, false, true, HAS_KEY, false }, - { true, true, false, true, HAS_ORIGIN | HAS_DEV_ORIGIN, false }, - { true, true, false, true, HAS_FALLBACK_ORIGIN, false }, - { true, true, false, true, HAS_SSL_ORIGIN, true }, - { true, true, false, true, HAS_ALT_ORIGIN, true }, - { true, true, false, true, HAS_ALT_FALLBACK_ORIGIN, true }, - { true, true, false, true, HAS_PROBE_URL, false }, - - { true, false, false, true, HAS_KEY, false }, - { true, false, false, true, HAS_ORIGIN | HAS_DEV_ORIGIN, false }, - { true, false, false, true, HAS_FALLBACK_ORIGIN, true }, - { true, false, false, true, HAS_SSL_ORIGIN, true }, - { true, false, false, true, HAS_ALT_ORIGIN, true }, - { true, false, false, true, HAS_ALT_FALLBACK_ORIGIN, true }, - { true, false, false, true, HAS_PROBE_URL, false }, - - { false, true, true, true, HAS_NOTHING, false }, - { false, true, true, true, HAS_KEY, false }, - { false, true, true, true, HAS_ORIGIN | HAS_DEV_ORIGIN, false }, - { false, true, true, true, HAS_FALLBACK_ORIGIN, false }, - { false, true, true, true, HAS_SSL_ORIGIN, false }, - { false, true, true, true, HAS_ALT_ORIGIN, false }, - { false, true, true, true, HAS_ALT_FALLBACK_ORIGIN, false }, - { false, true, true, true, HAS_PROBE_URL, false }, - }; - - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { - int flags = 0; - if (tests[i].allowed) - flags |= DataReductionProxyParams::kAllowed; - if (tests[i].fallback_allowed) - flags |= DataReductionProxyParams::kFallbackAllowed; - if (tests[i].alternative_allowed) - flags |= DataReductionProxyParams::kAlternativeAllowed; - if (tests[i].promo_allowed) - flags |= DataReductionProxyParams::kPromoAllowed; - TestDataReductionProxyParams params( - flags, - HAS_EVERYTHING & ~(tests[i].missing_definitions)); - EXPECT_EQ(tests[i].expected_result, params.init_result()); - } -} - -} // namespace data_reduction_proxy diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_prefs.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_prefs.cc index 2817024..8e59a3f 100644 --- a/components/data_reduction_proxy/browser/data_reduction_proxy_prefs.cc +++ b/components/data_reduction_proxy/browser/data_reduction_proxy_prefs.cc @@ -16,10 +16,6 @@ void RegisterSyncableProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { false, user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); registry->RegisterBooleanPref( - data_reduction_proxy::prefs::kDataReductionProxyAltEnabled, - false, - user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); - registry->RegisterBooleanPref( data_reduction_proxy::prefs::kDataReductionProxyWasEnabledBefore, false, user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc index 1f7cd2f..fe08eaa 100644 --- a/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc +++ b/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc @@ -16,7 +16,6 @@ #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.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/common/data_reduction_proxy_pref_names.h" #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h" #include "crypto/random.h" @@ -34,7 +33,7 @@ #include "net/url_request/url_request_status.h" #include "url/gurl.h" - +using base::FieldTrialList; using base::StringPrintf; namespace { @@ -46,6 +45,8 @@ const char kUMAProxyStartupStateHistogram[] = // Key of the UMA DataReductionProxy.ProbeURL histogram. const char kUMAProxyProbeURL[] = "DataReductionProxy.ProbeURL"; +const char kEnabled[] = "Enabled"; + // TODO(marq): Factor this string out into a constant here and in // http_auth_handler_spdyproxy. const char kAuthenticationRealmName[] = "SpdyProxy"; @@ -66,19 +67,51 @@ int64 GetInt64PrefValue(const base::ListValue& list_value, size_t index) { namespace data_reduction_proxy { -DataReductionProxySettings::DataReductionProxySettings( - DataReductionProxyParams* params) +bool DataReductionProxySettings::allowed_; +bool DataReductionProxySettings::promo_allowed_; + +// static +bool DataReductionProxySettings::IsProxyOriginSetOnCommandLine() { + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + return command_line.HasSwitch( + data_reduction_proxy::switches::kDataReductionProxy); +} + +// static +bool DataReductionProxySettings::IsProxyKeySetOnCommandLine() { + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + return command_line.HasSwitch( + data_reduction_proxy::switches::kEnableDataReductionProxy); +} + +// static +bool DataReductionProxySettings::IsIncludedInFieldTrialOrFlags() { + return (base::FieldTrialList::FindFullName( + "DataCompressionProxyRollout") == kEnabled || + IsProxyOriginSetOnCommandLine()); +} + +// static +void DataReductionProxySettings::SetAllowed(bool allowed) { + allowed_ = allowed; +} + +// static +void DataReductionProxySettings::SetPromoAllowed(bool promo_allowed) { + promo_allowed_ = promo_allowed; +} + +DataReductionProxySettings::DataReductionProxySettings() : restricted_by_carrier_(false), enabled_by_user_(false), prefs_(NULL), local_state_prefs_(NULL), - url_request_context_getter_(NULL) { - DCHECK(params); - params_.reset(params); + url_request_context_getter_(NULL), + fallback_allowed_(true) { } DataReductionProxySettings::~DataReductionProxySettings() { - if (params_->allowed()) + if (IsDataReductionProxyAllowed()) spdy_proxy_auth_enabled_.Destroy(); } @@ -89,12 +122,6 @@ void DataReductionProxySettings::InitPrefMembers() { GetOriginalProfilePrefs(), base::Bind(&DataReductionProxySettings::OnProxyEnabledPrefChange, base::Unretained(this))); - data_reduction_proxy_alternative_enabled_.Init( - prefs::kDataReductionProxyAltEnabled, - GetOriginalProfilePrefs(), - base::Bind( - &DataReductionProxySettings::OnProxyAlternativeEnabledPrefChange, - base::Unretained(this))); } void DataReductionProxySettings::InitDataReductionProxySettings( @@ -112,7 +139,7 @@ void DataReductionProxySettings::InitDataReductionProxySettings( RecordDataReductionInit(); // Disable the proxy if it is not allowed to be used. - if (!params_->allowed()) + if (!IsDataReductionProxyAllowed()) return; AddDefaultProxyBypassRules(); @@ -126,52 +153,49 @@ void DataReductionProxySettings::InitDataReductionProxySettings( PrefService* prefs, PrefService* local_state_prefs, net::URLRequestContextGetter* url_request_context_getter, - scoped_ptr<DataReductionProxyConfigurator> configurator) { + scoped_ptr<DataReductionProxyConfigurator> config) { InitDataReductionProxySettings(prefs, local_state_prefs, url_request_context_getter); - SetProxyConfigurator(configurator.Pass()); + SetProxyConfigurator(config.Pass()); } void DataReductionProxySettings::SetProxyConfigurator( scoped_ptr<DataReductionProxyConfigurator> configurator) { DCHECK(configurator); - configurator_ = configurator.Pass(); + config_ = configurator.Pass(); } // static void DataReductionProxySettings::InitDataReductionProxySession( net::HttpNetworkSession* session, - const DataReductionProxyParams* params) { -// This is a no-op unless the authentication parameters are compiled in. -// (even though values for them may be specified on the command line). -// Authentication will still work if the command line parameters are used, -// however there will be a round-trip overhead for each challenge/response -// (typically once per session). -// TODO(bengr):Pass a configuration struct into DataReductionProxyConfigurator's -// constructor. The struct would carry everything in the preprocessor flags. + const std::string& key) { + // This is a no-op unless the key is set. (even though values for them may be + // specified on the command line). Authentication will still work if the + // command line parameters are used, however there will be a round-trip + // overhead for each challenge/response (typically once per session). + // TODO(bengr):Pass a configuration struct into + // DataReductionProxyConfigurator's constructor. + if (key.empty()) + return; DCHECK(session); net::HttpAuthCache* auth_cache = session->http_auth_cache(); DCHECK(auth_cache); - InitDataReductionAuthentication(auth_cache, params); + InitDataReductionAuthentication(auth_cache, key); } // static void DataReductionProxySettings::InitDataReductionAuthentication( net::HttpAuthCache* auth_cache, - const DataReductionProxyParams* params) { + const std::string& key) { DCHECK(auth_cache); - DCHECK(params); int64 timestamp = (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds() / 1000; - DataReductionProxyParams::DataReductionProxyList proxies = - params->GetAllowedProxies(); - for (DataReductionProxyParams::DataReductionProxyList::iterator it = - proxies.begin(); - it != proxies.end(); ++it) { + DataReductionProxyList proxies = GetDataReductionProxies(); + for (DataReductionProxyList::iterator it = proxies.begin(); + it != proxies.end(); ++it) { GURL auth_origin = (*it).GetOrigin(); - int32 rand[3]; crypto::RandBytes(rand, 3 * sizeof(rand[0])); @@ -186,7 +210,7 @@ void DataReductionProxySettings::InitDataReductionAuthentication( rand[0], rand[1], rand[2]); - base::string16 password = AuthHashForSalt(timestamp, params->key()); + base::string16 password = AuthHashForSalt(timestamp, key); DVLOG(1) << "origin: [" << auth_origin << "] realm: [" << realm << "] challenge: [" << challenge << "] password: [" << password << "]"; @@ -203,6 +227,65 @@ void DataReductionProxySettings::InitDataReductionAuthentication( } } +// TODO(bengr): Use a configuration struct to carry field trial state as well. +// static +bool DataReductionProxySettings::IsDataReductionProxyAllowed() { + return allowed_; +} + +// static +bool DataReductionProxySettings::IsDataReductionProxyPromoAllowed() { + return IsProxyOriginSetOnCommandLine() || + (IsDataReductionProxyAllowed() && promo_allowed_); +} + +// static +bool DataReductionProxySettings::IsPreconnectHintingAllowed() { + if (!IsDataReductionProxyAllowed()) + return false; + return FieldTrialList::FindFullName("DataCompressionProxyPreconnectHints") == + kEnabled; +} + +// static +std::string DataReductionProxySettings::GetDataReductionProxyOrigin() { + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + if (command_line.HasSwitch(switches::kDataReductionProxyDev)) + return command_line.GetSwitchValueASCII(switches::kDataReductionProxyDev); + if (command_line.HasSwitch(switches::kDataReductionProxy)) + return command_line.GetSwitchValueASCII(switches::kDataReductionProxy); +#if defined(DATA_REDUCTION_DEV_HOST) + if (FieldTrialList::FindFullName("DataCompressionProxyDevRollout") == + kEnabled) { + return DATA_REDUCTION_DEV_HOST; + } +#endif +#if defined(SPDY_PROXY_AUTH_ORIGIN) + return SPDY_PROXY_AUTH_ORIGIN; +#else + return std::string(); +#endif +} + +// static +std::string DataReductionProxySettings::GetDataReductionProxyFallback() { + // Regardless of what else is defined, only return a value if the main proxy + // origin is defined. + if (GetDataReductionProxyOrigin().empty()) + return std::string(); + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + if (command_line.HasSwitch(switches::kDataReductionProxyFallback)) { + return command_line.GetSwitchValueASCII( + switches::kDataReductionProxyFallback); + } +#if defined(DATA_REDUCTION_FALLBACK_HOST) + return DATA_REDUCTION_FALLBACK_HOST; +#else + return std::string(); +#endif +} + +// static bool DataReductionProxySettings::IsAcceptableAuthChallenge( net::AuthChallengeInfo* auth_info) { // Challenge realm must start with the authentication realm name. @@ -212,10 +295,8 @@ bool DataReductionProxySettings::IsAcceptableAuthChallenge( return false; // The challenger must be one of the configured proxies. - DataReductionProxyParams::DataReductionProxyList proxies = - params_->GetAllowedProxies(); - for (DataReductionProxyParams::DataReductionProxyList::iterator it = - proxies.begin(); + DataReductionProxyList proxies = GetDataReductionProxies(); + for (DataReductionProxyList::iterator it = proxies.begin(); it != proxies.end(); ++it) { net::HostPortPair origin_host = net::HostPortPair::FromURL(*it); if (origin_host.Equals(auth_info->challenger)) @@ -231,7 +312,7 @@ base::string16 DataReductionProxySettings::GetTokenForAuthChallenge( std::string realm_suffix = auth_info->realm.substr(strlen(kAuthenticationRealmName)); if (base::StringToInt64(realm_suffix, &salt)) { - return AuthHashForSalt(salt, params_->key()); + return AuthHashForSalt(salt, key_); } else { DVLOG(1) << "Unable to parse realm name " << auth_info->realm << "into an int for salting."; @@ -244,21 +325,36 @@ base::string16 DataReductionProxySettings::GetTokenForAuthChallenge( bool DataReductionProxySettings::IsDataReductionProxyEnabled() { return spdy_proxy_auth_enabled_.GetValue() || - DataReductionProxyParams::IsKeySetOnCommandLine(); -} - -bool DataReductionProxySettings::IsDataReductionProxyAlternativeEnabled() { - return data_reduction_proxy_alternative_enabled_.GetValue(); + IsProxyKeySetOnCommandLine(); } bool DataReductionProxySettings::IsDataReductionProxyManaged() { return spdy_proxy_auth_enabled_.IsManaged(); } +// static +DataReductionProxySettings::DataReductionProxyList +DataReductionProxySettings::GetDataReductionProxies() { + DataReductionProxyList proxies; + std::string proxy = GetDataReductionProxyOrigin(); + std::string fallback = GetDataReductionProxyFallback(); + + if (!proxy.empty()) + proxies.push_back(GURL(proxy)); + + if (!fallback.empty()) { + // Sanity check: fallback isn't the only proxy. + DCHECK(!proxies.empty()); + proxies.push_back(GURL(fallback)); + } + + return proxies; +} + void DataReductionProxySettings::SetDataReductionProxyEnabled(bool enabled) { DCHECK(thread_checker_.CalledOnValidThread()); // Prevent configuring the proxy when it is not allowed to be used. - if (!params_->allowed()) + if (!IsDataReductionProxyAllowed()) return; if (spdy_proxy_auth_enabled_.GetValue() != enabled) { @@ -267,18 +363,6 @@ void DataReductionProxySettings::SetDataReductionProxyEnabled(bool enabled) { } } -void DataReductionProxySettings::SetDataReductionProxyAlternativeEnabled( - bool enabled) { - DCHECK(thread_checker_.CalledOnValidThread()); - // Prevent configuring the proxy when it is not allowed to be used. - if (!params_->alternative_allowed()) - return; - if (data_reduction_proxy_alternative_enabled_.GetValue() != enabled) { - data_reduction_proxy_alternative_enabled_.SetValue(enabled); - OnProxyAlternativeEnabledPrefChange(); - } -} - int64 DataReductionProxySettings::GetDataReductionLastUpdateTime() { DCHECK(thread_checker_.CalledOnValidThread()); PrefService* local_state = GetLocalStatePrefs(); @@ -323,7 +407,6 @@ void DataReductionProxySettings::OnURLFetchComplete( // The current network doesn't block the canary, so don't restrict the // proxy configurations. SetProxyConfigs(true /* enabled */, - IsDataReductionProxyAlternativeEnabled(), false /* restricted */, false /* at_startup */); RecordProbeURLFetchResult(SUCCEEDED_PROXY_ENABLED); @@ -340,7 +423,6 @@ void DataReductionProxySettings::OnURLFetchComplete( if (!restricted_by_carrier_) { // Restrict the proxy. SetProxyConfigs(true /* enabled */, - IsDataReductionProxyAlternativeEnabled(), true /* restricted */, false /* at_startup */); RecordProbeURLFetchResult(FAILED_PROXY_DISABLED); @@ -351,28 +433,33 @@ void DataReductionProxySettings::OnURLFetchComplete( restricted_by_carrier_ = true; } -PrefService* DataReductionProxySettings::GetOriginalProfilePrefs() { +void DataReductionProxySettings::OnIPAddressChanged() { DCHECK(thread_checker_.CalledOnValidThread()); - return prefs_; + if (enabled_by_user_) { + DCHECK(IsDataReductionProxyAllowed()); + ProbeWhetherDataReductionProxyIsAvailable(); + } } -PrefService* DataReductionProxySettings::GetLocalStatePrefs() { +void DataReductionProxySettings::OnProxyEnabledPrefChange() { DCHECK(thread_checker_.CalledOnValidThread()); - return local_state_prefs_; + if (!DataReductionProxySettings::IsDataReductionProxyAllowed()) + return; + MaybeActivateDataReductionProxy(false); } void DataReductionProxySettings::AddDefaultProxyBypassRules() { // localhost - configurator_->AddHostPatternToBypass("<local>"); + config_->AddHostPatternToBypass("<local>"); // RFC1918 private addresses. - configurator_->AddHostPatternToBypass("10.0.0.0/8"); - configurator_->AddHostPatternToBypass("172.16.0.0/12"); - configurator_->AddHostPatternToBypass("192.168.0.0/16"); + config_->AddHostPatternToBypass("10.0.0.0/8"); + config_->AddHostPatternToBypass("172.16.0.0/12"); + config_->AddHostPatternToBypass("192.168.0.0/16"); // RFC4193 private addresses. - configurator_->AddHostPatternToBypass("fc00::/7"); + config_->AddHostPatternToBypass("fc00::/7"); // IPV6 probe addresses. - configurator_->AddHostPatternToBypass("*-ds.metric.gstatic.com"); - configurator_->AddHostPatternToBypass("*-v4.metric.gstatic.com"); + config_->AddHostPatternToBypass("*-ds.metric.gstatic.com"); + config_->AddHostPatternToBypass("*-v4.metric.gstatic.com"); } void DataReductionProxySettings::LogProxyState( @@ -393,26 +480,14 @@ void DataReductionProxySettings::LogProxyState( << " " << (at_startup ? kAtStartup : kByUser); } -void DataReductionProxySettings::OnIPAddressChanged() { - DCHECK(thread_checker_.CalledOnValidThread()); - if (enabled_by_user_) { - DCHECK(params_->allowed()); - ProbeWhetherDataReductionProxyIsAvailable(); - } -} - -void DataReductionProxySettings::OnProxyEnabledPrefChange() { +PrefService* DataReductionProxySettings::GetOriginalProfilePrefs() { DCHECK(thread_checker_.CalledOnValidThread()); - if (!params_->allowed()) - return; - MaybeActivateDataReductionProxy(false); + return prefs_; } -void DataReductionProxySettings::OnProxyAlternativeEnabledPrefChange() { +PrefService* DataReductionProxySettings::GetLocalStatePrefs() { DCHECK(thread_checker_.CalledOnValidThread()); - if (!params_->alternative_allowed()) - return; - MaybeActivateDataReductionProxy(false); + return local_state_prefs_; } void DataReductionProxySettings::ResetDataReductionStatistics() { @@ -442,42 +517,34 @@ void DataReductionProxySettings::MaybeActivateDataReductionProxy( ResetDataReductionStatistics(); } - // Configure use of the data reduction proxy if it is enabled. - enabled_by_user_= IsDataReductionProxyEnabled(); - SetProxyConfigs(enabled_by_user_, - IsDataReductionProxyAlternativeEnabled(), - restricted_by_carrier_, - at_startup); + std::string proxy = GetDataReductionProxyOrigin(); + // Configure use of the data reduction proxy if it is enabled and the proxy + // origin is non-empty. + enabled_by_user_= IsDataReductionProxyEnabled() && !proxy.empty(); + SetProxyConfigs(enabled_by_user_, restricted_by_carrier_, at_startup); // Check if the proxy has been restricted explicitly by the carrier. if (enabled_by_user_) ProbeWhetherDataReductionProxyIsAvailable(); } -void DataReductionProxySettings::SetProxyConfigs(bool enabled, - bool alternative_enabled, - bool restricted, - bool at_startup) { +void DataReductionProxySettings::SetProxyConfigs( + bool enabled, bool restricted, bool at_startup) { DCHECK(thread_checker_.CalledOnValidThread()); + // If |restricted| is true and there is no defined fallback proxy. + // treat this as a disable. + std::string fallback = GetDataReductionProxyFallback(); + if (fallback.empty() && enabled && restricted) + enabled = false; + LogProxyState(enabled, restricted, at_startup); - // The alternative is only configured if the standard configuration is - // is enabled. if (enabled) { - if (alternative_enabled) { - configurator_->Enable(restricted, - !params_->fallback_allowed(), - 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()); - } + config_->Enable(restricted, + !fallback_allowed_, + GetDataReductionProxyOrigin(), + fallback); } else { - configurator_->Disable(); + config_->Disable(); } } @@ -485,7 +552,7 @@ void DataReductionProxySettings::SetProxyConfigs(bool enabled, void DataReductionProxySettings::RecordDataReductionInit() { DCHECK(thread_checker_.CalledOnValidThread()); ProxyStartupState state = PROXY_NOT_AVAILABLE; - if (params_->allowed()) { + if (IsDataReductionProxyAllowed()) { if (IsDataReductionProxyEnabled()) state = PROXY_ENABLED; else @@ -508,11 +575,6 @@ void DataReductionProxySettings::RecordStartupState(ProxyStartupState state) { PROXY_STARTUP_STATE_COUNT); } -void DataReductionProxySettings::ResetParamsForTest( - DataReductionProxyParams* params) { - params_.reset(params); -} - DataReductionProxySettings::ContentLengthList DataReductionProxySettings::GetDailyContentLengths(const char* pref_name) { DCHECK(thread_checker_.CalledOnValidThread()); @@ -524,7 +586,7 @@ DataReductionProxySettings::GetDailyContentLengths(const char* pref_name) { } } return content_lengths; -} + } void DataReductionProxySettings::GetContentLengths( unsigned int days, @@ -568,21 +630,55 @@ void DataReductionProxySettings::GetContentLengths( local_state->GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate); } +std::string DataReductionProxySettings::GetProxyCheckURL() { + if (!IsDataReductionProxyAllowed()) + return std::string(); + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + if (command_line.HasSwitch(switches::kDataReductionProxyProbeURL)) { + return command_line.GetSwitchValueASCII( + switches::kDataReductionProxyProbeURL); + } +#if defined(DATA_REDUCTION_PROXY_PROBE_URL) + return DATA_REDUCTION_PROXY_PROBE_URL; +#else + return std::string(); +#endif +} + // static base::string16 DataReductionProxySettings::AuthHashForSalt( int64 salt, const std::string& key) { + std::string active_key; + + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + if (command_line.HasSwitch(switches::kDataReductionProxy)) { + // If an origin is provided via a switch, then only consider the value + // that is provided by a switch. Do not use the preprocessor constant. + // Don't expose |key_| to a proxy passed in via the command line. + if (!command_line.HasSwitch(switches::kDataReductionProxyKey)) + return base::string16(); + active_key = command_line.GetSwitchValueASCII( + switches::kDataReductionProxyKey); + } else { + active_key = key; + } + DCHECK(!active_key.empty()); + std::string salted_key = base::StringPrintf("%lld%s%lld", static_cast<long long>(salt), - key.c_str(), + active_key.c_str(), static_cast<long long>(salt)); return base::UTF8ToUTF16(base::MD5String(salted_key)); } net::URLFetcher* DataReductionProxySettings::GetURLFetcher() { DCHECK(url_request_context_getter_); - net::URLFetcher* fetcher = net::URLFetcher::Create(params_->probe_url(), + std::string url = GetProxyCheckURL(); + if (url.empty()) + return NULL; + net::URLFetcher* fetcher = net::URLFetcher::Create(GURL(url), net::URLFetcher::GET, this); fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE | net::LOAD_BYPASS_PROXY); diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_settings.h b/components/data_reduction_proxy/browser/data_reduction_proxy_settings.h index cf0abe1..27bf158 100644 --- a/components/data_reduction_proxy/browser/data_reduction_proxy_settings.h +++ b/components/data_reduction_proxy/browser/data_reduction_proxy_settings.h @@ -14,7 +14,6 @@ #include "base/prefs/pref_member.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_params.h" #include "net/base/network_change_notifier.h" #include "net/url_request/url_fetcher_delegate.h" @@ -87,14 +86,34 @@ class DataReductionProxySettings public net::NetworkChangeNotifier::IPAddressObserver { public: 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(); - DataReductionProxySettings(DataReductionProxyParams* params); + // Returns true if this application instance is part of the data reduction + // 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(); - DataReductionProxyParams* params() const { - return params_.get(); + // Set and get the key to be used for data reduction proxy authentication. + void set_key(const std::string& key) { + key_ = key; + } + + const std::string& key() const { + return key_; } // Initializes the data reduction proxy with profile and local state prefs, @@ -115,22 +134,45 @@ class DataReductionProxySettings PrefService* prefs, PrefService* local_state_prefs, net::URLRequestContextGetter* url_request_context_getter, - scoped_ptr<DataReductionProxyConfigurator> configurator); + scoped_ptr<DataReductionProxyConfigurator> config); // Sets the logic the embedder uses to set the networking configuration that // causes traffic to be proxied. void SetProxyConfigurator( scoped_ptr<DataReductionProxyConfigurator> configurator); - // If proxy authentication is compiled in, pre-cache authentication - // keys for all configured proxies in |session|. - static void InitDataReductionProxySession( - net::HttpNetworkSession* session, - const DataReductionProxyParams* params); + // If proxy authentication is compiled in, pre-cache an authentication + // |key| for all configured proxies in |session|. + static void InitDataReductionProxySession(net::HttpNetworkSession* session, + const std::string& key); + + // 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 // a compatible, configured proxy. - bool IsAcceptableAuthChallenge(net::AuthChallengeInfo* auth_info); + static bool IsAcceptableAuthChallenge(net::AuthChallengeInfo* auth_info); // 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 @@ -140,9 +182,6 @@ class DataReductionProxySettings // Returns true if the proxy is enabled. bool IsDataReductionProxyEnabled(); - // Returns true if the alternative proxy is enabled. - bool IsDataReductionProxyAlternativeEnabled(); - // Returns true if the proxy is managed by an adminstrator's policy. bool IsDataReductionProxyManaged(); @@ -151,8 +190,15 @@ class DataReductionProxySettings // probe succeeds. void SetDataReductionProxyEnabled(bool enabled); - // Enables or disables the alternative data reduction proxy configuration. - void SetDataReductionProxyAlternativeEnabled(bool enabled); + // If |allowed|, the fallback proxy will be included in the proxy + // configuration. + 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 // daily original and received content lengths. @@ -186,17 +232,13 @@ class DataReductionProxySettings ContentLengthList GetDailyContentLengths(const char* pref_name); // Sets the proxy configs, enabling or disabling the proxy according to - // the value of |enabled| and |alternative_enabled|. Use the alternative - // configuration only if |enabled| and |alternative_enabled| are true. If - // |restricted| is true, only enable the fallback proxy. |at_startup| is true - // when this method is called from InitDataReductionProxySettings. - virtual void SetProxyConfigs(bool enabled, - bool alternative_enabled, - bool restricted, - bool at_startup); - - // Metrics method. Subclasses should override if they wish to provide - // alternatives. + // the value of |enabled|. If |restricted| is true, only enable the fallback + // proxy. |at_startup| is true when this method is called from + // InitDataReductionProxySettings. + virtual void SetProxyConfigs(bool enabled, bool restricted, bool at_startup); + + // Metrics methods. Subclasses should override if they wish to provide + // alternate methods. virtual void RecordDataReductionInit(); virtual void AddDefaultProxyBypassRules(); @@ -211,13 +253,10 @@ class DataReductionProxySettings virtual void RecordStartupState( data_reduction_proxy::ProxyStartupState state); - DataReductionProxyConfigurator* configurator() { - return configurator_.get(); + DataReductionProxyConfigurator* config() { + return config_.get(); } - // Reset params for tests. - void ResetParamsForTest(DataReductionProxyParams* params); - private: friend class DataReductionProxySettingsTestBase; friend class DataReductionProxySettingsTest; @@ -249,20 +288,16 @@ class DataReductionProxySettings TestBypassList); FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, CheckInitMetricsWhenNotAllowed); - FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest, - TestSetProxyConfigs); // NetworkChangeNotifier::IPAddressObserver: virtual void OnIPAddressChanged() OVERRIDE; // Underlying implementation of InitDataReductionProxySession(), factored // out to be testable without creating a full HttpNetworkSession. - static void InitDataReductionAuthentication( - net::HttpAuthCache* auth_cache, - const DataReductionProxyParams* params); + static void InitDataReductionAuthentication(net::HttpAuthCache* auth_cache, + const std::string& key); void OnProxyEnabledPrefChange(); - void OnProxyAlternativeEnabledPrefChange(); void ResetDataReductionStatistics(); @@ -272,12 +307,15 @@ class DataReductionProxySettings // the proxy, if enabled. Otherwise enables the proxy if disabled by a probe // failure. void ProbeWhetherDataReductionProxyIsAvailable(); + std::string GetProxyCheckURL(); // 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 // 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_; bool restricted_by_carrier_; @@ -285,18 +323,17 @@ class DataReductionProxySettings scoped_ptr<net::URLFetcher> fetcher_; BooleanPrefMember spdy_proxy_auth_enabled_; - BooleanPrefMember data_reduction_proxy_alternative_enabled_; PrefService* prefs_; PrefService* local_state_prefs_; net::URLRequestContextGetter* url_request_context_getter_; - scoped_ptr<DataReductionProxyConfigurator> configurator_; + scoped_ptr<DataReductionProxyConfigurator> config_; base::ThreadChecker thread_checker_; - scoped_ptr<DataReductionProxyParams> params_; + bool fallback_allowed_; DISALLOW_COPY_AND_ASSIGN(DataReductionProxySettings); }; diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.cc index a985683..d6475144 100644 --- a/components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.cc +++ b/components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.cc @@ -19,7 +19,7 @@ using testing::Return; namespace { 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 kProbeURLWithOKResponse[] = "http://ok.org/"; @@ -49,44 +49,20 @@ ProbeURLFetchResult FetchResult(bool enabled, bool success) { return FAILED_PROXY_ALREADY_DISABLED; } -TestDataReductionProxyConfig::TestDataReductionProxyConfig() - : enabled_(false), - restricted_(false), - fallback_restricted_(false) {} - void TestDataReductionProxyConfig::Enable( bool restricted, bool fallback_restricted, const std::string& primary_origin, - const std::string& fallback_origin, - const std::string& ssl_origin) { + const std::string& fallback_origin) { enabled_ = true; restricted_ = restricted; fallback_restricted_ = fallback_restricted; - origin_ = primary_origin; - fallback_origin_ = fallback_origin; - ssl_origin_ = ssl_origin; } void TestDataReductionProxyConfig::Disable() { enabled_ = false; 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() @@ -96,11 +72,18 @@ DataReductionProxySettingsTestBase::DataReductionProxySettingsTestBase() DataReductionProxySettingsTestBase::~DataReductionProxySettingsTestBase() {} void DataReductionProxySettingsTestBase::AddProxyToCommandLine() { - AddTestProxyToCommandLine(); + DataReductionProxySettings::SetAllowed(true); + CommandLine::ForCurrentProcess()->AppendSwitchASCII( + switches::kDataReductionProxy, kDataReductionProxy); + CommandLine::ForCurrentProcess()->AppendSwitchASCII( + switches::kDataReductionProxyFallback, kDataReductionProxyFallback); + CommandLine::ForCurrentProcess()->AppendSwitchASCII( + switches::kDataReductionProxyKey, kDataReductionProxyKey); } // testing::Test implementation: void DataReductionProxySettingsTestBase::SetUp() { + DataReductionProxySettings::SetAllowed(true); PrefRegistrySimple* registry = pref_service_.registry(); registry->RegisterListPref(prefs::kDailyHttpOriginalContentLength); registry->RegisterListPref(prefs::kDailyHttpReceivedContentLength); @@ -108,11 +91,9 @@ void DataReductionProxySettingsTestBase::SetUp() { 0L); registry->RegisterDictionaryPref(kProxy); registry->RegisterBooleanPref(prefs::kDataReductionProxyEnabled, false); - registry->RegisterBooleanPref(prefs::kDataReductionProxyAltEnabled, false); registry->RegisterBooleanPref(prefs::kDataReductionProxyWasEnabledBefore, false); - AddProxyToCommandLine(); - ResetSettings(true, true, false, true); + ResetSettings(); ListPrefUpdate original_update(&pref_service_, prefs::kDailyHttpOriginalContentLength); @@ -130,21 +111,9 @@ void DataReductionProxySettingsTestBase::SetUp() { } template <class C> -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; +void DataReductionProxySettingsTestBase::ResetSettings() { MockDataReductionProxySettings<C>* settings = - new MockDataReductionProxySettings<C>(flags); + new MockDataReductionProxySettings<C>(); EXPECT_CALL(*settings, GetOriginalProfilePrefs()) .Times(AnyNumber()) .WillRepeatedly(Return(&pref_service_)); @@ -154,13 +123,12 @@ void DataReductionProxySettingsTestBase::ResetSettings(bool allowed, EXPECT_CALL(*settings, GetURLFetcher()).Times(0); EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0); settings_.reset(settings); - settings_->configurator_.reset(new TestDataReductionProxyConfig()); + settings_->config_.reset(new TestDataReductionProxyConfig()); } // Explicitly generate required instantiations. template void -DataReductionProxySettingsTestBase::ResetSettings<DataReductionProxySettings>( - bool allowed, bool fallback_allowed, bool alt_allowed, bool promo_allowed); +DataReductionProxySettingsTestBase::ResetSettings<DataReductionProxySettings>(); template <class C> void DataReductionProxySettingsTestBase::SetProbeResult( @@ -202,8 +170,7 @@ void DataReductionProxySettingsTestBase::CheckProxyConfigs( bool expected_restricted, bool expected_fallback_restricted) { TestDataReductionProxyConfig* config = - static_cast<TestDataReductionProxyConfig*>( - settings_->configurator_.get()); + static_cast<TestDataReductionProxyConfig*>(settings_->config_.get()); ASSERT_EQ(expected_restricted, config->restricted_); ASSERT_EQ(expected_fallback_restricted, config->fallback_restricted_); ASSERT_EQ(expected_enabled, config->enabled_); @@ -275,6 +242,7 @@ void DataReductionProxySettingsTestBase::CheckOnPrefChange( void DataReductionProxySettingsTestBase::CheckInitDataReductionProxy( bool enabled_at_startup) { + AddProxyToCommandLine(); base::MessageLoopForUI loop; SetProbeResult(kProbeURLWithOKResponse, "OK", diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.h b/components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.h index eae8bae..f0cc648 100644 --- a/components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.h +++ b/components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.h @@ -21,13 +21,13 @@ namespace data_reduction_proxy { class TestDataReductionProxyConfig : public DataReductionProxyConfigurator { public: - TestDataReductionProxyConfig(); + TestDataReductionProxyConfig() + : enabled_(false), restricted_(false), fallback_restricted_(false) {} virtual ~TestDataReductionProxyConfig() {} virtual void Enable(bool restricted, bool fallback_restricted, const std::string& primary_origin, - const std::string& fallback_origin, - const std::string& ssl_origin) OVERRIDE; + const std::string& fallback_origin) OVERRIDE; virtual void Disable() OVERRIDE; virtual void AddHostPatternToBypass(const std::string& pattern) OVERRIDE {} virtual void AddURLPatternToBypass(const std::string& pattern) OVERRIDE {} @@ -44,23 +44,11 @@ class TestDataReductionProxyConfig : public DataReductionProxyConfigurator { // configuration has been disallowed. True if |Enable| is called with // |fallback_restricted| set to true. Defaults to false. bool fallback_restricted_; - - // The origins that are passed to |Enable|. - std::string origin_; - std::string fallback_origin_; - std::string ssl_origin_; }; template <class C> class MockDataReductionProxySettings : public C { 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(GetOriginalProfilePrefs, PrefService*()); MOCK_METHOD0(GetLocalStatePrefs, PrefService*()); @@ -72,38 +60,24 @@ class MockDataReductionProxySettings : public C { void(ProxyStartupState state)); // SetProxyConfigs should always call LogProxyState exactly once. - virtual void SetProxyConfigs(bool enabled, - bool alternative_enabled, - bool restricted, - bool at_startup) OVERRIDE { + virtual void SetProxyConfigs( + bool enabled, bool restricted, bool at_startup) OVERRIDE { EXPECT_CALL(*this, LogProxyState(enabled, restricted, at_startup)).Times(1); - C::SetProxyConfigs(enabled, alternative_enabled, restricted, at_startup); + C::SetProxyConfigs(enabled, restricted, at_startup); } }; class DataReductionProxySettingsTestBase : public testing::Test { public: - static void AddTestProxyToCommandLine(); - DataReductionProxySettingsTestBase(); - DataReductionProxySettingsTestBase(bool allowed, - bool fallback_allowed, - bool alt_allowed, - bool promo_allowed); virtual ~DataReductionProxySettingsTestBase(); void AddProxyToCommandLine(); virtual void SetUp() OVERRIDE; - template <class C> void ResetSettings(bool allowed, - 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 ResetSettings(); + virtual void ResetSettings() = 0; template <class C> void SetProbeResult( const std::string& test_url, @@ -148,12 +122,8 @@ class ConcreteDataReductionProxySettingsTest : public DataReductionProxySettingsTestBase { public: typedef MockDataReductionProxySettings<C> MockSettings; - virtual void ResetSettings(bool allowed, - bool fallback_allowed, - bool alt_allowed, - bool promo_allowed) OVERRIDE { - return DataReductionProxySettingsTestBase::ResetSettings<C>( - allowed, fallback_allowed, alt_allowed, promo_allowed); + virtual void ResetSettings() OVERRIDE { + return DataReductionProxySettingsTestBase::ResetSettings<C>(); } virtual void SetProbeResult(const std::string& test_url, diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_settings_unittest.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_settings_unittest.cc index fcb78fe..56778a7 100644 --- a/components/data_reduction_proxy/browser/data_reduction_proxy_settings_unittest.cc +++ b/components/data_reduction_proxy/browser/data_reduction_proxy_settings_unittest.cc @@ -8,7 +8,6 @@ #include "base/md5.h" #include "base/message_loop/message_loop.h" #include "base/strings/utf_string_conversions.h" -#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.h" #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names.h" #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h" @@ -24,9 +23,6 @@ const char kDataReductionProxy[] = "https://foo.com:443/"; const char kDataReductionProxyDev[] = "http://foo-dev.com:80"; const char kDataReductionProxyFallback[] = "http://bar.com:80"; const char kDataReductionProxyKey[] = "12345"; -const char kDataReductionProxyAlt[] = "https://alt.com:443/"; -const char kDataReductionProxyAltFallback[] = "http://alt2.com:80"; -const char kDataReductionProxySSL[] = "http://ssl.com:80"; const char kProbeURLWithOKResponse[] = "http://ok.org/"; const char kProbeURLWithBadResponse[] = "http://bad.org/"; @@ -43,17 +39,13 @@ class DataReductionProxySettingsTest TEST_F(DataReductionProxySettingsTest, TestAuthenticationInit) { + AddProxyToCommandLine(); net::HttpAuthCache cache; - DataReductionProxyParams drp_params( - DataReductionProxyParams::kAllowed | - DataReductionProxyParams::kFallbackAllowed | - DataReductionProxyParams::kPromoAllowed); - drp_params.set_key(kDataReductionProxyKey); DataReductionProxySettings::InitDataReductionAuthentication( - &cache, &drp_params); - DataReductionProxyParams::DataReductionProxyList proxies = - drp_params.GetAllowedProxies(); - for (DataReductionProxyParams::DataReductionProxyList::iterator it = + &cache, kDataReductionProxyKey); + DataReductionProxySettings::DataReductionProxyList proxies = + DataReductionProxySettings::GetDataReductionProxies(); + for (DataReductionProxySettings::DataReductionProxyList::iterator it = proxies.begin(); it != proxies.end(); ++it) { net::HttpAuthCache::Entry* entry = cache.LookupByPath(*it, std::string("/")); @@ -68,33 +60,53 @@ TEST_F(DataReductionProxySettingsTest, TestAuthenticationInit) { } TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyOrigin) { + AddProxyToCommandLine(); // SetUp() adds the origin to the command line, which should be returned here. std::string result = - settings_->params()->origin().spec(); - EXPECT_EQ(GURL(kDataReductionProxy), GURL(result)); + DataReductionProxySettings::GetDataReductionProxyOrigin(); + EXPECT_EQ(kDataReductionProxy, result); } TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyDevOrigin) { + AddProxyToCommandLine(); CommandLine::ForCurrentProcess()->AppendSwitchASCII( switches::kDataReductionProxyDev, kDataReductionProxyDev); - ResetSettings(true, true, false, true); std::string result = - settings_->params()->origin().spec(); - EXPECT_EQ(GURL(kDataReductionProxyDev), GURL(result)); + DataReductionProxySettings::GetDataReductionProxyOrigin(); + EXPECT_EQ(kDataReductionProxyDev, result); } - TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxies) { - DataReductionProxyParams drp_params( - DataReductionProxyParams::kAllowed | - DataReductionProxyParams::kFallbackAllowed | - DataReductionProxyParams::kPromoAllowed); - DataReductionProxyParams::DataReductionProxyList proxies = - drp_params.GetAllowedProxies(); - - unsigned int expected_proxy_size = 2u; + DataReductionProxySettings::DataReductionProxyList proxies = + DataReductionProxySettings::GetDataReductionProxies(); + + unsigned int expected_proxy_size = 0u; +#if defined(SPDY_PROXY_AUTH_ORIGIN) + ++expected_proxy_size; +#endif +#if defined(DATA_REDUCTION_FALLBACK_HOST) + ++expected_proxy_size; +#endif + EXPECT_EQ(expected_proxy_size, proxies.size()); + // Adding just the fallback on the command line shouldn't add a proxy unless + // there was already one compiled in. + CommandLine::ForCurrentProcess()->AppendSwitchASCII( + switches::kDataReductionProxyFallback, kDataReductionProxyFallback); + proxies = DataReductionProxySettings::GetDataReductionProxies(); + + // So: if there weren't any proxies before, there still won't be. + // If there were one or two, there will be two now. + expected_proxy_size = expected_proxy_size == 0u ? 0u : 2u; + + EXPECT_EQ(expected_proxy_size, proxies.size()); + + CommandLine::ForCurrentProcess()->AppendSwitchASCII( + switches::kDataReductionProxy, kDataReductionProxy); + proxies = DataReductionProxySettings::GetDataReductionProxies(); + EXPECT_EQ(2u, proxies.size()); + // Command line proxies have precedence, so even if there were other values // compiled in, these should be the ones in the list. EXPECT_EQ("foo.com", proxies[0].host()); @@ -104,6 +116,7 @@ TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxies) { } TEST_F(DataReductionProxySettingsTest, TestAuthHashGeneration) { + AddProxyToCommandLine(); std::string salt = "8675309"; // Jenny's number to test the hash generator. std::string salted_key = salt + kDataReductionProxyKey + salt; base::string16 expected_hash = base::UTF8ToUTF16(base::MD5String(salted_key)); @@ -112,55 +125,25 @@ TEST_F(DataReductionProxySettingsTest, TestAuthHashGeneration) { 8675309, kDataReductionProxyKey)); } -TEST_F(DataReductionProxySettingsTest, TestSetProxyConfigs) { - CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kDataReductionProxyAlt, kDataReductionProxyAlt); - CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kDataReductionProxyAltFallback, kDataReductionProxyAltFallback); +// Test that the auth key set by preprocessor directive is not used +// when an origin is set via a switch. This test only does anything useful in +// Chrome builds. +TEST_F(DataReductionProxySettingsTest, + TestAuthHashGenerationWithOriginSetViaSwitch) { CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kDataReductionSSLProxy, kDataReductionProxySSL); - ResetSettings(true, true, true, true); - TestDataReductionProxyConfig* config = - static_cast<TestDataReductionProxyConfig*>( - settings_->configurator()); - - settings_->SetProxyConfigs(true, true, false, false); - EXPECT_TRUE(config->enabled_); - EXPECT_TRUE(net::HostPortPair::FromString(kDataReductionProxyAlt).Equals( - net::HostPortPair::FromString(config->origin_))); - EXPECT_TRUE( - net::HostPortPair::FromString(kDataReductionProxyAltFallback).Equals( - net::HostPortPair::FromString(config->fallback_origin_))); - EXPECT_TRUE(net::HostPortPair::FromString(kDataReductionProxySSL).Equals( - net::HostPortPair::FromString(config->ssl_origin_))); - - settings_->SetProxyConfigs(true, false, false, false); - EXPECT_TRUE(config->enabled_); - EXPECT_TRUE(net::HostPortPair::FromString(kDataReductionProxy).Equals( - net::HostPortPair::FromString(config->origin_))); - EXPECT_TRUE(net::HostPortPair::FromString(kDataReductionProxyFallback).Equals( - net::HostPortPair::FromString(config->fallback_origin_))); - EXPECT_EQ("", config->ssl_origin_); - - settings_->SetProxyConfigs(false, true, false, false); - EXPECT_FALSE(config->enabled_); - EXPECT_EQ("", config->origin_); - EXPECT_EQ("", config->fallback_origin_); - EXPECT_EQ("", config->ssl_origin_); - - settings_->SetProxyConfigs(false, false, false, false); - EXPECT_FALSE(config->enabled_); - EXPECT_EQ("", config->origin_); - EXPECT_EQ("", config->fallback_origin_); - EXPECT_EQ("", config->ssl_origin_); + switches::kDataReductionProxy, kDataReductionProxy); + EXPECT_EQ(base::string16(), + DataReductionProxySettings::AuthHashForSalt( + 8675309, kDataReductionProxyKey)); } TEST_F(DataReductionProxySettingsTest, TestIsProxyEnabledOrManaged) { + AddProxyToCommandLine(); settings_->InitPrefMembers(); base::MessageLoopForUI loop; // The proxy is disabled initially. settings_->enabled_by_user_ = false; - settings_->SetProxyConfigs(false, false, false, false); + settings_->SetProxyConfigs(false, false, false); EXPECT_FALSE(settings_->IsDataReductionProxyEnabled()); EXPECT_FALSE(settings_->IsDataReductionProxyManaged()); @@ -175,6 +158,7 @@ TEST_F(DataReductionProxySettingsTest, TestIsProxyEnabledOrManaged) { } TEST_F(DataReductionProxySettingsTest, TestAcceptableChallenges) { + AddProxyToCommandLine(); typedef struct { std::string host; std::string realm; @@ -201,11 +185,13 @@ TEST_F(DataReductionProxySettingsTest, TestAcceptableChallenges) { auth_info->challenger = net::HostPortPair::FromString(tests[i].host); auth_info->realm = tests[i].realm; EXPECT_EQ(tests[i].expected_to_succeed, - settings_->IsAcceptableAuthChallenge(auth_info.get())); + DataReductionProxySettings::IsAcceptableAuthChallenge( + auth_info.get())); } } TEST_F(DataReductionProxySettingsTest, TestChallengeTokens) { + AddProxyToCommandLine(); typedef struct { std::string realm; bool expected_empty_token; @@ -295,15 +281,14 @@ TEST_F(DataReductionProxySettingsTest, TestContentLengths) { // TODO(marq): Add a test to verify that MaybeActivateDataReductionProxy // is called when the pref in |settings_| is enabled. TEST_F(DataReductionProxySettingsTest, TestMaybeActivateDataReductionProxy) { + AddProxyToCommandLine(); + // Initialize the pref member in |settings_| without the usual callback // so it won't trigger MaybeActivateDataReductionProxy when the pref value // is set. settings_->spdy_proxy_auth_enabled_.Init( prefs::kDataReductionProxyEnabled, settings_->GetOriginalProfilePrefs()); - settings_->data_reduction_proxy_alternative_enabled_.Init( - prefs::kDataReductionProxyAltEnabled, - settings_->GetOriginalProfilePrefs()); // TODO(bengr): Test enabling/disabling while a probe is outstanding. base::MessageLoopForUI loop; @@ -320,18 +305,16 @@ TEST_F(DataReductionProxySettingsTest, TestMaybeActivateDataReductionProxy) { } TEST_F(DataReductionProxySettingsTest, TestOnIPAddressChanged) { + AddProxyToCommandLine(); base::MessageLoopForUI loop; // The proxy is enabled initially. pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled, true); settings_->spdy_proxy_auth_enabled_.Init( prefs::kDataReductionProxyEnabled, settings_->GetOriginalProfilePrefs()); - settings_->data_reduction_proxy_alternative_enabled_.Init( - prefs::kDataReductionProxyAltEnabled, - settings_->GetOriginalProfilePrefs()); settings_->enabled_by_user_ = true; settings_->restricted_by_carrier_ = false; - settings_->SetProxyConfigs(true, false, false, true); + settings_->SetProxyConfigs(true, false, true); // IP address change triggers a probe that succeeds. Proxy remains // unrestricted. CheckProbeOnIPChange(kProbeURLWithOKResponse, "OK", true, false, false); @@ -344,11 +327,12 @@ TEST_F(DataReductionProxySettingsTest, TestOnIPAddressChanged) { } TEST_F(DataReductionProxySettingsTest, TestOnProxyEnabledPrefChange) { + AddProxyToCommandLine(); settings_->InitPrefMembers(); base::MessageLoopForUI loop; // The proxy is enabled initially. settings_->enabled_by_user_ = true; - settings_->SetProxyConfigs(true, false, false, true); + settings_->SetProxyConfigs(true, false, true); // The pref is disabled, so correspondingly should be the proxy. CheckOnPrefChange(false, false, false); // The pref is enabled, so correspondingly should be the proxy. @@ -400,12 +384,9 @@ TEST_F(DataReductionProxySettingsTest, CheckInitMetricsWhenNotAllowed) { // No call to |AddProxyToCommandLine()| was made, so the proxy feature // should be unavailable. base::MessageLoopForUI loop; - // Clear the command line. Setting flags can force the proxy to be allowed. - CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); - - ResetSettings(false, false, false, false); + DataReductionProxySettings::SetAllowed(false); + EXPECT_FALSE(DataReductionProxySettings::IsDataReductionProxyAllowed()); MockSettings* settings = static_cast<MockSettings*>(settings_.get()); - EXPECT_FALSE(settings->params()->allowed()); EXPECT_CALL(*settings, RecordStartupState(PROXY_NOT_AVAILABLE)); scoped_ptr<DataReductionProxyConfigurator> configurator( diff --git a/components/data_reduction_proxy/common/data_reduction_proxy_pref_names.cc b/components/data_reduction_proxy/common/data_reduction_proxy_pref_names.cc index 2e089cf..064caa6 100644 --- a/components/data_reduction_proxy/common/data_reduction_proxy_pref_names.cc +++ b/components/data_reduction_proxy/common/data_reduction_proxy_pref_names.cc @@ -72,9 +72,6 @@ const char kDataReductionProxy[] = "auth.spdyproxy.origin"; // A boolean specifying whether the data reduction proxy is 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 // before. const char kDataReductionProxyWasEnabledBefore[] = diff --git a/components/data_reduction_proxy/common/data_reduction_proxy_pref_names.h b/components/data_reduction_proxy/common/data_reduction_proxy_pref_names.h index 1d7de44..ed6379c 100644 --- a/components/data_reduction_proxy/common/data_reduction_proxy_pref_names.h +++ b/components/data_reduction_proxy/common/data_reduction_proxy_pref_names.h @@ -24,7 +24,6 @@ extern const char kDailyOriginalContentLengthViaDataReductionProxy[]; extern const char kDailyOriginalContentLengthWithDataReductionProxyEnabled[]; extern const char kDataReductionProxy[]; extern const char kDataReductionProxyEnabled[]; -extern const char kDataReductionProxyAltEnabled[]; extern const char kDataReductionProxyWasEnabledBefore[]; extern const char kHttpOriginalContentLength[]; extern const char kHttpReceivedContentLength[]; diff --git a/components/data_reduction_proxy/common/data_reduction_proxy_switches.cc b/components/data_reduction_proxy/common/data_reduction_proxy_switches.cc index 0ebe292..c7034f4 100644 --- a/components/data_reduction_proxy/common/data_reduction_proxy_switches.cc +++ b/components/data_reduction_proxy/common/data_reduction_proxy_switches.cc @@ -10,13 +10,6 @@ namespace switches { // The origin of the data reduction proxy. 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. const char kDataReductionProxyDev[] = "spdy-proxy-dev-auth-origin"; @@ -30,14 +23,8 @@ const char kDataReductionProxyKey[] = "spdy-proxy-auth-value"; // proxy. Note this canary does not go through the data reduction proxy. 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. const char kEnableDataReductionProxy[] = "enable-spdy-proxy-auth"; -// Enable the alternative data reduction proxy. -const char kEnableDataReductionProxyAlt[] = "enable-data-reduction-proxy-alt"; - } // namespace switches } // namespace data_reduction_proxy diff --git a/components/data_reduction_proxy/common/data_reduction_proxy_switches.h b/components/data_reduction_proxy/common/data_reduction_proxy_switches.h index da3b4e2..ed09a3c 100644 --- a/components/data_reduction_proxy/common/data_reduction_proxy_switches.h +++ b/components/data_reduction_proxy/common/data_reduction_proxy_switches.h @@ -12,15 +12,11 @@ namespace switches { // alongside the definition of their values in the .cc file. extern const char kDataReductionProxy[]; -extern const char kDataReductionProxyAlt[]; -extern const char kDataReductionProxyAltFallback[]; extern const char kDataReductionProxyDev[]; extern const char kDataReductionProxyFallback[]; extern const char kDataReductionProxyKey[]; extern const char kDataReductionProxyProbeURL[]; -extern const char kDataReductionSSLProxy[]; extern const char kEnableDataReductionProxy[]; -extern const char kEnableDataReductionProxyAlt[]; } // namespace switches } // namespace data_reduction_proxy |