summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjeremyim <jeremyim@chromium.org>2015-02-20 14:49:45 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-20 22:50:21 +0000
commitf917e431fd15598c0e28dbc9a39ac408272548a4 (patch)
tree801bab5a6f5267277f4a1a00231437517e82c8f4
parentdf75e1de1238c157580ec10d6f9478d7222b4d69 (diff)
downloadchromium_src-f917e431fd15598c0e28dbc9a39ac408272548a4.zip
chromium_src-f917e431fd15598c0e28dbc9a39ac408272548a4.tar.gz
chromium_src-f917e431fd15598c0e28dbc9a39ac408272548a4.tar.bz2
Class ownership changes:
- DRPIOData is a container for IOData lifetime objects, and constructed first. - DataSaverService is a container for Profile/UI based lifetime objects, and constructed second. It can take raw pointers to DRPIOData, since DataSaverService is destroyed before DRPIOData. - DRPIOData (and its classes) then fed a WeakPtr to the DataSaverService. - DataSaverService is (temporarily) owned by DRPSettings (primarily because DRPChromeSettings is the KeyedService) - this will swap in a future CL. - During KeyedService shutdown, the WeakPtr is invalidated. Removal of redundant functionality in the DRPSettings: - I/O thread related functionality (Canary check, IP address change) now lives in the Config class, with calls into DataSaverService to use the URLFetcher - the Settings class no longer is aware of Params, and instead uses the Config class for retrieving information - this results in Params construction moving from Settings -> DRP IO/Data - Certain information which is exposed to the UI (via the Settings class) is now cached after being retrieved from the Config class (for thread safety) BUG=452773 Review URL: https://codereview.chromium.org/893003002 Cr-Commit-Position: refs/heads/master@{#317432}
-rw-r--r--android_webview/browser/aw_browser_context.cc54
-rw-r--r--android_webview/browser/aw_browser_context.h6
-rw-r--r--chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_io_data.cc57
-rw-r--r--chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_io_data.h10
-rw-r--r--chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc46
-rw-r--r--chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h29
-rw-r--r--chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.cc29
-rw-r--r--chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h1
-rw-r--r--chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_unittest.cc4
-rw-r--r--chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.cc6
-rw-r--r--chrome/browser/net/spdyproxy/data_reduction_proxy_settings_unittest_android.cc61
-rw-r--r--chrome/browser/profiles/profile_impl_io_data.cc33
-rw-r--r--components/data_reduction_proxy.gypi2
-rw-r--r--components/data_reduction_proxy/content/browser/data_reduction_proxy_debug_resource_throttle.cc8
-rw-r--r--components/data_reduction_proxy/core/browser/BUILD.gn2
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_protocol_unittest.cc4
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc165
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h90
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.cc62
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h55
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc46
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc4
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc60
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h58
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data_unittest.cc32
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc23
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h12
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc27
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc85
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h106
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc428
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h198
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc215
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h98
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc302
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc80
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h34
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.cc9
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h12
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats_unittest.cc27
40 files changed, 967 insertions, 1613 deletions
diff --git a/android_webview/browser/aw_browser_context.cc b/android_webview/browser/aw_browser_context.cc
index 2d2e8ee..30f59cb 100644
--- a/android_webview/browser/aw_browser_context.cc
+++ b/android_webview/browser/aw_browser_context.cc
@@ -20,7 +20,9 @@
#include "components/autofill/core/common/autofill_pref_names.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "components/user_prefs/user_prefs.h"
#include "components/visitedlink/browser/visitedlink_master.h"
@@ -35,11 +37,6 @@
using base::FilePath;
using content::BrowserThread;
-namespace data_reduction_proxy {
-class DataReductionProxyConfigurator;
-class DataReductionProxyStatisticsPrefs;
-}
-
namespace android_webview {
namespace {
@@ -156,24 +153,22 @@ void AwBrowserContext::PreMainMessageLoopRun() {
cache_path, cookie_store_.get(),
make_scoped_ptr(CreateProxyConfigService()).Pass());
- data_reduction_proxy_settings_.reset(
- new data_reduction_proxy::DataReductionProxySettings(
- scoped_ptr<data_reduction_proxy::DataReductionProxyParams>(
- new data_reduction_proxy::DataReductionProxyParams(
- data_reduction_proxy::DataReductionProxyParams::kAllowed))
- .Pass()));
data_reduction_proxy_io_data_.reset(
new data_reduction_proxy::DataReductionProxyIOData(
data_reduction_proxy::Client::WEBVIEW_ANDROID,
- scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>(),
- data_reduction_proxy_settings_.get(),
+ data_reduction_proxy::DataReductionProxyParams::kAllowed,
url_request_context_getter_->GetNetLog(),
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
- BrowserThread::GetMessageLoopProxyForThread(
- BrowserThread::UI)));
- data_reduction_proxy_io_data_->Init();
- data_reduction_proxy_settings_->SetProxyConfigurator(
- data_reduction_proxy_io_data_->configurator());
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
+ false /* enable_quic */));
+ data_reduction_proxy_settings_.reset(
+ new data_reduction_proxy::DataReductionProxySettings());
+ data_reduction_proxy_service_.reset(
+ new data_reduction_proxy::DataReductionProxyService(
+ scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>(),
+ data_reduction_proxy_settings_.get(), GetAwURLRequestContext()));
+ data_reduction_proxy_io_data_->SetDataReductionProxyService(
+ data_reduction_proxy_service_->GetWeakPtr());
visitedlink_master_.reset(
new visitedlink::VisitedLinkMaster(this, this, false));
@@ -233,11 +228,6 @@ AwBrowserContext::GetDataReductionProxyIOData() {
return data_reduction_proxy_io_data_.get();
}
-data_reduction_proxy::DataReductionProxyConfigurator*
-AwBrowserContext::GetDataReductionProxyConfigurator() {
- return data_reduction_proxy_io_data_->configurator();
-}
-
AwURLRequestContextGetter* AwBrowserContext::GetAwURLRequestContext() {
return url_request_context_getter_.get();
}
@@ -276,12 +266,8 @@ void AwBrowserContext::CreateUserPrefServiceIfNecessary() {
if (data_reduction_proxy_settings_) {
data_reduction_proxy_settings_->InitDataReductionProxySettings(
- user_pref_service_.get(),
- scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>(),
- GetRequestContext(),
- GetAwURLRequestContext()->GetNetLog(),
- data_reduction_proxy_io_data_->event_store(),
- false /* disable QUIC for WebView */);
+ user_pref_service_.get(), data_reduction_proxy_io_data_.get(),
+ data_reduction_proxy_service_.Pass());
data_reduction_proxy_settings_->MaybeActivateDataReductionProxy(true);
SetDataReductionProxyEnabled(data_reduction_proxy_enabled_);
@@ -376,16 +362,18 @@ void AwBrowserContext::RebuildTable(
void AwBrowserContext::CreateDataReductionProxyStatisticsIfNecessary() {
DCHECK(user_pref_service_.get());
DCHECK(GetDataReductionProxySettings());
- if (GetDataReductionProxySettings()->statistics_prefs())
+ data_reduction_proxy::DataReductionProxyService*
+ data_reduction_proxy_service =
+ GetDataReductionProxySettings()->data_reduction_proxy_service();
+ DCHECK(data_reduction_proxy_service);
+ if (data_reduction_proxy_service->statistics_prefs())
return;
// We don't care about commit_delay for now. It is just a dummy value.
base::TimeDelta commit_delay = base::TimeDelta::FromMinutes(60);
- GetDataReductionProxySettings()->EnableCompressionStatisticsLogging(
+ data_reduction_proxy_service->EnableCompressionStatisticsLogging(
user_pref_service_.get(),
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
commit_delay);
- GetDataReductionProxyIOData()->SetDataReductionProxyStatisticsPrefs(
- GetDataReductionProxySettings()->statistics_prefs());
}
} // namespace android_webview
diff --git a/android_webview/browser/aw_browser_context.h b/android_webview/browser/aw_browser_context.h
index 755a838..1e32255 100644
--- a/android_webview/browser/aw_browser_context.h
+++ b/android_webview/browser/aw_browser_context.h
@@ -32,6 +32,7 @@ class WebContents;
namespace data_reduction_proxy {
class DataReductionProxyConfigurator;
class DataReductionProxyIOData;
+class DataReductionProxyService;
class DataReductionProxySettings;
}
@@ -94,9 +95,6 @@ class AwBrowserContext : public content::BrowserContext,
data_reduction_proxy::DataReductionProxyIOData*
GetDataReductionProxyIOData();
- data_reduction_proxy::DataReductionProxyConfigurator*
- GetDataReductionProxyConfigurator();
-
AwURLRequestContextGetter* GetAwURLRequestContext();
void CreateUserPrefServiceIfNecessary();
@@ -157,6 +155,8 @@ class AwBrowserContext : public content::BrowserContext,
scoped_ptr<AwSSLHostStateDelegate> ssl_host_state_delegate_;
scoped_ptr<data_reduction_proxy::DataReductionProxyIOData>
data_reduction_proxy_io_data_;
+ scoped_ptr<data_reduction_proxy::DataReductionProxyService>
+ data_reduction_proxy_service_;
DISALLOW_COPY_AND_ASSIGN(AwBrowserContext);
};
diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_io_data.cc b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_io_data.cc
index 6512a1f..e6e8ae2 100644
--- a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_io_data.cc
+++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_io_data.cc
@@ -4,64 +4,55 @@
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_io_data.h"
-#include "base/bind.h"
-#include "base/prefs/pref_service.h"
-#include "base/time/time.h"
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
-#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h"
-#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
+
+#if defined(OS_ANDROID)
+#include "base/android/build_info.h"
+#endif
#if defined(ENABLE_DATA_REDUCTION_PROXY_DEBUGGING)
#include "chrome/browser/browser_process.h"
#include "components/data_reduction_proxy/content/browser/content_data_reduction_proxy_debug_ui_service.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h"
#endif
namespace content {
class BrowserContext;
}
+using data_reduction_proxy::DataReductionProxyParams;
+
scoped_ptr<data_reduction_proxy::DataReductionProxyIOData>
CreateDataReductionProxyChromeIOData(
net::NetLog* net_log,
- content::BrowserContext* browser_context,
PrefService* prefs,
const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
- const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) {
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
+ bool enable_quic) {
DCHECK(net_log);
DCHECK(prefs);
- DCHECK(browser_context);
- DataReductionProxyChromeSettings* settings =
- DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
- browser_context);
-#if defined(OS_ANDROID) || defined(OS_IOS)
- // On mobile we write data reduction proxy prefs directly to the pref service.
- // On desktop we store data reduction proxy prefs in memory, writing to disk
- // every 60 minutes and on termination. Shutdown hooks must be added for
- // Android and iOS in order for non-zero delays to be supported.
- // (http://crbug.com/408264)
- base::TimeDelta commit_delay = base::TimeDelta();
-#else
- base::TimeDelta commit_delay = base::TimeDelta::FromMinutes(60);
+ int flags = DataReductionProxyParams::kAllowed |
+ DataReductionProxyParams::kFallbackAllowed |
+ DataReductionProxyParams::kAlternativeAllowed;
+ if (DataReductionProxyParams::IsIncludedInPromoFieldTrial())
+ flags |= DataReductionProxyParams::kPromoAllowed;
+ if (DataReductionProxyParams::IsIncludedInHoldbackFieldTrial())
+ flags |= DataReductionProxyParams::kHoldback;
+#if defined(OS_ANDROID)
+ if (DataReductionProxyParams::IsIncludedInAndroidOnePromoFieldTrial(
+ base::android::BuildInfo::GetInstance()->android_build_fp())) {
+ flags |= DataReductionProxyParams::kPromoAllowed;
+ }
#endif
- data_reduction_proxy::DataReductionProxyStatisticsPrefs*
- data_reduction_proxy_statistics_prefs =
- new data_reduction_proxy::DataReductionProxyStatisticsPrefs(
- prefs, ui_task_runner, commit_delay);
-
scoped_ptr<data_reduction_proxy::DataReductionProxyIOData>
data_reduction_proxy_io_data(
new data_reduction_proxy::DataReductionProxyIOData(
- DataReductionProxyChromeSettings::GetClient(),
- make_scoped_ptr(data_reduction_proxy_statistics_prefs),
- settings,
- net_log,
- io_task_runner,
- ui_task_runner));
+ DataReductionProxyChromeSettings::GetClient(), flags, net_log,
+ io_task_runner, ui_task_runner, enable_quic));
data_reduction_proxy_io_data->InitOnUIThread(prefs);
#if defined(ENABLE_DATA_REDUCTION_PROXY_DEBUGGING)
diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_io_data.h b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_io_data.h
index f60240c..d39c0a1 100644
--- a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_io_data.h
+++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_io_data.h
@@ -15,14 +15,8 @@ namespace base {
class SingleThreadTaskRunner;
}
-namespace content {
-class BrowserContext;
-}
-
namespace data_reduction_proxy {
-class DataReductionProxyConfigurator;
class DataReductionProxyIOData;
-class DataReductionProxySettings;
}
namespace net {
@@ -34,9 +28,9 @@ class NetLog;
scoped_ptr<data_reduction_proxy::DataReductionProxyIOData>
CreateDataReductionProxyChromeIOData(
net::NetLog* net_log,
- content::BrowserContext* browser_context,
PrefService* prefs,
const scoped_refptr<base::SingleThreadTaskRunner>& io_thread_runner,
- const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread_runner);
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread_runner,
+ bool enable_quic);
#endif // CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_CHROME_IO_DATA_H_
diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc
index d54fd26..5d63307 100644
--- a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc
+++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc
@@ -9,6 +9,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/prefs/pref_service.h"
#include "base/prefs/scoped_user_pref_update.h"
+#include "base/time/time.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
#include "chrome/browser/prefs/proxy_prefs.h"
@@ -17,6 +18,7 @@
#include "chrome/common/pref_names.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
@@ -67,28 +69,46 @@ void DataReductionProxyChromeSettings::MigrateDataReductionProxyOffProxyPrefs(
prefs->ClearPref(prefs::kProxy);
}
-DataReductionProxyChromeSettings::DataReductionProxyChromeSettings(
- scoped_ptr<DataReductionProxyParams> params)
- : DataReductionProxySettings(params.Pass()) {
+DataReductionProxyChromeSettings::DataReductionProxyChromeSettings()
+ : DataReductionProxySettings() {
}
DataReductionProxyChromeSettings::~DataReductionProxyChromeSettings() {
}
+void DataReductionProxyChromeSettings::Shutdown() {
+ data_reduction_proxy_service()->Shutdown();
+}
+
void DataReductionProxyChromeSettings::InitDataReductionProxySettings(
data_reduction_proxy::DataReductionProxyIOData* io_data,
PrefService* profile_prefs,
- PrefService* local_state_prefs,
- net::URLRequestContextGetter* request_context,
- bool enable_quic) {
- SetProxyConfigurator(io_data->configurator());
+ net::URLRequestContextGetter* request_context_getter,
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) {
+#if defined(OS_ANDROID) || defined(OS_IOS)
+ // On mobile we write Data Reduction Proxy prefs directly to the pref service.
+ // On desktop we store Data Reduction Proxy prefs in memory, writing to disk
+ // every 60 minutes and on termination. Shutdown hooks must be added for
+ // Android and iOS in order for non-zero delays to be supported.
+ // (http://crbug.com/408264)
+ base::TimeDelta commit_delay = base::TimeDelta();
+#else
+ base::TimeDelta commit_delay = base::TimeDelta::FromMinutes(60);
+#endif
+
+ scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>
+ statistics_prefs = make_scoped_ptr(
+ new data_reduction_proxy::DataReductionProxyStatisticsPrefs(
+ profile_prefs, ui_task_runner, commit_delay));
+ scoped_ptr<data_reduction_proxy::DataReductionProxyService>
+ service = make_scoped_ptr(
+ new data_reduction_proxy::DataReductionProxyService(
+ statistics_prefs.Pass(), this, request_context_getter));
DataReductionProxySettings::InitDataReductionProxySettings(
- profile_prefs,
- io_data->PassStatisticsPrefs(),
- request_context,
- io_data->net_log(),
- io_data->event_store(),
- enable_quic);
+ profile_prefs, io_data, service.Pass());
+ io_data->SetDataReductionProxyService(
+ data_reduction_proxy_service()->GetWeakPtr());
+
DataReductionProxySettings::SetOnDataReductionEnabledCallback(
base::Bind(&DataReductionProxyChromeSettings::RegisterSyntheticFieldTrial,
base::Unretained(this)));
diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h
index b3f1bdf..4f3b283 100644
--- a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h
+++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h
@@ -5,24 +5,21 @@
#ifndef CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_CHROME_SETTINGS_H_
#define CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_CHROME_SETTINGS_H_
-#include "base/memory/scoped_ptr.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
#include "components/keyed_service/core/keyed_service.h"
-namespace base {
class PrefService;
+
+namespace base {
+class SingleThreadTaskRunner;
}
namespace data_reduction_proxy {
-class DataReductionProxyConfigurator;
class DataReductionProxyIOData;
-class DataReductionProxyEventStore;
-class DataReductionProxyParams;
}
namespace net {
-class NetLog;
class URLRequestContextGetter;
}
@@ -34,23 +31,23 @@ class DataReductionProxyChromeSettings
: public data_reduction_proxy::DataReductionProxySettings,
public KeyedService {
public:
- // Constructs a settings object with the given configuration parameters.
- // Construction and destruction must happen on the UI thread.
- explicit DataReductionProxyChromeSettings(
- scoped_ptr<data_reduction_proxy::DataReductionProxyParams> params);
+ // Constructs a settings object. Construction and destruction must happen on
+ // the UI thread.
+ DataReductionProxyChromeSettings();
// Destructs the settings object.
~DataReductionProxyChromeSettings() override;
- // Initialize the settings object with the given configurator, prefs services,
- // and request context. Settings takes ownership of statistics prefs from
- // |io_data|.
+ // Overrides KeyedService::Shutdown:
+ void Shutdown() override;
+
+ // Initialize the settings object with the given io_data, prefs services,
+ // request context getter, and task runner.
void InitDataReductionProxySettings(
data_reduction_proxy::DataReductionProxyIOData* io_data,
PrefService* profile_prefs,
- PrefService* local_state_prefs,
- net::URLRequestContextGetter* request_context,
- bool enable_quic);
+ net::URLRequestContextGetter* request_context_getter,
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner);
// Gets the client type for the data reduction proxy.
static data_reduction_proxy::Client GetClient();
diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.cc b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.cc
index 90f2384..33fcb42 100644
--- a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.cc
+++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.cc
@@ -7,19 +7,8 @@
#include "base/bind.h"
#include "base/memory/singleton.h"
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h"
-#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
-#include "content/public/browser/browser_thread.h"
-
-#if defined(OS_ANDROID)
-#include "base/android/build_info.h"
-#endif
-
-using content::BrowserThread;
-using data_reduction_proxy::DataReductionProxyParams;
-using data_reduction_proxy::DataReductionProxyUsageStats;
// static
DataReductionProxyChromeSettings*
@@ -56,21 +45,5 @@ DataReductionProxyChromeSettingsFactory::
KeyedService* DataReductionProxyChromeSettingsFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
- int flags = DataReductionProxyParams::kAllowed |
- DataReductionProxyParams::kFallbackAllowed |
- DataReductionProxyParams::kAlternativeAllowed;
- if (DataReductionProxyParams::IsIncludedInPromoFieldTrial())
- flags |= DataReductionProxyParams::kPromoAllowed;
- if (DataReductionProxyParams::IsIncludedInHoldbackFieldTrial())
- flags |= DataReductionProxyParams::kHoldback;
-#if defined(OS_ANDROID)
- if (DataReductionProxyParams::IsIncludedInAndroidOnePromoFieldTrial(
- base::android::BuildInfo::GetInstance()->android_build_fp())) {
- flags |= DataReductionProxyParams::kPromoAllowed;
- }
-#endif
-
- return new DataReductionProxyChromeSettings(
- scoped_ptr<DataReductionProxyParams>(new DataReductionProxyParams(flags))
- .Pass());
+ return new DataReductionProxyChromeSettings();
}
diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h
index 05cb123f..a4a22bf 100644
--- a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h
+++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h
@@ -7,7 +7,6 @@
#include "base/compiler_specific.h"
#include "base/memory/singleton.h"
-#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
class DataReductionProxyChromeSettings;
diff --git a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_unittest.cc b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_unittest.cc
index 77ebed8..d36deb4 100644
--- a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_unittest.cc
+++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_unittest.cc
@@ -18,8 +18,8 @@ using data_reduction_proxy::DataReductionProxySettings;
class DataReductionProxyChromeSettingsTest : public testing::Test {
public:
void SetUp() override {
- drp_chrome_settings_ = make_scoped_ptr(new DataReductionProxyChromeSettings(
- make_scoped_ptr(new DataReductionProxyParams(0))));
+ drp_chrome_settings_ =
+ make_scoped_ptr(new DataReductionProxyChromeSettings());
dict_ = make_scoped_ptr(new DictionaryValue());
mock_pref_service_ = make_scoped_ptr(new TestingPrefServiceSimple());
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 ce94aae..8eaf2d2 100644
--- a/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.cc
+++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.cc
@@ -31,12 +31,12 @@ DataReductionProxySettingsAndroid::~DataReductionProxySettingsAndroid() {
jboolean DataReductionProxySettingsAndroid::IsDataReductionProxyAllowed(
JNIEnv* env, jobject obj) {
- return Settings()->params()->allowed();
+ return Settings()->Allowed();
}
jboolean DataReductionProxySettingsAndroid::IsDataReductionProxyPromoAllowed(
JNIEnv* env, jobject obj) {
- return Settings()->params()->promo_allowed();
+ return Settings()->PromoAllowed();
}
jboolean DataReductionProxySettingsAndroid::IsIncludedInAltFieldTrial(
@@ -47,7 +47,7 @@ jboolean DataReductionProxySettingsAndroid::IsIncludedInAltFieldTrial(
ScopedJavaLocalRef<jstring>
DataReductionProxySettingsAndroid::GetDataReductionProxyOrigin(
JNIEnv* env, jobject obj) {
- return ConvertUTF8ToJavaString(env, Settings()->params()->origin().ToURI());
+ return ConvertUTF8ToJavaString(env, Settings()->PrimaryOrigin());
}
jboolean DataReductionProxySettingsAndroid::IsDataReductionProxyEnabled(
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 478cd91..9c89795 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
@@ -18,8 +18,11 @@
#include "chrome/browser/prefs/proxy_prefs.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h"
#include "net/proxy/proxy_server.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -70,49 +73,19 @@ void data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings(
if (holdback)
flags |= DataReductionProxyParams::kHoldback;
MockDataReductionProxySettings<C>* settings =
- new MockDataReductionProxySettings<C>(flags);
+ new MockDataReductionProxySettings<C>();
+ settings->config_ = test_context_->config();
+ settings->data_reduction_proxy_service_ =
+ test_context_->CreateDataReductionProxyService();
+ test_context_->config()->ResetParamFlagsForTest(flags);
+ settings->UpdateConfigValues();
EXPECT_CALL(*settings, GetOriginalProfilePrefs())
.Times(AnyNumber())
- .WillRepeatedly(Return(&pref_service_));
+ .WillRepeatedly(Return(test_context_->pref_service()));
EXPECT_CALL(*settings, GetLocalStatePrefs())
.Times(AnyNumber())
- .WillRepeatedly(Return(&pref_service_));
- EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0);
- EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0);
+ .WillRepeatedly(Return(test_context_->pref_service()));
settings_.reset(settings);
- settings_->SetDataReductionProxyStatisticsPrefs(
- scoped_ptr<DataReductionProxyStatisticsPrefs>(
- new DataReductionProxyStatisticsPrefs(
- &pref_service_,
- scoped_refptr<base::TestSimpleTaskRunner>(
- new base::TestSimpleTaskRunner()),
- base::TimeDelta())));
-}
-
-template <class C>
-void data_reduction_proxy::DataReductionProxySettingsTestBase::SetProbeResult(
- const std::string& test_url,
- const std::string& response,
- ProbeURLFetchResult result,
- bool success,
- int expected_calls) {
- MockDataReductionProxySettings<C>* settings =
- static_cast<MockDataReductionProxySettings<C>*>(settings_.get());
- if (0 == expected_calls) {
- EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0);
- EXPECT_CALL(*settings, RecordProbeURLFetchResult(_)).Times(0);
- } else {
- EXPECT_CALL(*settings, RecordProbeURLFetchResult(result)).Times(1);
- EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck())
- .Times(expected_calls)
- .WillRepeatedly(Return(new net::FakeURLFetcher(
- GURL(test_url),
- settings,
- response,
- success ? net::HTTP_OK : net::HTTP_INTERNAL_SERVER_ERROR,
- success ? net::URLRequestStatus::SUCCESS :
- net::URLRequestStatus::FAILED)));
- }
}
template void
@@ -123,14 +96,6 @@ data_reduction_proxy::DataReductionProxySettingsTestBase::ResetSettings<
bool promo_allowed,
bool holdback);
-template void
-data_reduction_proxy::DataReductionProxySettingsTestBase::SetProbeResult<
- DataReductionProxyChromeSettings>(const std::string& test_url,
- const std::string& response,
- ProbeURLFetchResult result,
- bool success,
- int expected_calls);
-
class DataReductionProxySettingsAndroidTest
: public data_reduction_proxy::ConcreteDataReductionProxySettingsTest<
DataReductionProxyChromeSettings> {
@@ -166,7 +131,7 @@ TEST_F(DataReductionProxySettingsAndroidTest, TestGetDataReductionProxyOrigin) {
SettingsAndroid()->GetDataReductionProxyOrigin(env_, NULL);
ASSERT_TRUE(result.obj());
const base::android::JavaRef<jstring>& str_ref = result;
- EXPECT_EQ(expected_params_->DefaultOrigin(),
+ EXPECT_EQ(test_context_->config()->test_params()->DefaultOrigin(),
ConvertJavaStringToUTF8(str_ref));
}
diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc
index f6a04b2..4935556 100644
--- a/chrome/browser/profiles/profile_impl_io_data.cc
+++ b/chrome/browser/profiles/profile_impl_io_data.cc
@@ -38,13 +38,8 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h"
-#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
-#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
#include "components/domain_reliability/monitor.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/cookie_store_factory.h"
@@ -170,26 +165,24 @@ void ProfileImplIOData::Handle::Init(
if (io_data_->domain_reliability_monitor_)
io_data_->domain_reliability_monitor_->MoveToNetworkThread();
- ChromeNetLog* const net_log = g_browser_process->io_thread()->net_log();
-
- io_data_->set_data_reduction_proxy_io_data(
- CreateDataReductionProxyChromeIOData(
- net_log, profile_, profile_->GetPrefs(),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
- BrowserThread::GetMessageLoopProxyForThread(
- BrowserThread::UI)).Pass());
-
// TODO(tbansal): Move this to IO thread once the data reduction proxy
// params are unified into a single object.
bool enable_quic_for_data_reduction_proxy =
IOThread::ShouldEnableQuicForDataReductionProxy();
+ io_data_->set_data_reduction_proxy_io_data(
+ CreateDataReductionProxyChromeIOData(
+ g_browser_process->io_thread()->net_log(), profile_->GetPrefs(),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
+ enable_quic_for_data_reduction_proxy)
+ .Pass());
+
DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile_)->
- InitDataReductionProxySettings(io_data_->data_reduction_proxy_io_data(),
- profile_->GetPrefs(),
- g_browser_process->local_state(),
- profile_->GetRequestContext(),
- enable_quic_for_data_reduction_proxy);
+ InitDataReductionProxySettings(
+ io_data_->data_reduction_proxy_io_data(), profile_->GetPrefs(),
+ profile_->GetRequestContext(),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI));
}
content::ResourceContext*
@@ -465,8 +458,6 @@ void ProfileImplIOData::InitializeInternal(
main_context->set_net_log(io_thread->net_log());
- data_reduction_proxy_io_data()->Init();
-
network_delegate_ = data_reduction_proxy_io_data()->CreateNetworkDelegate(
chrome_network_delegate.Pass(), true).Pass();
diff --git a/components/data_reduction_proxy.gypi b/components/data_reduction_proxy.gypi
index 8cdef29..5184706 100644
--- a/components/data_reduction_proxy.gypi
+++ b/components/data_reduction_proxy.gypi
@@ -78,6 +78,8 @@
'data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h',
'data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc',
'data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h',
+ 'data_reduction_proxy/core/browser/data_reduction_proxy_service.cc',
+ 'data_reduction_proxy/core/browser/data_reduction_proxy_service.h',
'data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc',
'data_reduction_proxy/core/browser/data_reduction_proxy_settings.h',
'data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.cc',
diff --git a/components/data_reduction_proxy/content/browser/data_reduction_proxy_debug_resource_throttle.cc b/components/data_reduction_proxy/content/browser/data_reduction_proxy_debug_resource_throttle.cc
index 60d31bc..f7bdb96 100644
--- a/components/data_reduction_proxy/content/browser/data_reduction_proxy_debug_resource_throttle.cc
+++ b/components/data_reduction_proxy/content/browser/data_reduction_proxy_debug_resource_throttle.cc
@@ -4,6 +4,7 @@
#include "components/data_reduction_proxy/content/browser/data_reduction_proxy_debug_resource_throttle.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_debug_ui_service.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
@@ -30,13 +31,12 @@ DataReductionProxyDebugResourceThrottle::MaybeCreate(
if (io_data && io_data->IsEnabled() &&
data_reduction_proxy::DataReductionProxyParams::
WarnIfNoDataReductionProxy()) {
- DCHECK(io_data->params());
DCHECK(io_data->debug_ui_service());
DCHECK(request);
return scoped_ptr<DataReductionProxyDebugResourceThrottle>(
- new DataReductionProxyDebugResourceThrottle(request, resource_type,
- io_data->debug_ui_service(),
- io_data->params()));
+ new DataReductionProxyDebugResourceThrottle(
+ request, resource_type, io_data->debug_ui_service(),
+ io_data->config()->params()));
}
return nullptr;
}
diff --git a/components/data_reduction_proxy/core/browser/BUILD.gn b/components/data_reduction_proxy/core/browser/BUILD.gn
index 43f0802..d89bd38 100644
--- a/components/data_reduction_proxy/core/browser/BUILD.gn
+++ b/components/data_reduction_proxy/core/browser/BUILD.gn
@@ -25,6 +25,8 @@ static_library("browser") {
"data_reduction_proxy_prefs.h",
"data_reduction_proxy_request_options.cc",
"data_reduction_proxy_request_options.h",
+ "data_reduction_proxy_service.cc",
+ "data_reduction_proxy_service.h",
"data_reduction_proxy_settings.cc",
"data_reduction_proxy_settings.h",
"data_reduction_proxy_statistics_prefs.cc",
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_protocol_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_protocol_unittest.cc
index 8dac81b..8907c65 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_protocol_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_protocol_unittest.cc
@@ -13,7 +13,6 @@
#include "base/strings/stringprintf.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h"
@@ -119,7 +118,8 @@ class DataReductionProxyProtocolTest : public testing::Test {
// to requests.
context_->set_http_user_agent_settings(&http_user_agent_settings_);
usage_stats_.reset(new DataReductionProxyUsageStats(
- test_context_->config()->params(), test_context_->settings(),
+ test_context_->config()->params(),
+ test_context_->data_reduction_proxy_service()->GetWeakPtr(),
test_context_->task_runner()));
DataReductionProxyInterceptor* interceptor =
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc
index 573a235..2328d26 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc
@@ -11,6 +11,7 @@
#include "base/single_thread_task_runner.h"
#include "base/strings/string_util.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "net/base/load_flags.h"
@@ -47,47 +48,71 @@ void RecordNetworkChangeEvent(DataReductionProxyNetworkChangeEvent event) {
namespace data_reduction_proxy {
DataReductionProxyConfig::DataReductionProxyConfig(
- scoped_ptr<DataReductionProxyParams> params)
+ scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
+ scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
+ net::NetLog* net_log,
+ scoped_ptr<DataReductionProxyParams> params,
+ DataReductionProxyConfigurator* configurator,
+ DataReductionProxyEventStore* event_store)
: restricted_by_carrier_(false),
disabled_on_vpn_(false),
unreachable_(false),
enabled_by_user_(false),
alternative_enabled_by_user_(false),
- net_log_(nullptr),
- url_request_context_getter_(nullptr),
- configurator_(nullptr),
- event_store_(nullptr) {
- params_.reset(params.release());
+ params_(params.release()),
+ io_task_runner_(io_task_runner),
+ ui_task_runner_(ui_task_runner),
+ net_log_(net_log),
+ configurator_(configurator),
+ event_store_(event_store) {
+ DCHECK(io_task_runner);
+ DCHECK(ui_task_runner);
+ DCHECK(configurator);
+ DCHECK(event_store);
+ InitOnIOThread();
}
DataReductionProxyConfig::~DataReductionProxyConfig() {
net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
}
-void DataReductionProxyConfig::InitDataReductionProxyConfig(
- scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
- net::NetLog* net_log,
- net::URLRequestContextGetter* url_request_context_getter,
- DataReductionProxyConfigurator* configurator,
- DataReductionProxyEventStore* event_store) {
- DCHECK(io_task_runner);
- DCHECK(configurator);
- DCHECK(event_store);
- DCHECK(io_task_runner->BelongsToCurrentThread());
- io_task_runner_ = io_task_runner;
- net_log_ = net_log;
- url_request_context_getter_ = url_request_context_getter;
- configurator_ = configurator;
- event_store_ = event_store;
- net::NetworkChangeNotifier::AddIPAddressObserver(this);
+void DataReductionProxyConfig::SetDataReductionProxyService(
+ base::WeakPtr<DataReductionProxyService> data_reduction_proxy_service) {
+ data_reduction_proxy_service_ = data_reduction_proxy_service;
}
-void DataReductionProxyConfig::SetProxyConfigs(bool enabled,
- bool alternative_enabled,
- bool restricted,
- bool at_startup) {
- DCHECK(configurator_);
+void DataReductionProxyConfig::SetProxyPrefs(bool enabled,
+ bool alternative_enabled,
+ bool at_startup) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ io_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&DataReductionProxyConfig::SetProxyConfigOnIOThread,
+ base::Unretained(this), enabled,
+ alternative_enabled, at_startup));
+}
+
+void DataReductionProxyConfig::SetProxyConfigOnIOThread(
+ bool enabled, bool alternative_enabled, bool at_startup) {
+ enabled_by_user_ = enabled;
+ alternative_enabled_by_user_ = alternative_enabled;
+ UpdateConfigurator(enabled_by_user_, alternative_enabled_by_user_,
+ restricted_by_carrier_, at_startup);
+
+ // Check if the proxy has been restricted explicitly by the carrier.
+ if (enabled &&
+ !(alternative_enabled && !params()->alternative_fallback_allowed())) {
+ ui_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&DataReductionProxyConfig::StartProbe,
+ base::Unretained(this)));
+ }
+}
+void DataReductionProxyConfig::UpdateConfigurator(bool enabled,
+ bool alternative_enabled,
+ bool restricted,
+ bool at_startup) {
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
+ DCHECK(configurator_);
LogProxyState(enabled, restricted, at_startup);
// The alternative is only configured if the standard configuration is
// is enabled.
@@ -126,11 +151,17 @@ void DataReductionProxyConfig::LogProxyState(bool enabled,
<< (at_startup ? kAtStartup : kByUser);
}
-void DataReductionProxyConfig::OnURLFetchComplete(
- const net::URLFetcher* source) {
- DCHECK(source == fetcher_.get());
- net::URLRequestStatus status = source->GetStatus();
+void DataReductionProxyConfig::HandleProbeResponse(
+ const std::string& response, const net::URLRequestStatus& status) {
+ DCHECK(ui_task_runner_->BelongsToCurrentThread());
+ io_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&DataReductionProxyConfig::HandleProbeResponseOnIOThread,
+ base::Unretained(this), response, status));
+}
+void DataReductionProxyConfig::HandleProbeResponseOnIOThread(
+ const std::string& response, const net::URLRequestStatus& status) {
if (event_store_) {
event_store_->EndCanaryRequest(bound_net_log_, status.error());
}
@@ -147,9 +178,6 @@ void DataReductionProxyConfig::OnURLFetchComplete(
std::abs(status.error()));
}
- std::string response;
- source->GetResponseAsString(&response);
-
if ("OK" == response.substr(0, 2)) {
DVLOG(1) << "The data reduction proxy is unrestricted.";
@@ -159,8 +187,8 @@ void DataReductionProxyConfig::OnURLFetchComplete(
// the network operator had blocked the canary and restricted the user.
// The current network doesn't block the canary, so don't restrict the
// proxy configurations.
- SetProxyConfigs(true /* enabled */, false /* alternative_enabled */,
- false /* restricted */, false /* at_startup */);
+ UpdateConfigurator(true /* enabled */, false /* alternative_enabled */,
+ false /* restricted */, false /* at_startup */);
RecordProbeURLFetchResult(SUCCEEDED_PROXY_ENABLED);
} else {
RecordProbeURLFetchResult(SUCCEEDED_PROXY_ALREADY_ENABLED);
@@ -174,8 +202,8 @@ void DataReductionProxyConfig::OnURLFetchComplete(
if (enabled_by_user_) {
if (!restricted_by_carrier_) {
// Restrict the proxy.
- SetProxyConfigs(true /* enabled */, false /* alternative_enabled */,
- true /* restricted */, false /* at_startup */);
+ UpdateConfigurator(true /* enabled */, false /* alternative_enabled */,
+ true /* restricted */, false /* at_startup */);
RecordProbeURLFetchResult(FAILED_PROXY_DISABLED);
} else {
RecordProbeURLFetchResult(FAILED_PROXY_ALREADY_DISABLED);
@@ -185,6 +213,7 @@ void DataReductionProxyConfig::OnURLFetchComplete(
}
void DataReductionProxyConfig::OnIPAddressChanged() {
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
if (enabled_by_user_) {
DCHECK(params()->allowed());
RecordNetworkChangeEvent(IP_CHANGED);
@@ -194,10 +223,28 @@ void DataReductionProxyConfig::OnIPAddressChanged() {
!params()->alternative_fallback_allowed()) {
return;
}
- ProbeWhetherDataReductionProxyIsAvailable();
+
+ ui_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&DataReductionProxyConfig::StartProbe,
+ base::Unretained(this)));
}
}
+void DataReductionProxyConfig::InitOnIOThread() {
+ if (!io_task_runner_->BelongsToCurrentThread()) {
+ io_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&DataReductionProxyConfig::InitOnIOThread,
+ base::Unretained(this)));
+ return;
+ }
+
+ if (!params_->allowed())
+ return;
+
+ AddDefaultProxyBypassRules();
+ net::NetworkChangeNotifier::AddIPAddressObserver(this);
+}
+
void DataReductionProxyConfig::AddDefaultProxyBypassRules() {
// localhost
DCHECK(configurator_);
@@ -230,33 +277,19 @@ void DataReductionProxyConfig::RecordProbeURLFetchResult(
PROBE_URL_FETCH_RESULT_COUNT);
}
-net::URLFetcher* DataReductionProxyConfig::GetURLFetcherForProbe() {
- net::URLFetcher* fetcher =
- net::URLFetcher::Create(params_->probe_url(), net::URLFetcher::GET, this);
- fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE | net::LOAD_BYPASS_PROXY);
- DCHECK(url_request_context_getter_);
- fetcher->SetRequestContext(url_request_context_getter_);
- // Configure max retries to be at most kMaxRetries times for 5xx errors.
- static const int kMaxRetries = 5;
- fetcher->SetMaxRetriesOn5xx(kMaxRetries);
- fetcher->SetAutomaticallyRetryOnNetworkChanges(kMaxRetries);
- return fetcher;
-}
-
-void DataReductionProxyConfig::ProbeWhetherDataReductionProxyIsAvailable() {
- net::URLFetcher* fetcher = GetURLFetcherForProbe();
- if (!fetcher)
- return;
- fetcher_.reset(fetcher);
-
+void DataReductionProxyConfig::StartProbe() {
+ DCHECK(ui_task_runner_->BelongsToCurrentThread());
bound_net_log_ = net::BoundNetLog::Make(
net_log_, net::NetLog::SOURCE_DATA_REDUCTION_PROXY);
- if (event_store_) {
- event_store_->BeginCanaryRequest(bound_net_log_,
- fetcher_->GetOriginalURL());
+ if (data_reduction_proxy_service_) {
+ if (event_store_)
+ event_store_->BeginCanaryRequest(bound_net_log_, params_->probe_url());
+
+ data_reduction_proxy_service_->CheckProbeURL(
+ params_->probe_url(),
+ base::Bind(&DataReductionProxyConfig::HandleProbeResponse,
+ base::Unretained(this)));
}
-
- fetcher_->Start();
}
void DataReductionProxyConfig::GetNetworkList(
@@ -278,15 +311,15 @@ bool DataReductionProxyConfig::DisableIfVPN() {
interface_name.begin(),
interface_name.begin() + vpn_interface_name_prefix.size(),
vpn_interface_name_prefix.c_str())) {
- SetProxyConfigs(false, alternative_enabled_by_user_, false, false);
+ UpdateConfigurator(false, alternative_enabled_by_user_, false, false);
disabled_on_vpn_ = true;
RecordNetworkChangeEvent(DISABLED_ON_VPN);
return true;
}
}
if (disabled_on_vpn_) {
- SetProxyConfigs(enabled_by_user_, alternative_enabled_by_user_,
- restricted_by_carrier_, false);
+ UpdateConfigurator(enabled_by_user_, alternative_enabled_by_user_,
+ restricted_by_carrier_, false);
}
disabled_on_vpn_ = false;
return false;
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h
index 7427761..09cfd28 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h
@@ -13,7 +13,6 @@
#include "net/base/net_log.h"
#include "net/base/net_util.h"
#include "net/base/network_change_notifier.h"
-#include "net/url_request/url_fetcher_delegate.h"
namespace base {
class SingleThreadTaskRunner;
@@ -21,8 +20,7 @@ class SingleThreadTaskRunner;
namespace net {
class NetLog;
-class URLFetcher;
-class URLRequestContextGetter;
+class URLRequestStatus;
}
namespace data_reduction_proxy {
@@ -30,6 +28,7 @@ namespace data_reduction_proxy {
class DataReductionProxyConfigurator;
class DataReductionProxyEventStore;
class DataReductionProxyParams;
+class DataReductionProxyService;
// Values of the UMA DataReductionProxy.ProbeURL histogram.
// This enum must remain synchronized with
@@ -61,45 +60,43 @@ enum ProbeURLFetchResult {
// This object lives on the IO thread and all of its methods are expected to be
// called from there.
class DataReductionProxyConfig
- : public net::URLFetcherDelegate,
- public net::NetworkChangeNotifier::IPAddressObserver {
+ : public net::NetworkChangeNotifier::IPAddressObserver {
public:
- // DataReductionProxyConfig will take ownership of |params|.
- DataReductionProxyConfig(scoped_ptr<DataReductionProxyParams> params);
- ~DataReductionProxyConfig() override;
-
- // Initializes the Data Reduction Proxy config with an |io_task_runner|,
- // |net_log|, a |UrlRequestContextGetter| for canary probes, a
- // |DataReductionProxyConfigurator| for setting the proxy configuration, and a
- // |DataReductionProxyEventStore| for logging event changes. The caller must
- // ensure that all parameters remain alive for the lifetime of the
- // |DataReductionProxyConfig| instance.
- void InitDataReductionProxyConfig(
+ // The caller must ensure that all parameters remain alive for the lifetime
+ // of the |DataReductionProxyConfig| instance, with the exception of |params|
+ // which this instance will own.
+ DataReductionProxyConfig(
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
+ scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
net::NetLog* net_log,
- net::URLRequestContextGetter* url_request_context_getter,
+ scoped_ptr<DataReductionProxyParams> params,
DataReductionProxyConfigurator* configurator,
DataReductionProxyEventStore* event_store);
+ ~DataReductionProxyConfig() override;
// Returns the underlying |DataReductionProxyParams| instance.
DataReductionProxyParams* params() const {
return params_.get();
}
- protected:
- // Virtualized for testing. Returns a fetcher for the probe to check if OK for
- // the proxy to use TLS.
- virtual net::URLFetcher* GetURLFetcherForProbe();
+ void SetDataReductionProxyService(
+ base::WeakPtr<DataReductionProxyService> data_reduction_proxy_service);
+ // This method expects to run on the UI thread. It permits the data reduction
+ // proxy configuration to change based on changes initiated by the user.
+ virtual void SetProxyPrefs(bool enabled,
+ bool alternative_enabled,
+ bool at_startup);
+
+ protected:
// 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);
+ void SetProxyConfigOnIOThread(bool enabled,
+ bool alternative_enabled,
+ bool at_startup);
// Writes a warning to the log that is used in backend processing of
// customer feedback. Virtual so tests can mock it for verification.
@@ -116,27 +113,39 @@ class DataReductionProxyConfig
private:
friend class DataReductionProxyConfigTest;
+ friend class MockDataReductionProxyConfig;
friend class TestDataReductionProxyConfig;
FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest,
TestOnIPAddressChanged);
- FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, TestSetProxyConfigs);
FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest,
TestSetProxyConfigsHoldback);
- // net::URLFetcherDelegate:
- void OnURLFetchComplete(const net::URLFetcher* source) override;
-
// NetworkChangeNotifier::IPAddressObserver:
void OnIPAddressChanged() override;
+ // Performs initialization on the IO thread.
+ void InitOnIOThread();
+
+ // Updates the Data Reduction Proxy configurator with the current config.
+ virtual void UpdateConfigurator(bool enabled,
+ bool alternative_enabled,
+ bool restricted,
+ bool at_startup);
+
+ // Begins a probe request to determine if the Data Reduction Proxy is
+ // permitted to use the HTTPS proxy servers.
+ void StartProbe();
+
+ // Parses the probe responses and appropriately configures the Data Reduction
+ // Proxy rules.
+ virtual void HandleProbeResponse(const std::string& response,
+ const net::URLRequestStatus& status);
+ virtual void HandleProbeResponseOnIOThread(
+ const std::string& response, const net::URLRequestStatus& status);
+
// Adds the default proxy bypass rules for the Data Reduction Proxy.
void AddDefaultProxyBypassRules();
- // Requests the proxy probe URL, if one is set. If unable to do so, disables
- // the proxy, if enabled. Otherwise enables the proxy if disabled by a probe
- // failure.
- void ProbeWhetherDataReductionProxyIsAvailable();
-
// Disables use of the Data Reduction Proxy on VPNs. Returns true if the
// Data Reduction Proxy has been disabled.
bool DisableIfVPN();
@@ -154,6 +163,10 @@ class DataReductionProxyConfig
// IO thread.
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
+ // |ui_task_runner_| should be the task runner for running operations on the
+ // UI thread.
+ scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
+
// The caller must ensure that the |net_log_|, if set, outlives this instance.
// It is used to create new instances of |bound_net_log_| on canary
// requests. |bound_net_log_| permits the correlation of the begin and end
@@ -162,9 +175,6 @@ class DataReductionProxyConfig
net::NetLog* net_log_;
net::BoundNetLog bound_net_log_;
- // Used to retrieve a URLRequestContext for performing the canary check.
- net::URLRequestContextGetter* url_request_context_getter_;
-
// The caller must ensure that the |configurator_| outlives this instance.
DataReductionProxyConfigurator* configurator_;
@@ -173,8 +183,10 @@ class DataReductionProxyConfig
base::ThreadChecker thread_checker_;
- // The URLFetcher being used for the canary check.
- scoped_ptr<net::URLFetcher> fetcher_;
+ // A weak pointer to a |DataReductionProxyService| to perform probe requests.
+ // The weak pointer is required since the |DataReductionProxyService| is
+ // destroyed before this instance of the |DataReductionProxyConfig|.
+ base::WeakPtr<DataReductionProxyService> data_reduction_proxy_service_;
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyConfig);
};
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.cc
index 595edf1..7e6d12c 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.cc
@@ -10,23 +10,23 @@
#include "net/url_request/url_request_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
-namespace data_reduction_proxy {
+using testing::_;
-TestDataReductionProxyConfig::TestDataReductionProxyConfig()
- : TestDataReductionProxyConfig(DataReductionProxyParams::kAllowed |
- DataReductionProxyParams::kFallbackAllowed |
- DataReductionProxyParams::kPromoAllowed) {
-}
+namespace data_reduction_proxy {
-TestDataReductionProxyConfig::TestDataReductionProxyConfig(int flags)
+TestDataReductionProxyConfig::TestDataReductionProxyConfig(
+ int params_flags,
+ unsigned int params_definitions,
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner,
+ net::NetLog* net_log,
+ DataReductionProxyConfigurator* configurator,
+ DataReductionProxyEventStore* event_store)
: DataReductionProxyConfig(
- scoped_ptr<TestDataReductionProxyParams>(
- new TestDataReductionProxyParams(
- flags,
- TestDataReductionProxyParams::HAS_EVERYTHING &
- ~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
- ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN))
- .Pass()) {
+ task_runner, task_runner, net_log,
+ make_scoped_ptr(
+ new TestDataReductionProxyParams(params_flags, params_definitions))
+ .Pass(),
+ configurator, event_store) {
network_interfaces_.reset(new net::NetworkInterfaceList());
}
@@ -62,24 +62,38 @@ void TestDataReductionProxyConfig::SetStateForTest(
enabled_by_user_ = enabled_by_user;
alternative_enabled_by_user_ = alternative_enabled_by_user;
restricted_by_carrier_ = restricted_by_carrier;
- SetProxyConfigs(enabled_by_user_, alternative_enabled_by_user_,
- restricted_by_carrier_, at_startup);
+ UpdateConfigurator(enabled_by_user_, alternative_enabled_by_user_,
+ restricted_by_carrier_, at_startup);
}
-MockDataReductionProxyConfig::MockDataReductionProxyConfig(int flags)
- : TestDataReductionProxyConfig(flags) {
+MockDataReductionProxyConfig::MockDataReductionProxyConfig(
+ int params_flags,
+ unsigned int params_definitions,
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner,
+ net::NetLog* net_log,
+ DataReductionProxyConfigurator* configurator,
+ DataReductionProxyEventStore* event_store)
+ : TestDataReductionProxyConfig(
+ params_flags, params_definitions, task_runner, net_log, configurator,
+ event_store) {
}
MockDataReductionProxyConfig::~MockDataReductionProxyConfig() {
}
-void MockDataReductionProxyConfig::SetProxyConfigs(bool enabled,
- bool alternative_enabled,
- bool restricted,
- bool at_startup) {
+void MockDataReductionProxyConfig::UpdateConfigurator(bool enabled,
+ bool alternative_enabled,
+ bool restricted,
+ bool at_startup) {
EXPECT_CALL(*this, LogProxyState(enabled, restricted, at_startup)).Times(1);
- DataReductionProxyConfig::SetProxyConfigs(enabled, alternative_enabled,
- restricted, at_startup);
+ DataReductionProxyConfig::UpdateConfigurator(enabled, alternative_enabled,
+ restricted, at_startup);
+}
+
+void MockDataReductionProxyConfig::HandleProbeResponse(
+ const std::string& response,
+ const net::URLRequestStatus& status) {
+ DataReductionProxyConfig::HandleProbeResponse(response, status);
}
} // namespace data_reduction_proxy
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h
index a27ea2b..a15d529 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h
@@ -5,17 +5,24 @@
#ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_CONFIG_TEST_UTILS_H_
#define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_CONFIG_TEST_UTILS_H_
+#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h"
#include "net/base/net_util.h"
#include "testing/gmock/include/gmock/gmock.h"
+namespace base {
+class SingleThreadTaskRunner;
+}
+
namespace net {
-class URLFetcher;
+class NetLog;
}
namespace data_reduction_proxy {
+class DataReductionProxyConfigurator;
+class DataReductionProxyEventStore;
class TestDataReductionProxyParams;
// Test version of |DataReductionProxyConfig|, which uses an underlying
@@ -24,12 +31,14 @@ class TestDataReductionProxyParams;
// change the underlying state.
class TestDataReductionProxyConfig : public DataReductionProxyConfig {
public:
- // Creates a default |TestDataReductionProxyConfig| which uses the following
- // |DataReductionProxyParams| flags:
- // kAllowed | kFallbackAllowed | kPromoAllowed
- TestDataReductionProxyConfig();
- // Creates a |TestDataReductionProxyConfig| with the provided |flags|.
- TestDataReductionProxyConfig(int flags);
+ // Creates a |TestDataReductionProxyConfig| with the provided |params_flags|.
+ TestDataReductionProxyConfig(
+ int params_flags,
+ unsigned int params_definitions,
+ scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
+ net::NetLog* net_log,
+ DataReductionProxyConfigurator* configurator,
+ DataReductionProxyEventStore* event_store);
~TestDataReductionProxyConfig() override;
void GetNetworkList(net::NetworkInterfaceList* interfaces,
@@ -59,20 +68,32 @@ class TestDataReductionProxyConfig : public DataReductionProxyConfig {
// testing.
class MockDataReductionProxyConfig : public TestDataReductionProxyConfig {
public:
- // Creates a |MockDataReductionProxyConfig| with the provided |flags|.
- MockDataReductionProxyConfig(int flags);
- ~MockDataReductionProxyConfig() override;
+ // Creates a |MockDataReductionProxyConfig| with the provided |params_flags|.
+ MockDataReductionProxyConfig(
+ int params_flags,
+ unsigned int params_definitions,
+ scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
+ net::NetLog* net_log,
+ DataReductionProxyConfigurator* configurator,
+ DataReductionProxyEventStore* event_store);
+ ~MockDataReductionProxyConfig();
- MOCK_METHOD0(GetURLFetcherForProbe, net::URLFetcher*());
MOCK_METHOD1(RecordProbeURLFetchResult, void(ProbeURLFetchResult result));
MOCK_METHOD3(LogProxyState,
void(bool enabled, bool restricted, bool at_startup));
-
- // SetProxyConfigs should always call LogProxyState exactly once.
- void SetProxyConfigs(bool enabled,
- bool alternative_enabled,
- bool restricted,
- bool at_startup) override;
+ MOCK_METHOD3(SetProxyPrefs,
+ void(bool enabled, bool alternative_enabled, bool at_startup));
+
+ // UpdateConfigurator should always call LogProxyState exactly once.
+ void UpdateConfigurator(bool enabled,
+ bool alternative_enabled,
+ bool restricted,
+ bool at_startup) override;
+
+ // HandleProbeResponse should always call RecordProbeURLFetchResult exactly
+ // once.
+ void HandleProbeResponse(const std::string& response,
+ const net::URLRequestStatus& status) override;
};
} // namespace data_reduction_proxy
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
index cd8b74c..c6c5ab6 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
@@ -7,6 +7,7 @@
#include "base/command_line.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_test_utils.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h"
@@ -75,7 +76,6 @@ class DataReductionProxyConfigTest : public testing::Test {
if (holdback)
flags |= DataReductionProxyParams::kHoldback;
config()->ResetParamFlagsForTest(flags);
- EXPECT_CALL(*config(), GetURLFetcherForProbe()).Times(0);
EXPECT_CALL(*config(), LogProxyState(_, _, _)).Times(0);
}
@@ -85,17 +85,9 @@ class DataReductionProxyConfigTest : public testing::Test {
bool success,
int expected_calls) {
if (0 == expected_calls) {
- EXPECT_CALL(*config(), GetURLFetcherForProbe()).Times(0);
EXPECT_CALL(*config(), RecordProbeURLFetchResult(_)).Times(0);
} else {
EXPECT_CALL(*config(), RecordProbeURLFetchResult(result)).Times(1);
- EXPECT_CALL(*config(), GetURLFetcherForProbe())
- .Times(expected_calls)
- .WillRepeatedly(Return(new net::FakeURLFetcher(
- GURL(test_url), config(), response,
- success ? net::HTTP_OK : net::HTTP_INTERNAL_SERVER_ERROR,
- success ? net::URLRequestStatus::SUCCESS
- : net::URLRequestStatus::FAILED)));
}
}
@@ -108,6 +100,16 @@ class DataReductionProxyConfigTest : public testing::Test {
ASSERT_EQ(expected_enabled, configurator()->enabled());
}
+ class TestResponder {
+ public:
+ void ExecuteCallback(FetcherResponseCallback callback) {
+ callback.Run(response, status);
+ }
+
+ std::string response;
+ net::URLRequestStatus status;
+ };
+
void CheckProbeOnIPChange(const std::string& probe_url,
const std::string& response,
bool request_succeeded,
@@ -117,6 +119,16 @@ class DataReductionProxyConfigTest : public testing::Test {
FetchResult(!config()->restricted_by_carrier_,
request_succeeded && (response == "OK")),
request_succeeded, 1);
+ MockDataReductionProxyService* service =
+ test_context_->data_reduction_proxy_service();
+ TestResponder responder;
+ responder.response = response;
+ responder.status =
+ net::URLRequestStatus(net::URLRequestStatus::SUCCESS, net::OK);
+ EXPECT_CALL(*service, CheckProbeURL(_, _))
+ .Times(1)
+ .WillRepeatedly(testing::WithArgs<1>(
+ testing::Invoke(&responder, &TestResponder::ExecuteCallback)));
config()->OnIPAddressChanged();
test_context_->RunUntilIdle();
CheckProxyConfigs(true, expected_restricted, expected_fallback_restricted);
@@ -179,7 +191,7 @@ TEST_F(DataReductionProxyConfigTest, TestGetDataReductionProxies) {
proxies[1]);
}
-TEST_F(DataReductionProxyConfigTest, TestSetProxyConfigs) {
+TEST_F(DataReductionProxyConfigTest, TestUpdateConfigurator) {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kDataReductionProxyAlt, params()->DefaultAltOrigin());
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
@@ -189,7 +201,7 @@ TEST_F(DataReductionProxyConfigTest, TestSetProxyConfigs) {
switches::kDataReductionSSLProxy, params()->DefaultSSLOrigin());
ResetSettings(true, true, true, true, false);
- config()->SetProxyConfigs(true, true, false, false);
+ config()->UpdateConfigurator(true, true, false, false);
EXPECT_TRUE(configurator()->enabled());
EXPECT_EQ(
@@ -207,7 +219,7 @@ TEST_F(DataReductionProxyConfigTest, TestSetProxyConfigs) {
net::ProxyServer::FromURI(configurator()->ssl_origin(),
net::ProxyServer::SCHEME_HTTP));
- config()->SetProxyConfigs(true, false, false, false);
+ config()->UpdateConfigurator(true, false, false, false);
EXPECT_TRUE(configurator()->enabled());
EXPECT_TRUE(
net::HostPortPair::FromString(params()->DefaultOrigin())
@@ -217,23 +229,23 @@ TEST_F(DataReductionProxyConfigTest, TestSetProxyConfigs) {
configurator()->fallback_origin())));
EXPECT_TRUE(configurator()->ssl_origin().empty());
- config()->SetProxyConfigs(false, true, false, false);
+ config()->UpdateConfigurator(false, true, false, false);
EXPECT_FALSE(configurator()->enabled());
EXPECT_TRUE(configurator()->origin().empty());
EXPECT_TRUE(configurator()->fallback_origin().empty());
EXPECT_TRUE(configurator()->ssl_origin().empty());
- config()->SetProxyConfigs(false, false, false, false);
+ config()->UpdateConfigurator(false, false, false, false);
EXPECT_FALSE(configurator()->enabled());
EXPECT_TRUE(configurator()->origin().empty());
EXPECT_TRUE(configurator()->fallback_origin().empty());
EXPECT_TRUE(configurator()->ssl_origin().empty());
}
-TEST_F(DataReductionProxyConfigTest, TestSetProxyConfigsHoldback) {
+TEST_F(DataReductionProxyConfigTest, TestUpdateConfiguratorHoldback) {
ResetSettings(true, true, true, true, true);
- config()->SetProxyConfigs(true, true, false, false);
+ config()->UpdateConfigurator(true, true, false, false);
EXPECT_FALSE(configurator()->enabled());
EXPECT_EQ("", configurator()->origin());
EXPECT_EQ("", configurator()->fallback_origin());
@@ -244,7 +256,7 @@ TEST_F(DataReductionProxyConfigTest, TestOnIPAddressChanged) {
// The proxy is enabled initially.
config()->enabled_by_user_ = true;
config()->restricted_by_carrier_ = false;
- config()->SetProxyConfigs(true, false, false, true);
+ config()->UpdateConfigurator(true, false, false, true);
// IP address change triggers a probe that succeeds. Proxy remains
// unrestricted.
CheckProbeOnIPChange(kProbeURLWithOKResponse, "OK", true, false, false);
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc
index 2655d4b3..dbebf76 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor_unittest.cc
@@ -190,10 +190,10 @@ class DataReductionProxyInterceptorWithServerTest : public testing::Test {
DataReductionProxyTestContext::DEFAULT_TEST_CONTEXT_OPTIONS));
std::string spec;
base::TrimString(proxy_.GetURL("/").spec(), "/", &spec);
- test_context_->io_data()->test_params()->set_origin(
+ test_context_->config()->test_params()->set_origin(
net::ProxyServer::FromURI(spec, net::ProxyServer::SCHEME_HTTP));
std::string proxy_name =
- test_context_->io_data()->params()->origin().ToURI();
+ test_context_->config()->params()->origin().ToURI();
proxy_service_.reset(
net::ProxyService::CreateFixedFromPacResult(
"PROXY " + proxy_name + "; DIRECT"));
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc
index 00f44c5..636eb80 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc
@@ -9,11 +9,11 @@
#include "base/prefs/pref_member.h"
#include "base/single_thread_task_runner.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypass_protocol.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h"
@@ -25,35 +25,33 @@ namespace data_reduction_proxy {
DataReductionProxyIOData::DataReductionProxyIOData(
const Client& client,
- scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs,
- DataReductionProxySettings* settings,
+ int param_flags,
net::NetLog* net_log,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
- scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)
+ scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
+ bool enable_quic)
: client_(client),
- temporary_statistics_prefs_(statistics_prefs.Pass()),
- settings_(settings),
net_log_(net_log),
io_task_runner_(io_task_runner),
ui_task_runner_(ui_task_runner),
- shutdown_on_ui_(false),
- initialized_(false),
- network_delegate_created_(false) {
- DCHECK(settings);
+ shutdown_on_ui_(false) {
DCHECK(net_log);
DCHECK(io_task_runner_.get());
DCHECK(ui_task_runner_.get());
- params_ = settings->params()->Clone();
+ scoped_ptr<DataReductionProxyParams> params(
+ new DataReductionProxyParams(param_flags));
+ params->EnableQuic(enable_quic);
request_options_.reset(new DataReductionProxyRequestOptions(
- client_, params_.get(), io_task_runner_));
+ client_, params.get(), io_task_runner_));
+ request_options_->Init();
event_store_.reset(new DataReductionProxyEventStore(ui_task_runner));
configurator_.reset(new DataReductionProxyConfigurator(
io_task_runner, net_log, event_store_.get()));
proxy_delegate_.reset(
- new data_reduction_proxy::DataReductionProxyDelegate(
- request_options_.get(), params_.get()));
- if (temporary_statistics_prefs_)
- statistics_prefs_ = temporary_statistics_prefs_->GetWeakPtr();
+ new DataReductionProxyDelegate(request_options_.get(), params.get()));
+ config_.reset(new DataReductionProxyConfig(
+ io_task_runner_, ui_task_runner_, net_log, params.Pass(),
+ configurator_.get(), event_store_.get()));
}
DataReductionProxyIOData::DataReductionProxyIOData() : shutdown_on_ui_(false) {
@@ -63,13 +61,6 @@ DataReductionProxyIOData::~DataReductionProxyIOData() {
DCHECK(shutdown_on_ui_);
}
-void DataReductionProxyIOData::Init() {
- DCHECK(!initialized_);
- DCHECK(!network_delegate_created_);
- initialized_ = true;
- request_options_->Init();
-}
-
void DataReductionProxyIOData::InitOnUIThread(PrefService* pref_service) {
DCHECK(ui_task_runner_->BelongsToCurrentThread());
enabled_.Init(prefs::kDataReductionProxyEnabled, pref_service);
@@ -83,14 +74,10 @@ void DataReductionProxyIOData::ShutdownOnUIThread() {
shutdown_on_ui_ = true;
}
-void DataReductionProxyIOData::SetDataReductionProxyStatisticsPrefs(
- base::WeakPtr<DataReductionProxyStatisticsPrefs> statistics_prefs) {
- statistics_prefs_ = statistics_prefs;
-}
-
-scoped_ptr<DataReductionProxyStatisticsPrefs>
-DataReductionProxyIOData::PassStatisticsPrefs() {
- return temporary_statistics_prefs_.Pass();
+void DataReductionProxyIOData::SetDataReductionProxyService(
+ base::WeakPtr<DataReductionProxyService> data_reduction_proxy_service) {
+ service_ = data_reduction_proxy_service;
+ config()->SetDataReductionProxyService(data_reduction_proxy_service);
}
bool DataReductionProxyIOData::IsEnabled() const {
@@ -104,7 +91,7 @@ scoped_ptr<net::URLRequestInterceptor>
DataReductionProxyIOData::CreateInterceptor() {
DCHECK(io_task_runner_->BelongsToCurrentThread());
return make_scoped_ptr(new DataReductionProxyInterceptor(
- params_.get(), usage_stats_.get(), event_store_.get()));
+ config_->params(), usage_stats_.get(), event_store_.get()));
}
scoped_ptr<DataReductionProxyNetworkDelegate>
@@ -114,15 +101,14 @@ DataReductionProxyIOData::CreateNetworkDelegate(
DCHECK(io_task_runner_->BelongsToCurrentThread());
scoped_ptr<DataReductionProxyNetworkDelegate> network_delegate(
new DataReductionProxyNetworkDelegate(
- wrapped_network_delegate.Pass(), params_.get(),
+ wrapped_network_delegate.Pass(), config_->params(),
request_options_.get(), configurator_.get()));
if (track_proxy_bypass_statistics && !usage_stats_) {
usage_stats_.reset(new data_reduction_proxy::DataReductionProxyUsageStats(
- params_.get(), settings_, ui_task_runner_));
- network_delegate->InitStatisticsPrefsAndUMA(
- ui_task_runner_, statistics_prefs_, &enabled_, usage_stats_.get());
+ config_->params(), service_, ui_task_runner_));
+ network_delegate->InitIODataAndUMA(ui_task_runner_, this, &enabled_,
+ usage_stats_.get());
}
- network_delegate_created_ = true;
return network_delegate.Pass();
}
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h
index 7c3f509..5fbd0ad 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h
@@ -20,10 +20,10 @@ class URLRequestInterceptor;
namespace data_reduction_proxy {
+class DataReductionProxyConfig;
class DataReductionProxyConfigurator;
class DataReductionProxyEventStore;
-class DataReductionProxyParams;
-class DataReductionProxySettings;
+class DataReductionProxyService;
class DataReductionProxyStatisticsPrefs;
class DataReductionProxyUsageStats;
@@ -31,26 +31,19 @@ class DataReductionProxyUsageStats;
// the IO thread.
class DataReductionProxyIOData {
public:
- // Constructs a DataReductionProxyIOData object and takes ownership of
- // |params| and |statistics_prefs|. |params| contains information about the
- // DNS names used by the proxy, and allowable configurations.
- // |statistics_prefs| maintains compression statistics during use of the
- // proxy. |settings| provides a UI hook to signal when the proxy is
- // unavailable. Only |statistics_prefs.get()| may be null.
+ // Constructs a DataReductionProxyIOData object. |param_flags| is used to
+ // set information about the DNS names used by the proxy, and allowable
+ // configurations.
DataReductionProxyIOData(
const Client& client,
- scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs,
- DataReductionProxySettings* settings,
+ int param_flags,
net::NetLog* net_log,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
- scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
+ scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
+ bool enable_quic);
virtual ~DataReductionProxyIOData();
- // Initializes IOData objects on the IO thread. Must be called before using
- // members.
- void Init();
-
// Initializes preferences, including a preference to track whether the
// Data Reduction Proxy is enabled.
void InitOnUIThread(PrefService* pref_service);
@@ -58,11 +51,9 @@ class DataReductionProxyIOData {
// Destroys the statistics preferences.
void ShutdownOnUIThread();
- void SetDataReductionProxyStatisticsPrefs(
- base::WeakPtr<DataReductionProxyStatisticsPrefs> statistics_prefs);
-
- // Passes ownership of |statistics_prefs_|.
- scoped_ptr<DataReductionProxyStatisticsPrefs> PassStatisticsPrefs();
+ // Sets the Data Reduction Proxy service after it has been created.
+ void SetDataReductionProxyService(
+ base::WeakPtr<DataReductionProxyService> data_reduction_proxy_service);
// Creates an interceptor suitable for following the Data Reduction Proxy
// bypass protocol.
@@ -83,6 +74,10 @@ class DataReductionProxyIOData {
return configurator_.get();
}
+ DataReductionProxyConfig* config() const {
+ return config_.get();
+ }
+
DataReductionProxyEventStore* event_store() const {
return event_store_.get();
}
@@ -99,15 +94,15 @@ class DataReductionProxyIOData {
return net_log_;
}
+ base::WeakPtr<DataReductionProxyService> service() const {
+ return service_;
+ }
+
// Used for testing.
DataReductionProxyUsageStats* usage_stats() const {
return usage_stats_.get();
}
- DataReductionProxyParams* params() const {
- return params_.get();
- }
-
DataReductionProxyDebugUIService* debug_ui_service() const {
return debug_ui_service_.get();
}
@@ -127,14 +122,7 @@ class DataReductionProxyIOData {
Client client_;
// Parameters including DNS names and allowable configurations.
- scoped_ptr<DataReductionProxyParams> params_;
-
- // Tracker of compression statistics to be displayed to the user.
- base::WeakPtr<DataReductionProxyStatisticsPrefs> statistics_prefs_;
-
- // |temporary_statistics_prefs_| is used only until DataReductionProxySettings
- // initialization and is dead after.
- scoped_ptr<DataReductionProxyStatisticsPrefs> temporary_statistics_prefs_;
+ scoped_ptr<DataReductionProxyConfig> config_;
// Holds the DataReductionProxyDebugUIManager for Data Reduction Proxy bypass
// interstitials.
@@ -150,8 +138,8 @@ class DataReductionProxyIOData {
// request.
scoped_ptr<DataReductionProxyDelegate> proxy_delegate_;
- // User-facing settings object.
- DataReductionProxySettings* settings_;
+ // Data Reduction Proxy objects with a UI based lifetime.
+ base::WeakPtr<DataReductionProxyService> service_;
// Tracker of various metrics to be reported in UMA.
scoped_ptr<DataReductionProxyUsageStats> usage_stats_;
@@ -168,8 +156,6 @@ class DataReductionProxyIOData {
// Used
bool shutdown_on_ui_;
- bool initialized_;
- bool network_delegate_created_;
// Preference that determines if the Data Reduction Proxy has been enabled
// by the user. In practice, this can be overridden by the command line.
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data_unittest.cc
index 75506f0..e877e85 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data_unittest.cc
@@ -13,9 +13,7 @@
#include "base/time/time.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h"
-#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "net/base/net_log.h"
#include "net/url_request/url_request_interceptor.h"
#include "net/url_request/url_request_test_util.h"
@@ -54,13 +52,6 @@ namespace data_reduction_proxy {
class DataReductionProxyIODataTest : public testing::Test {
public:
void SetUp() override {
- scoped_ptr<TestDataReductionProxyParams> params;
- params.reset(new TestDataReductionProxyParams(
- TestDataReductionProxyParams::kAllowed,
- TestDataReductionProxyParams::HAS_EVERYTHING &
- ~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
- ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN));
- settings_.reset(new DataReductionProxySettings(params.Pass()));
RegisterSimpleProfilePrefs(prefs_.registry());
}
@@ -88,29 +79,18 @@ class DataReductionProxyIODataTest : public testing::Test {
return &prefs_;
}
- DataReductionProxySettings* settings() const {
- return settings_.get();
- }
-
private:
base::MessageLoopForIO loop_;
net::TestDelegate delegate_;
net::TestURLRequestContext context_;
net::NetLog net_log_;
TestingPrefServiceSimple prefs_;
- scoped_ptr<DataReductionProxySettings> settings_;
};
TEST_F(DataReductionProxyIODataTest, TestConstruction) {
- DataReductionProxyStatisticsPrefs* statistics_prefs =
- new DataReductionProxyStatisticsPrefs(
- prefs(), message_loop_proxy(), base::TimeDelta());
- scoped_ptr<DataReductionProxyIOData> io_data(
- new DataReductionProxyIOData(
- Client::UNKNOWN, make_scoped_ptr(statistics_prefs), settings(),
- net_log(), message_loop_proxy(), message_loop_proxy()));
- settings()->SetDataReductionProxyStatisticsPrefs(
- io_data->PassStatisticsPrefs());
+ scoped_ptr<DataReductionProxyIOData> io_data(new DataReductionProxyIOData(
+ Client::UNKNOWN, DataReductionProxyParams::kAllowed, net_log(),
+ message_loop_proxy(), message_loop_proxy(), false /* enable_quic */));
// Check that io_data creates an interceptor. Such an interceptor is
// thoroughly tested by DataReductionProxyInterceptoTest.
@@ -118,10 +98,6 @@ TEST_F(DataReductionProxyIODataTest, TestConstruction) {
io_data->CreateInterceptor();
EXPECT_NE(nullptr, interceptor.get());
- // At this point io_data->statistics_prefs() should be set and compression
- // statistics logging should be enabled.
- EXPECT_EQ(statistics_prefs, settings()->statistics_prefs().get());
-
// When creating a network delegate, expect that it properly wraps a
// network delegate. Such a network delegate is thoroughly tested by
// DataReductionProxyNetworkDelegateTest.
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc
index 9df2ef5..1db8852 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc
@@ -12,7 +12,9 @@
#include "base/strings/string_number_conversions.h"
#include "base/time/time.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h"
#include "net/base/load_flags.h"
@@ -93,15 +95,15 @@ DataReductionProxyNetworkDelegate::DataReductionProxyNetworkDelegate(
DataReductionProxyNetworkDelegate::~DataReductionProxyNetworkDelegate() {
}
-void DataReductionProxyNetworkDelegate::InitStatisticsPrefsAndUMA(
+void DataReductionProxyNetworkDelegate::InitIODataAndUMA(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
- const base::WeakPtr<DataReductionProxyStatisticsPrefs>& statistics_prefs,
+ DataReductionProxyIOData* io_data,
BooleanPrefMember* data_reduction_proxy_enabled,
DataReductionProxyUsageStats* usage_stats) {
DCHECK(data_reduction_proxy_enabled);
DCHECK(usage_stats);
ui_task_runner_ = ui_task_runner;
- data_reduction_proxy_statistics_prefs_ = statistics_prefs;
+ data_reduction_proxy_io_data_ = io_data;
data_reduction_proxy_enabled_ = data_reduction_proxy_enabled;
data_reduction_proxy_usage_stats_ = usage_stats;
}
@@ -251,17 +253,20 @@ void DataReductionProxyNetworkDelegate::UpdateContentLengthPrefs(
int original_content_length,
bool data_reduction_proxy_enabled,
DataReductionProxyRequestType request_type) {
- if (data_reduction_proxy_statistics_prefs_) {
- int64 total_received = data_reduction_proxy_statistics_prefs_->GetInt64(
+ if (data_reduction_proxy_io_data_ &&
+ data_reduction_proxy_io_data_->service()) {
+ DataReductionProxyStatisticsPrefs* data_reduction_proxy_statistics_prefs =
+ data_reduction_proxy_io_data_->service()->statistics_prefs();
+ int64 total_received = data_reduction_proxy_statistics_prefs->GetInt64(
data_reduction_proxy::prefs::kHttpReceivedContentLength);
- int64 total_original = data_reduction_proxy_statistics_prefs_->GetInt64(
+ int64 total_original = data_reduction_proxy_statistics_prefs->GetInt64(
data_reduction_proxy::prefs::kHttpOriginalContentLength);
total_received += received_content_length;
total_original += original_content_length;
- data_reduction_proxy_statistics_prefs_->SetInt64(
+ data_reduction_proxy_statistics_prefs->SetInt64(
data_reduction_proxy::prefs::kHttpReceivedContentLength,
total_received);
- data_reduction_proxy_statistics_prefs_->SetInt64(
+ data_reduction_proxy_statistics_prefs->SetInt64(
data_reduction_proxy::prefs::kHttpOriginalContentLength,
total_original);
@@ -271,7 +276,7 @@ void DataReductionProxyNetworkDelegate::UpdateContentLengthPrefs(
data_reduction_proxy_enabled,
request_type,
base::Time::Now(),
- data_reduction_proxy_statistics_prefs_.get());
+ data_reduction_proxy_statistics_prefs);
}
}
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h
index 116cdc7..b31a962 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.h
@@ -40,9 +40,9 @@ class URLRequest;
namespace data_reduction_proxy {
class DataReductionProxyConfigurator;
+class DataReductionProxyIOData;
class DataReductionProxyParams;
class DataReductionProxyRequestOptions;
-class DataReductionProxyStatisticsPrefs;
class DataReductionProxyUsageStats;
// DataReductionProxyNetworkDelegate is a LayeredNetworkDelegate that wraps a
@@ -68,9 +68,9 @@ class DataReductionProxyNetworkDelegate : public net::LayeredNetworkDelegate {
// Initializes member variables to record data reduction proxy prefs and
// report UMA.
- void InitStatisticsPrefsAndUMA(
+ void InitIODataAndUMA(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
- const base::WeakPtr<DataReductionProxyStatisticsPrefs>& statistics_prefs,
+ DataReductionProxyIOData* io_data,
BooleanPrefMember* data_reduction_proxy_enabled,
DataReductionProxyUsageStats* usage_stats);
@@ -142,16 +142,14 @@ class DataReductionProxyNetworkDelegate : public net::LayeredNetworkDelegate {
// Weak, owned by our owner.
BooleanPrefMember* data_reduction_proxy_enabled_;
- // Must outlive this DataReductionProxyNetworkDelegate.
+ // All raw Data Reduction Proxy pointers must outlive |this|.
DataReductionProxyParams* data_reduction_proxy_params_;
- // Must outlive this DataReductionProxyNetworkDelegate.
DataReductionProxyUsageStats* data_reduction_proxy_usage_stats_;
DataReductionProxyRequestOptions* data_reduction_proxy_request_options_;
- base::WeakPtr<DataReductionProxyStatisticsPrefs>
- data_reduction_proxy_statistics_prefs_;
+ DataReductionProxyIOData* data_reduction_proxy_io_data_;
const DataReductionProxyConfigurator* configurator_;
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc
index 721574b..d78f797 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc
@@ -86,11 +86,11 @@ class DataReductionProxyNetworkDelegateTest : public testing::Test {
TestDataReductionProxyParams::HAS_EVERYTHING &
~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN,
- DataReductionProxyTestContext::SKIP_SETTINGS_INITIALIZATION));
+ DataReductionProxyTestContext::DEFAULT_TEST_CONTEXT_OPTIONS));
request_options_.reset(
new DataReductionProxyRequestOptions(
- kClient, params(), test_context_->task_runner()));
+ kClient, params(), test_context_->task_runner()));
data_reduction_proxy_network_delegate_.reset(
new DataReductionProxyNetworkDelegate(
@@ -140,12 +140,16 @@ class DataReductionProxyNetworkDelegateTest : public testing::Test {
return test_context_->config()->test_params();
}
+ TestDataReductionProxyIOData* io_data() const {
+ return test_context_->io_data();
+ }
+
TestingPrefServiceSimple* pref_service() const {
return test_context_->pref_service();
}
- scoped_ptr<DataReductionProxyStatisticsPrefs> CreateStatisticsPrefs() {
- return test_context_->CreateStatisticsPrefs().Pass();
+ DataReductionProxyStatisticsPrefs* statistics_prefs() const {
+ return test_context_->data_reduction_proxy_service()->statistics_prefs();
}
scoped_ptr<DataReductionProxyRequestOptions> request_options_;
@@ -410,14 +414,11 @@ TEST_F(DataReductionProxyNetworkDelegateTest, TotalLengths) {
const int64 kOriginalLength = 200;
const int64 kReceivedLength = 100;
- scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs =
- CreateStatisticsPrefs();
PrefRegistrySimple* registry = pref_service()->registry();
data_reduction_proxy::RegisterSimpleProfilePrefs(registry);
- data_reduction_proxy_network_delegate_->
- data_reduction_proxy_statistics_prefs_ =
- statistics_prefs->GetWeakPtr();
+ data_reduction_proxy_network_delegate_->data_reduction_proxy_io_data_ =
+ io_data();
data_reduction_proxy_network_delegate_->UpdateContentLengthPrefs(
kReceivedLength, kOriginalLength,
@@ -426,12 +427,12 @@ TEST_F(DataReductionProxyNetworkDelegateTest, TotalLengths) {
UNKNOWN_TYPE);
EXPECT_EQ(kReceivedLength,
- statistics_prefs->GetInt64(
+ statistics_prefs()->GetInt64(
data_reduction_proxy::prefs::kHttpReceivedContentLength));
EXPECT_FALSE(pref_service()->GetBoolean(
data_reduction_proxy::prefs::kDataReductionProxyEnabled));
EXPECT_EQ(kOriginalLength,
- statistics_prefs->GetInt64(
+ statistics_prefs()->GetInt64(
data_reduction_proxy::prefs::kHttpOriginalContentLength));
// Record the same numbers again, and total lengths should be doubled.
@@ -442,12 +443,12 @@ TEST_F(DataReductionProxyNetworkDelegateTest, TotalLengths) {
UNKNOWN_TYPE);
EXPECT_EQ(kReceivedLength * 2,
- statistics_prefs->GetInt64(
+ statistics_prefs()->GetInt64(
data_reduction_proxy::prefs::kHttpReceivedContentLength));
EXPECT_FALSE(pref_service()->GetBoolean(
data_reduction_proxy::prefs::kDataReductionProxyEnabled));
EXPECT_EQ(kOriginalLength * 2,
- statistics_prefs->GetInt64(
+ statistics_prefs()->GetInt64(
data_reduction_proxy::prefs::kHttpOriginalContentLength));
}
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc
new file mode 100644
index 0000000..08ff314
--- /dev/null
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc
@@ -0,0 +1,85 @@
+// Copyright 2015 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/core/browser/data_reduction_proxy_service.h"
+
+#include "base/sequenced_task_runner.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h"
+#include "net/base/load_flags.h"
+#include "net/url_request/url_fetcher.h"
+#include "net/url_request/url_request_status.h"
+
+namespace data_reduction_proxy {
+
+DataReductionProxyService::DataReductionProxyService(
+ scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs,
+ DataReductionProxySettings* settings,
+ net::URLRequestContextGetter* request_context_getter)
+ : url_request_context_getter_(request_context_getter),
+ settings_(settings),
+ weak_factory_(this) {
+ DCHECK(settings);
+ statistics_prefs_ = statistics_prefs.Pass();
+}
+
+DataReductionProxyService::~DataReductionProxyService() {
+}
+
+void DataReductionProxyService::Shutdown() {
+ DCHECK(CalledOnValidThread());
+ weak_factory_.InvalidateWeakPtrs();
+}
+
+void DataReductionProxyService::EnableCompressionStatisticsLogging(
+ PrefService* prefs,
+ scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
+ const base::TimeDelta& commit_delay) {
+ DCHECK(!statistics_prefs_);
+ statistics_prefs_.reset(new DataReductionProxyStatisticsPrefs(
+ prefs, ui_task_runner, commit_delay));
+}
+
+base::WeakPtr<DataReductionProxyService>
+DataReductionProxyService::GetWeakPtr() {
+ DCHECK(CalledOnValidThread());
+ return weak_factory_.GetWeakPtr();
+}
+
+void DataReductionProxyService::OnURLFetchComplete(
+ const net::URLFetcher* source) {
+ DCHECK(source == fetcher_.get());
+ net::URLRequestStatus status = source->GetStatus();
+
+ std::string response;
+ source->GetResponseAsString(&response);
+
+ fetcher_callback_.Run(response, status);
+}
+
+net::URLFetcher* DataReductionProxyService::GetURLFetcherForProbe(
+ const GURL& probe_url) {
+ net::URLFetcher* fetcher =
+ net::URLFetcher::Create(probe_url, net::URLFetcher::GET, this);
+ fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE | net::LOAD_BYPASS_PROXY);
+ DCHECK(url_request_context_getter_);
+ fetcher->SetRequestContext(url_request_context_getter_);
+ // Configure max retries to be at most kMaxRetries times for 5xx errors.
+ static const int kMaxRetries = 5;
+ fetcher->SetMaxRetriesOn5xx(kMaxRetries);
+ fetcher->SetAutomaticallyRetryOnNetworkChanges(kMaxRetries);
+ return fetcher;
+}
+
+void DataReductionProxyService::CheckProbeURL(
+ const GURL& probe_url, FetcherResponseCallback fetcher_callback) {
+ DCHECK(CalledOnValidThread());
+ net::URLFetcher* fetcher = GetURLFetcherForProbe(probe_url);
+ if (!fetcher)
+ return;
+ fetcher_.reset(fetcher);
+ fetcher_callback_ = fetcher_callback;
+ fetcher_->Start();
+}
+
+} // namespace data_reduction_proxy
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h
new file mode 100644
index 0000000..1017e813
--- /dev/null
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h
@@ -0,0 +1,106 @@
+// Copyright 2015 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_CORE_BROWSER_DATA_REDUCTION_PROXY_SERVICE_H_
+#define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_SERVICE_H_
+
+#include "base/callback.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "base/threading/non_thread_safe.h"
+#include "net/url_request/url_fetcher_delegate.h"
+
+class GURL;
+class PrefService;
+
+namespace base {
+class SequencedTaskRunner;
+class TimeDelta;
+}
+
+namespace net {
+class URLFetcher;
+class URLRequestContextGetter;
+class URLRequestStatus;
+}
+
+namespace data_reduction_proxy {
+
+typedef base::Callback<void(const std::string&, const net::URLRequestStatus&)>
+ FetcherResponseCallback;
+
+class DataReductionProxySettings;
+class DataReductionProxyStatisticsPrefs;
+
+
+// Contains and initializes all Data Reduction Proxy objects that have a
+// lifetime based on the UI thread.
+class DataReductionProxyService : public base::NonThreadSafe,
+ public net::URLFetcherDelegate {
+ public:
+ // The caller must ensure that |settings| and |request_context| remain alive
+ // for the lifetime of the |DataReductionProxyService| instance. This instance
+ // will take ownership of |statistics_prefs|.
+ // TODO(jeremyim): DataReductionProxyService should own
+ // DataReductionProxySettings and not vice versa.
+ DataReductionProxyService(
+ scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs,
+ DataReductionProxySettings* settings,
+ net::URLRequestContextGetter* request_context_getter);
+
+ ~DataReductionProxyService() override;
+
+ void Shutdown();
+
+ // Requests the given |probe_url|. Upon completion, returns the results to the
+ // caller via the |fetcher_callback|. Virtualized for unit testing.
+ virtual void CheckProbeURL(const GURL& probe_url,
+ FetcherResponseCallback fetcher_callback);
+
+ // Constructs statistics prefs. This should not be called if a valid
+ // statistics prefs is passed into the constructor.
+ void EnableCompressionStatisticsLogging(
+ PrefService* prefs,
+ scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
+ const base::TimeDelta& commit_delay);
+
+ DataReductionProxyStatisticsPrefs* statistics_prefs() const {
+ return statistics_prefs_.get();
+ }
+
+ DataReductionProxySettings* settings() const {
+ return settings_;
+ }
+
+ base::WeakPtr<DataReductionProxyService> GetWeakPtr();
+
+ protected:
+ // Virtualized for testing. Returns a fetcher for the probe to check if OK for
+ // the proxy to use TLS.
+ virtual net::URLFetcher* GetURLFetcherForProbe(const GURL& probe_url);
+
+ private:
+ // net::URLFetcherDelegate:
+ void OnURLFetchComplete(const net::URLFetcher* source) override;
+
+ net::URLRequestContextGetter* url_request_context_getter_;
+
+ // The URLFetcher being used for the canary check.
+ scoped_ptr<net::URLFetcher> fetcher_;
+ FetcherResponseCallback fetcher_callback_;
+
+ // Tracks compression statistics to be displayed to the user.
+ scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs_;
+
+ DataReductionProxySettings* settings_;
+
+ base::WeakPtrFactory<DataReductionProxyService> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(DataReductionProxyService);
+};
+
+} // namespace data_reduction_proxy
+
+#endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_SERVICE_H_
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc
index ebc3f13..081c49f 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.cc
@@ -6,66 +6,24 @@
#include "base/bind.h"
#include "base/command_line.h"
-#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
-#include "base/metrics/sparse_histogram.h"
#include "base/prefs/pref_member.h"
#include "base/prefs/pref_service.h"
-#include "base/prefs/scoped_user_pref_update.h"
#include "base/strings/string_number_conversions.h"
-#include "base/strings/string_util.h"
-#include "base/strings/stringprintf.h"
-#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h"
-#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h"
-#include "net/base/host_port_pair.h"
-#include "net/base/load_flags.h"
-#include "net/base/net_errors.h"
-#include "net/base/net_util.h"
-#include "net/http/http_network_session.h"
-#include "net/http/http_response_headers.h"
-#include "net/proxy/proxy_server.h"
-#include "net/url_request/url_fetcher.h"
-#include "net/url_request/url_fetcher_delegate.h"
-#include "net/url_request/url_request_context_getter.h"
-#include "net/url_request/url_request_status.h"
-#include "url/gurl.h"
-
-
-using base::StringPrintf;
namespace {
-// Values of the UMA DataReductionProxy.NetworkChangeEvents histograms.
-// This enum must remain synchronized with the enum of the same
-// name in metrics/histograms/histograms.xml.
-enum DataReductionProxyNetworkChangeEvent {
- IP_CHANGED = 0, // The client IP address changed.
- DISABLED_ON_VPN = 1, // The proxy is disabled because a VPN is running.
- CHANGE_EVENT_COUNT = 2 // This must always be last.
-};
-
// Key of the UMA DataReductionProxy.StartupState histogram.
const char kUMAProxyStartupStateHistogram[] =
"DataReductionProxy.StartupState";
-// Key of the UMA DataReductionProxy.ProbeURL histogram.
-const char kUMAProxyProbeURL[] = "DataReductionProxy.ProbeURL";
-
-// Key of the UMA DataReductionProxy.ProbeURLNetError histogram.
-const char kUMAProxyProbeURLNetError[] = "DataReductionProxy.ProbeURLNetError";
-
-// Record a network change event.
-void RecordNetworkChangeEvent(DataReductionProxyNetworkChangeEvent event) {
- UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.NetworkChangeEvents",
- event,
- CHANGE_EVENT_COUNT);
-}
-
int64 GetInt64PrefValue(const base::ListValue& list_value, size_t index) {
int64 val = 0;
std::string pref_value;
@@ -89,25 +47,19 @@ bool IsEnabledOnCommandLine() {
namespace data_reduction_proxy {
-DataReductionProxySettings::DataReductionProxySettings(
- scoped_ptr<DataReductionProxyParams> params)
- : restricted_by_carrier_(false),
- enabled_by_user_(false),
- disabled_on_vpn_(false),
- unreachable_(false),
+DataReductionProxySettings::DataReductionProxySettings()
+ : unreachable_(false),
+ allowed_(false),
+ alternative_allowed_(false),
+ promo_allowed_(false),
prefs_(NULL),
- url_request_context_getter_(NULL),
- net_log_(NULL),
event_store_(NULL),
- configurator_(NULL) {
- DCHECK(params.get());
- config_.reset(new DataReductionProxyConfig(params.Pass()));
+ config_(nullptr) {
}
DataReductionProxySettings::~DataReductionProxySettings() {
- if (params()->allowed())
+ if (allowed_)
spdy_proxy_auth_enabled_.Destroy();
- net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
}
void DataReductionProxySettings::InitPrefMembers() {
@@ -125,56 +77,31 @@ void DataReductionProxySettings::InitPrefMembers() {
base::Unretained(this)));
}
+void DataReductionProxySettings::UpdateConfigValues() {
+ DCHECK(config_);
+ allowed_ = config_->params()->allowed();
+ alternative_allowed_ = config_->params()->alternative_allowed();
+ promo_allowed_ = config_->params()->promo_allowed();
+ primary_origin_ = config_->params()->origin().ToURI();
+}
+
void DataReductionProxySettings::InitDataReductionProxySettings(
PrefService* prefs,
- scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs,
- net::URLRequestContextGetter* url_request_context_getter,
- net::NetLog* net_log,
- DataReductionProxyEventStore* event_store,
- bool enable_quic) {
+ DataReductionProxyIOData* io_data,
+ scoped_ptr<DataReductionProxyService> data_reduction_proxy_service) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(prefs);
- DCHECK(!statistics_prefs_);
- DCHECK(url_request_context_getter);
- DCHECK(event_store);
+ DCHECK(io_data);
+ DCHECK(io_data->config());
+ DCHECK(io_data->event_store());
+ DCHECK(data_reduction_proxy_service.get());
prefs_ = prefs;
- statistics_prefs_ = statistics_prefs.Pass();
- url_request_context_getter_ = url_request_context_getter;
- net_log_ = net_log;
- event_store_ = event_store;
+ config_ = io_data->config();
+ event_store_ = io_data->event_store();
+ data_reduction_proxy_service_ = data_reduction_proxy_service.Pass();
InitPrefMembers();
+ UpdateConfigValues();
RecordDataReductionInit();
-
- // Disable the proxy if it is not allowed to be used.
- if (!params()->allowed())
- return;
-
- params()->EnableQuic(enable_quic);
-
- AddDefaultProxyBypassRules();
- net::NetworkChangeNotifier::AddIPAddressObserver(this);
-}
-
-void DataReductionProxySettings::SetDataReductionProxyStatisticsPrefs(
- scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs) {
- statistics_prefs_ = statistics_prefs.Pass();
-}
-
-void DataReductionProxySettings::EnableCompressionStatisticsLogging(
- PrefService* prefs,
- scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
- const base::TimeDelta& commit_delay) {
- DCHECK(!statistics_prefs_);
- statistics_prefs_.reset(
- new DataReductionProxyStatisticsPrefs(
- prefs, ui_task_runner, commit_delay));
-}
-
-base::WeakPtr<DataReductionProxyStatisticsPrefs>
-DataReductionProxySettings::statistics_prefs() {
- if (statistics_prefs_)
- return statistics_prefs_->GetWeakPtr();
- return base::WeakPtr<DataReductionProxyStatisticsPrefs>();
}
void DataReductionProxySettings::SetOnDataReductionEnabledCallback(
@@ -183,12 +110,6 @@ void DataReductionProxySettings::SetOnDataReductionEnabledCallback(
on_data_reduction_proxy_enabled_.Run(IsDataReductionProxyEnabled());
}
-void DataReductionProxySettings::SetProxyConfigurator(
- DataReductionProxyConfigurator* configurator) {
- DCHECK(configurator);
- configurator_ = configurator;
-}
-
bool DataReductionProxySettings::IsDataReductionProxyEnabled() {
return spdy_proxy_auth_enabled_.GetValue() || IsEnabledOnCommandLine();
}
@@ -205,7 +126,7 @@ bool DataReductionProxySettings::IsDataReductionProxyManaged() {
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 (!allowed_)
return;
if (spdy_proxy_auth_enabled_.GetValue() != enabled) {
@@ -218,7 +139,7 @@ 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())
+ if (!alternative_allowed_)
return;
if (data_reduction_proxy_alternative_enabled_.GetValue() != enabled) {
data_reduction_proxy_alternative_enabled_.SetValue(enabled);
@@ -228,9 +149,10 @@ void DataReductionProxySettings::SetDataReductionProxyAlternativeEnabled(
int64 DataReductionProxySettings::GetDataReductionLastUpdateTime() {
DCHECK(thread_checker_.CalledOnValidThread());
- DCHECK(statistics_prefs_);
+ DCHECK(data_reduction_proxy_service_->statistics_prefs());
int64 last_update_internal =
- statistics_prefs_->GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate);
+ data_reduction_proxy_service_->statistics_prefs()->GetInt64(
+ prefs::kDailyHttpContentLengthLastUpdateDate);
base::Time last_update = base::Time::FromInternalValue(last_update_internal);
return static_cast<int64>(last_update.ToJsTime());
}
@@ -256,157 +178,36 @@ DataReductionProxySettings::GetDailyReceivedContentLengths() {
return GetDailyContentLengths(prefs::kDailyHttpReceivedContentLength);
}
-void DataReductionProxySettings::OnURLFetchComplete(
- const net::URLFetcher* source) {
- DCHECK(thread_checker_.CalledOnValidThread());
-
- DCHECK(source == fetcher_.get());
- net::URLRequestStatus status = source->GetStatus();
-
- if (event_store_) {
- event_store_->EndCanaryRequest(bound_net_log_, status.error());
- }
-
- if (status.status() == net::URLRequestStatus::FAILED) {
- if (status.error() == net::ERR_INTERNET_DISCONNECTED) {
- RecordProbeURLFetchResult(INTERNET_DISCONNECTED);
- return;
- }
- // TODO(bengr): Remove once we understand the reasons probes are failing.
- // Probe errors are either due to fetcher-level errors or modified
- // responses. This only tracks the former.
- UMA_HISTOGRAM_SPARSE_SLOWLY(
- kUMAProxyProbeURLNetError, std::abs(status.error()));
- }
-
- std::string response;
- source->GetResponseAsString(&response);
-
- if ("OK" == response.substr(0, 2)) {
- DVLOG(1) << "The data reduction proxy is unrestricted.";
-
- if (enabled_by_user_) {
- if (restricted_by_carrier_) {
- // The user enabled the proxy, but sometime previously in the session,
- // the network operator had blocked the canary and restricted the user.
- // 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);
- } else {
- RecordProbeURLFetchResult(SUCCEEDED_PROXY_ALREADY_ENABLED);
- }
- }
- restricted_by_carrier_ = false;
- return;
- }
- DVLOG(1) << "The data reduction proxy is restricted to the configured "
- << "fallback proxy.";
- if (enabled_by_user_) {
- if (!restricted_by_carrier_) {
- // Restrict the proxy.
- SetProxyConfigs(true /* enabled */,
- IsDataReductionProxyAlternativeEnabled(),
- true /* restricted */,
- false /* at_startup */);
- RecordProbeURLFetchResult(FAILED_PROXY_DISABLED);
- } else {
- RecordProbeURLFetchResult(FAILED_PROXY_ALREADY_DISABLED);
- }
- }
- restricted_by_carrier_ = true;
-}
-
PrefService* DataReductionProxySettings::GetOriginalProfilePrefs() {
DCHECK(thread_checker_.CalledOnValidThread());
return prefs_;
}
-void DataReductionProxySettings::AddDefaultProxyBypassRules() {
- // localhost
- DCHECK(configurator_);
- configurator_->AddHostPatternToBypass("<local>");
- // RFC6890 loopback addresses.
- // TODO(tbansal): Remove this once crbug/446705 is fixed.
- configurator_->AddHostPatternToBypass("127.0.0.0/8");
-
- // RFC6890 current network (only valid as source address).
- configurator_->AddHostPatternToBypass("0.0.0.0/8");
-
- // RFC1918 private addresses.
- configurator_->AddHostPatternToBypass("10.0.0.0/8");
- configurator_->AddHostPatternToBypass("172.16.0.0/12");
- configurator_->AddHostPatternToBypass("192.168.0.0/16");
-
- // RFC3513 unspecified address.
- configurator_->AddHostPatternToBypass("::/128");
-
- // RFC4193 private addresses.
- configurator_->AddHostPatternToBypass("fc00::/7");
- // IPV6 probe addresses.
- configurator_->AddHostPatternToBypass("*-ds.metric.gstatic.com");
- configurator_->AddHostPatternToBypass("*-v4.metric.gstatic.com");
-}
-
-void DataReductionProxySettings::LogProxyState(
- bool enabled, bool restricted, bool at_startup) {
- // This must stay a LOG(WARNING); the output is used in processing customer
- // feedback.
- const char kAtStartup[] = "at startup";
- const char kByUser[] = "by user action";
- const char kOn[] = "ON";
- const char kOff[] = "OFF";
- const char kRestricted[] = "(Restricted)";
- const char kUnrestricted[] = "(Unrestricted)";
-
- std::string annotated_on =
- kOn + std::string(" ") + (restricted ? kRestricted : kUnrestricted);
-
- LOG(WARNING) << "SPDY proxy " << (enabled ? annotated_on : kOff)
- << " " << (at_startup ? kAtStartup : kByUser);
-}
-
-void DataReductionProxySettings::OnIPAddressChanged() {
- DCHECK(thread_checker_.CalledOnValidThread());
- if (enabled_by_user_) {
- DCHECK(params()->allowed());
- RecordNetworkChangeEvent(IP_CHANGED);
- if (DisableIfVPN())
- return;
- if (IsDataReductionProxyAlternativeEnabled() &&
- !params()->alternative_fallback_allowed()) {
- return;
- }
- ProbeWhetherDataReductionProxyIsAvailable();
- }
-}
-
void DataReductionProxySettings::OnProxyEnabledPrefChange() {
DCHECK(thread_checker_.CalledOnValidThread());
if (!on_data_reduction_proxy_enabled_.is_null())
on_data_reduction_proxy_enabled_.Run(IsDataReductionProxyEnabled());
- if (!params()->allowed())
+ if (!allowed_)
return;
MaybeActivateDataReductionProxy(false);
}
void DataReductionProxySettings::OnProxyAlternativeEnabledPrefChange() {
DCHECK(thread_checker_.CalledOnValidThread());
- if (!params()->alternative_allowed())
+ if (!alternative_allowed_)
return;
MaybeActivateDataReductionProxy(false);
}
void DataReductionProxySettings::ResetDataReductionStatistics() {
DCHECK(thread_checker_.CalledOnValidThread());
- DCHECK(statistics_prefs_);
+ DCHECK(data_reduction_proxy_service_->statistics_prefs());
base::ListValue* original_update =
- statistics_prefs_->GetList(prefs::kDailyHttpOriginalContentLength);
+ data_reduction_proxy_service_->statistics_prefs()->GetList(
+ prefs::kDailyHttpOriginalContentLength);
base::ListValue* received_update =
- statistics_prefs_->GetList(prefs::kDailyHttpReceivedContentLength);
+ data_reduction_proxy_service_->statistics_prefs()->GetList(
+ prefs::kDailyHttpReceivedContentLength);
original_update->Clear();
received_update->Clear();
for (size_t i = 0; i < kNumDaysInHistory; ++i) {
@@ -432,54 +233,15 @@ void DataReductionProxySettings::MaybeActivateDataReductionProxy(
ResetDataReductionStatistics();
}
// Configure use of the data reduction proxy if it is enabled.
- enabled_by_user_= IsDataReductionProxyEnabled();
- SetProxyConfigs(enabled_by_user_ && !disabled_on_vpn_,
- IsDataReductionProxyAlternativeEnabled(),
- restricted_by_carrier_,
- at_startup);
-
- // Check if the proxy has been restricted explicitly by the carrier.
- if (enabled_by_user_ && !disabled_on_vpn_ &&
- !(IsDataReductionProxyAlternativeEnabled() &&
- !params()->alternative_fallback_allowed())) {
- ProbeWhetherDataReductionProxyIsAvailable();
- }
-}
-
-void DataReductionProxySettings::SetProxyConfigs(bool enabled,
- bool alternative_enabled,
- bool restricted,
- bool at_startup) {
- DCHECK(thread_checker_.CalledOnValidThread());
- DCHECK(configurator_);
-
- LogProxyState(enabled, restricted, at_startup);
- // The alternative is only configured if the standard configuration is
- // is enabled.
- if (enabled & !params()->holdback()) {
- if (alternative_enabled) {
- configurator_->Enable(restricted,
- !params()->alternative_fallback_allowed(),
- params()->alt_origin().ToURI(),
- std::string(),
- params()->ssl_origin().ToURI());
- } else {
- configurator_->Enable(restricted,
- !params()->fallback_allowed(),
- params()->origin().ToURI(),
- params()->fallback_origin().ToURI(),
- std::string());
- }
- } else {
- configurator_->Disable();
- }
+ config_->SetProxyPrefs(IsDataReductionProxyEnabled(),
+ IsDataReductionProxyAlternativeEnabled(), at_startup);
}
// Metrics methods
void DataReductionProxySettings::RecordDataReductionInit() {
DCHECK(thread_checker_.CalledOnValidThread());
ProxyStartupState state = PROXY_NOT_AVAILABLE;
- if (params()->allowed()) {
+ if (allowed_) {
if (IsDataReductionProxyEnabled())
state = PROXY_ENABLED;
else
@@ -489,31 +251,19 @@ void DataReductionProxySettings::RecordDataReductionInit() {
RecordStartupState(state);
}
-void DataReductionProxySettings::RecordProbeURLFetchResult(
- ProbeURLFetchResult result) {
- UMA_HISTOGRAM_ENUMERATION(kUMAProxyProbeURL,
- result,
- PROBE_URL_FETCH_RESULT_COUNT);
-}
-
void DataReductionProxySettings::RecordStartupState(ProxyStartupState state) {
UMA_HISTOGRAM_ENUMERATION(kUMAProxyStartupStateHistogram,
state,
PROXY_STARTUP_STATE_COUNT);
}
-void DataReductionProxySettings::GetNetworkList(
- net::NetworkInterfaceList* interfaces,
- int policy) {
- net::GetNetworkList(interfaces, policy);
-}
-
DataReductionProxySettings::ContentLengthList
DataReductionProxySettings::GetDailyContentLengths(const char* pref_name) {
DCHECK(thread_checker_.CalledOnValidThread());
DataReductionProxySettings::ContentLengthList content_lengths;
- DCHECK(statistics_prefs_);
- const base::ListValue* list_value = statistics_prefs_->GetList(pref_name);
+ DCHECK(data_reduction_proxy_service_->statistics_prefs());
+ const base::ListValue* list_value =
+ data_reduction_proxy_service_->statistics_prefs()->GetList(pref_name);
if (list_value->GetSize() == kNumDaysInHistory) {
for (size_t i = 0; i < kNumDaysInHistory; ++i) {
content_lengths.push_back(GetInt64PrefValue(*list_value, i));
@@ -529,12 +279,14 @@ void DataReductionProxySettings::GetContentLengths(
int64* last_update_time) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_LE(days, kNumDaysInHistory);
- DCHECK(statistics_prefs_);
+ DCHECK(data_reduction_proxy_service_->statistics_prefs());
const base::ListValue* original_list =
- statistics_prefs_->GetList(prefs::kDailyHttpOriginalContentLength);
+ data_reduction_proxy_service_->statistics_prefs()->GetList(
+ prefs::kDailyHttpOriginalContentLength);
const base::ListValue* received_list =
- statistics_prefs_->GetList(prefs::kDailyHttpReceivedContentLength);
+ data_reduction_proxy_service_->statistics_prefs()->GetList(
+ prefs::kDailyHttpReceivedContentLength);
if (original_list->GetSize() != kNumDaysInHistory ||
received_list->GetSize() != kNumDaysInHistory) {
@@ -555,80 +307,8 @@ void DataReductionProxySettings::GetContentLengths(
*original_content_length = orig;
*received_content_length = recv;
*last_update_time =
- statistics_prefs_->GetInt64(prefs::kDailyHttpContentLengthLastUpdateDate);
-}
-
-net::URLFetcher* DataReductionProxySettings::GetBaseURLFetcher(
- const GURL& gurl,
- int load_flags) {
-
- net::URLFetcher* fetcher = net::URLFetcher::Create(gurl,
- net::URLFetcher::GET,
- this);
- fetcher->SetLoadFlags(load_flags);
- DCHECK(url_request_context_getter_);
- fetcher->SetRequestContext(url_request_context_getter_);
- // Configure max retries to be at most kMaxRetries times for 5xx errors.
- static const int kMaxRetries = 5;
- fetcher->SetMaxRetriesOn5xx(kMaxRetries);
- fetcher->SetAutomaticallyRetryOnNetworkChanges(kMaxRetries);
- return fetcher;
-}
-
-
-net::URLFetcher*
-DataReductionProxySettings::GetURLFetcherForAvailabilityCheck() {
- return GetBaseURLFetcher(params()->probe_url(),
- net::LOAD_DISABLE_CACHE | net::LOAD_BYPASS_PROXY);
-}
-
-
-void DataReductionProxySettings::ProbeWhetherDataReductionProxyIsAvailable() {
- net::URLFetcher* fetcher = GetURLFetcherForAvailabilityCheck();
- if (!fetcher)
- return;
- fetcher_.reset(fetcher);
-
- bound_net_log_ = net::BoundNetLog::Make(
- net_log_, net::NetLog::SOURCE_DATA_REDUCTION_PROXY);
- if (event_store_) {
- event_store_->BeginCanaryRequest(bound_net_log_,
- fetcher_->GetOriginalURL());
- }
-
- fetcher_->Start();
-}
-
-bool DataReductionProxySettings::DisableIfVPN() {
- net::NetworkInterfaceList network_interfaces;
- GetNetworkList(&network_interfaces, 0);
- // VPNs use a "tun" interface, so the presence of a "tun" interface indicates
- // a VPN is in use.
- // TODO(kundaji): Verify this works on Windows.
- const std::string vpn_interface_name_prefix = "tun";
- for (size_t i = 0; i < network_interfaces.size(); ++i) {
- std::string interface_name = network_interfaces[i].name;
- if (LowerCaseEqualsASCII(
- interface_name.begin(),
- interface_name.begin() + vpn_interface_name_prefix.size(),
- vpn_interface_name_prefix.c_str())) {
- SetProxyConfigs(false,
- IsDataReductionProxyAlternativeEnabled(),
- false,
- false);
- disabled_on_vpn_ = true;
- RecordNetworkChangeEvent(DISABLED_ON_VPN);
- return true;
- }
- }
- if (disabled_on_vpn_) {
- SetProxyConfigs(enabled_by_user_,
- IsDataReductionProxyAlternativeEnabled(),
- restricted_by_carrier_,
- false);
- }
- disabled_on_vpn_ = false;
- return false;
+ data_reduction_proxy_service_->statistics_prefs()->GetInt64(
+ prefs::kDailyHttpContentLengthLastUpdateDate);
}
} // namespace data_reduction_proxy
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h
index 17c2e52..f5b70a4 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h
@@ -14,28 +14,16 @@
#include "base/memory/scoped_ptr.h"
#include "base/prefs/pref_member.h"
#include "base/threading/thread_checker.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h"
-#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
-#include "net/base/net_log.h"
-#include "net/base/net_util.h"
-#include "net/base/network_change_notifier.h"
-#include "net/url_request/url_fetcher_delegate.h"
+#include "url/gurl.h"
class PrefService;
-namespace net {
-class HostPortPair;
-class HttpNetworkSession;
-class HttpResponseHeaders;
-class URLFetcher;
-class URLRequestContextGetter;
-}
-
namespace data_reduction_proxy {
+class DataReductionProxyConfig;
class DataReductionProxyEventStore;
+class DataReductionProxyIOData;
+class DataReductionProxyService;
class DataReductionProxyStatisticsPrefs;
// The number of days of bandwidth usage statistics that are tracked.
@@ -63,39 +51,20 @@ enum ProxyStartupState {
// be called from there.
// TODO(marq): Convert this to be a KeyedService with an
// associated factory class, and refactor the Java call sites accordingly.
-class DataReductionProxySettings
- : public net::URLFetcherDelegate,
- public net::NetworkChangeNotifier::IPAddressObserver {
+class DataReductionProxySettings {
public:
typedef std::vector<long long> ContentLengthList;
- static bool IsProxyKeySetOnCommandLine();
-
- DataReductionProxySettings(scoped_ptr<DataReductionProxyParams> params);
- ~DataReductionProxySettings() override;
-
- DataReductionProxyParams* params() const {
- return config_->params();
- }
+ DataReductionProxySettings();
+ virtual ~DataReductionProxySettings();
- // Initializes the data reduction proxy with profile and local state prefs,
- // and a |UrlRequestContextGetter| for canary probes. The caller must ensure
- // that all parameters remain alive for the lifetime of the
- // |DataReductionProxySettings| instance.
+ // Initializes the data reduction proxy with profile prefs and a
+ // |DataReductionProxyIOData|. The caller must ensure that all parameters
+ // remain alive for the lifetime of the |DataReductionProxySettings| instance.
void InitDataReductionProxySettings(
PrefService* prefs,
- scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs,
- net::URLRequestContextGetter* url_request_context_getter,
- net::NetLog* net_log,
- DataReductionProxyEventStore* event_store,
- bool enable_quic);
-
- // Constructs statistics prefs. This should not be called if a valid
- // statistics prefs is passed into the constructor.
- void EnableCompressionStatisticsLogging(
- PrefService* prefs,
- scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
- const base::TimeDelta& commit_delay);
+ DataReductionProxyIOData* io_data,
+ scoped_ptr<DataReductionProxyService> data_reduction_proxy_service);
base::WeakPtr<DataReductionProxyStatisticsPrefs> statistics_prefs();
@@ -104,11 +73,6 @@ class DataReductionProxySettings
void SetOnDataReductionEnabledCallback(
const base::Callback<void(bool)>& on_data_reduction_proxy_enabled);
- // Sets the logic the embedder uses to set the networking configuration that
- // causes traffic to be proxied.
- void SetProxyConfigurator(
- DataReductionProxyConfigurator* configurator);
-
// Returns true if the proxy is enabled.
bool IsDataReductionProxyEnabled();
@@ -118,9 +82,7 @@ class DataReductionProxySettings
// Returns true if the proxy is managed by an adminstrator's policy.
bool IsDataReductionProxyManaged();
- // Enables or disables the data reduction proxy. If a probe URL is available,
- // and a probe request fails at some point, the proxy won't be used until a
- // probe succeeds.
+ // Enables or disables the data reduction proxy.
void SetDataReductionProxyEnabled(bool enabled);
// Enables or disables the alternative data reduction proxy configuration.
@@ -156,11 +118,7 @@ class DataReductionProxySettings
ContentLengthList GetDailyContentLengths(const char* pref_name);
- // net::URLFetcherDelegate:
- void OnURLFetchComplete(const net::URLFetcher* source) override;
-
- // Configures data reduction proxy and makes a request to the probe URL to
- // determine server availability. |at_startup| is true when this method is
+ // Configures data reduction proxy. |at_startup| is true when this method is
// called in response to creating or loading a new profile.
void MaybeActivateDataReductionProxy(bool at_startup);
@@ -170,69 +128,60 @@ class DataReductionProxySettings
return event_store_;
}
- // Used for testing.
- void SetDataReductionProxyStatisticsPrefs(
- scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs);
+ // Returns true if the data reduction proxy configuration may be used.
+ bool Allowed() const {
+ return allowed_;
+ }
+
+ // Returns true if the alternative data reduction proxy configuration may be
+ // used.
+ bool AlternativeAllowed() const {
+ return alternative_allowed_;
+ }
+
+ // Returns true if the data reduction proxy promo may be shown.
+ // This is idependent of whether the data reduction proxy is allowed.
+ bool PromoAllowed() const {
+ return promo_allowed_;
+ }
+
+ // The data reduction proxy primary origin
+ const std::string PrimaryOrigin() const {
+ return primary_origin_;
+ }
+
+ DataReductionProxyService* data_reduction_proxy_service() {
+ return data_reduction_proxy_service_.get();
+ }
+
+ // Permits changing the underlying |DataReductionProxyConfig| without running
+ // the initialization loop.
+ void ResetConfigForTest(DataReductionProxyConfig* config) {
+ config_ = config;
+ }
protected:
void InitPrefMembers();
- // Returns a fetcher for the probe to check if OK for the proxy to use SPDY.
- // Virtual for testing.
- virtual net::URLFetcher* GetURLFetcherForAvailabilityCheck();
+ void UpdateConfigValues();
// Virtualized for unit test support.
virtual PrefService* GetOriginalProfilePrefs();
- // 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.
virtual void RecordDataReductionInit();
- virtual void AddDefaultProxyBypassRules();
-
- // Writes a warning to the log that is used in backend processing of
- // customer feedback. Virtual so tests can mock it for verification.
- virtual void LogProxyState(bool enabled, bool restricted, bool at_startup);
-
- // Virtualized for mocking. Records UMA containing the result of requesting
- // the probe URL.
- virtual void RecordProbeURLFetchResult(
- data_reduction_proxy::ProbeURLFetchResult result);
-
// Virtualized for mocking. Records UMA specifying whether the proxy was
// enabled or disabled at startup.
virtual void RecordStartupState(
data_reduction_proxy::ProxyStartupState state);
- // Virtualized for mocking. Returns the list of network interfaces in use.
- virtual void GetNetworkList(net::NetworkInterfaceList* interfaces,
- int policy);
-
- DataReductionProxyConfigurator* configurator() {
- return configurator_;
- }
-
private:
friend class DataReductionProxySettingsTestBase;
friend class DataReductionProxySettingsTest;
friend class DataReductionProxyTestContext;
FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
- TestAuthenticationInit);
- FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
- TestAuthHashGeneration);
- FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
- TestAuthHashGenerationWithOriginSetViaSwitch);
- FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
TestResetDataReductionStatistics);
FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
TestIsProxyEnabledOrManaged);
@@ -243,78 +192,45 @@ class DataReductionProxySettings
FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
TestMaybeActivateDataReductionProxy);
FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
- TestOnIPAddressChanged);
- FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
TestOnProxyEnabledPrefChange);
FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
TestInitDataReductionProxyOn);
FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
TestInitDataReductionProxyOff);
FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
- TestBypassList);
- FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
CheckInitMetricsWhenNotAllowed);
- FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
- TestSetProxyConfigs);
- FRIEND_TEST_ALL_PREFIXES(DataReductionProxySettingsTest,
- TestSetProxyConfigsHoldback);
-
- // NetworkChangeNotifier::IPAddressObserver:
- void OnIPAddressChanged() override;
void OnProxyEnabledPrefChange();
void OnProxyAlternativeEnabledPrefChange();
void ResetDataReductionStatistics();
- // Requests the proxy probe URL, if one is set. If unable to do so, disables
- // the proxy, if enabled. Otherwise enables the proxy if disabled by a probe
- // failure.
- void ProbeWhetherDataReductionProxyIsAvailable();
-
- // Disables use of the data reduction proxy on VPNs. Returns true if the
- // data reduction proxy has been disabled.
- bool DisableIfVPN();
-
- // Generic method to get a URL fetcher.
- net::URLFetcher* GetBaseURLFetcher(const GURL& gurl, int load_flags);
-
- std::string key_;
- bool restricted_by_carrier_;
- bool enabled_by_user_;
- bool disabled_on_vpn_;
bool unreachable_;
- scoped_ptr<net::URLFetcher> fetcher_;
-
- // A new BoundNetLog is created for each canary check so that we can correlate
- // the request begin/end phases.
- net::BoundNetLog bound_net_log_;
+ // The following values are cached in order to access the values on the
+ // correct thread.
+ bool allowed_;
+ bool alternative_allowed_;
+ bool promo_allowed_;
+ std::string primary_origin_;
BooleanPrefMember spdy_proxy_auth_enabled_;
BooleanPrefMember data_reduction_proxy_alternative_enabled_;
- PrefService* prefs_;
- scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs_;
-
- net::URLRequestContextGetter* url_request_context_getter_;
+ scoped_ptr<DataReductionProxyService> data_reduction_proxy_service_;
- // The caller must ensure that the |net_log_|, if set, outlives this instance.
- // It is used to create new instances of |bound_net_log_| on canary
- // requests.
- net::NetLog* net_log_;
+ PrefService* prefs_;
// The caller must ensure that the |event_store_| outlives this instance.
DataReductionProxyEventStore* event_store_;
- base::Callback<void(bool)> on_data_reduction_proxy_enabled_;
+ // The caller must ensure that the |config_| outlives this instance.
+ DataReductionProxyConfig* config_;
- DataReductionProxyConfigurator* configurator_;
+ base::Callback<void(bool)> on_data_reduction_proxy_enabled_;
base::ThreadChecker thread_checker_;
- scoped_ptr<DataReductionProxyConfig> config_;
-
DISALLOW_COPY_AND_ASSIGN(DataReductionProxySettings);
};
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc
index 0bc693d..ee292895 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc
@@ -6,17 +6,17 @@
#include "base/bind.h"
#include "base/command_line.h"
-#include "base/message_loop/message_loop.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/scoped_user_pref_update.h"
#include "base/strings/string_number_conversions.h"
-#include "base/test/test_simple_task_runner.h"
#include "base/time/time.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_test_utils.h"
-#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h"
-#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers_test_utils.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h"
@@ -26,29 +26,12 @@ using testing::Return;
namespace {
-const char kProbeURLWithOKResponse[] = "http://ok.org/";
-
const char kProxy[] = "proxy";
} // namespace
namespace data_reduction_proxy {
-namespace {
-
-ProbeURLFetchResult FetchResult(bool enabled, bool success) {
- if (enabled) {
- if (success)
- return SUCCEEDED_PROXY_ALREADY_ENABLED;
- return FAILED_PROXY_DISABLED;
- }
- if (success)
- return SUCCEEDED_PROXY_ENABLED;
- return FAILED_PROXY_ALREADY_DISABLED;
-}
-
-} // namespace
-
DataReductionProxySettingsTestBase::DataReductionProxySettingsTestBase()
: testing::Test() {
}
@@ -57,7 +40,17 @@ DataReductionProxySettingsTestBase::~DataReductionProxySettingsTestBase() {}
// testing::Test implementation:
void DataReductionProxySettingsTestBase::SetUp() {
- PrefRegistrySimple* registry = pref_service_.registry();
+ test_context_.reset(new DataReductionProxyTestContext(
+ DataReductionProxyParams::kAllowed |
+ DataReductionProxyParams::kFallbackAllowed |
+ DataReductionProxyParams::kPromoAllowed,
+ TestDataReductionProxyParams::HAS_EVERYTHING &
+ ~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
+ ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN,
+ DataReductionProxyTestContext::USE_MOCK_CONFIG |
+ DataReductionProxyTestContext::SKIP_SETTINGS_INITIALIZATION));
+
+ PrefRegistrySimple* registry = test_context_->pref_service()->registry();
registry->RegisterListPref(prefs::kDailyHttpOriginalContentLength);
registry->RegisterListPref(prefs::kDailyHttpReceivedContentLength);
registry->RegisterInt64Pref(prefs::kDailyHttpContentLengthLastUpdateDate,
@@ -68,16 +61,12 @@ void DataReductionProxySettingsTestBase::SetUp() {
registry->RegisterBooleanPref(prefs::kDataReductionProxyWasEnabledBefore,
false);
- event_store_.reset(new DataReductionProxyEventStore(
- scoped_refptr<base::TestSimpleTaskRunner>(
- new base::TestSimpleTaskRunner())));
-
//AddProxyToCommandLine();
ResetSettings(true, true, false, true, false);
- ListPrefUpdate original_update(&pref_service_,
+ ListPrefUpdate original_update(test_context_->pref_service(),
prefs::kDailyHttpOriginalContentLength);
- ListPrefUpdate received_update(&pref_service_,
+ ListPrefUpdate received_update(test_context_->pref_service(),
prefs::kDailyHttpReceivedContentLength);
for (int64 i = 0; i < kNumDaysInHistory; i++) {
original_update->Insert(0,
@@ -85,24 +74,9 @@ void DataReductionProxySettingsTestBase::SetUp() {
received_update->Insert(0, new base::StringValue(base::Int64ToString(i)));
}
last_update_time_ = base::Time::Now().LocalMidnight();
- scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs(
- new DataReductionProxyStatisticsPrefs(
- &pref_service_,
- scoped_refptr<base::TestSimpleTaskRunner>(
- new base::TestSimpleTaskRunner()),
- base::TimeDelta()));
- statistics_prefs->SetInt64(
+ settings_->data_reduction_proxy_service()->statistics_prefs()->SetInt64(
prefs::kDailyHttpContentLengthLastUpdateDate,
last_update_time_.ToInternalValue());
- settings_->SetDataReductionProxyStatisticsPrefs(
- statistics_prefs.Pass());
- expected_params_.reset(new TestDataReductionProxyParams(
- DataReductionProxyParams::kAllowed |
- DataReductionProxyParams::kFallbackAllowed |
- DataReductionProxyParams::kPromoAllowed,
- TestDataReductionProxyParams::HAS_EVERYTHING &
- ~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
- ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN));
}
template <class C>
@@ -123,20 +97,19 @@ void DataReductionProxySettingsTestBase::ResetSettings(bool allowed,
if (holdback)
flags |= DataReductionProxyParams::kHoldback;
MockDataReductionProxySettings<C>* settings =
- new MockDataReductionProxySettings<C>(flags);
+ new MockDataReductionProxySettings<C>();
+ settings->config_ = test_context_->config();
+ settings->data_reduction_proxy_service_ =
+ test_context_->CreateDataReductionProxyService();
+ test_context_->config()->ResetParamFlagsForTest(flags);
+ settings->UpdateConfigValues();
EXPECT_CALL(*settings, GetOriginalProfilePrefs())
.Times(AnyNumber())
- .WillRepeatedly(Return(&pref_service_));
+ .WillRepeatedly(Return(test_context_->pref_service()));
EXPECT_CALL(*settings, GetLocalStatePrefs())
.Times(AnyNumber())
- .WillRepeatedly(Return(&pref_service_));
- EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0);
- EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0);
+ .WillRepeatedly(Return(test_context_->pref_service()));
settings_.reset(settings);
- configurator_.reset(new TestDataReductionProxyConfigurator(
- scoped_refptr<base::TestSimpleTaskRunner>(
- new base::TestSimpleTaskRunner()), &net_log_, event_store_.get()));
- settings_->configurator_ = configurator_.get();
}
// Explicitly generate required instantiations.
@@ -148,146 +121,44 @@ DataReductionProxySettingsTestBase::ResetSettings<DataReductionProxySettings>(
bool promo_allowed,
bool holdback);
-template <class C>
-void DataReductionProxySettingsTestBase::SetProbeResult(
- const std::string& test_url,
- const std::string& response,
- ProbeURLFetchResult result,
- bool success,
- int expected_calls) {
- MockDataReductionProxySettings<C>* settings =
- static_cast<MockDataReductionProxySettings<C>*>(settings_.get());
- if (0 == expected_calls) {
- EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0);
- EXPECT_CALL(*settings, RecordProbeURLFetchResult(_)).Times(0);
- } else {
- EXPECT_CALL(*settings, RecordProbeURLFetchResult(result)).Times(1);
- EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck())
- .Times(expected_calls)
- .WillRepeatedly(Return(new net::FakeURLFetcher(
- GURL(test_url),
- settings,
- response,
- success ? net::HTTP_OK : net::HTTP_INTERNAL_SERVER_ERROR,
- success ? net::URLRequestStatus::SUCCESS :
- net::URLRequestStatus::FAILED)));
- }
-}
-
-// Explicitly generate required instantiations.
-template void
-DataReductionProxySettingsTestBase::SetProbeResult<DataReductionProxySettings>(
- const std::string& test_url,
- const std::string& response,
- ProbeURLFetchResult result,
- bool success,
- int expected_calls);
-
-void DataReductionProxySettingsTestBase::CheckProxyConfigs(
- bool expected_enabled,
- bool expected_restricted,
- bool expected_fallback_restricted) {
- TestDataReductionProxyConfigurator* config =
- static_cast<TestDataReductionProxyConfigurator*>(
- settings_->configurator_);
- ASSERT_EQ(expected_restricted, config->restricted());
- ASSERT_EQ(expected_fallback_restricted, config->fallback_restricted());
- ASSERT_EQ(expected_enabled, config->enabled());
-}
-
-void DataReductionProxySettingsTestBase::CheckProbe(
- bool initially_enabled,
- const std::string& probe_url,
- const std::string& response,
- bool request_succeeded,
+void DataReductionProxySettingsTestBase::ExpectSetProxyPrefs(
bool expected_enabled,
- bool expected_restricted,
- bool expected_fallback_restricted) {
- pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled,
- initially_enabled);
- if (initially_enabled)
- settings_->enabled_by_user_ = true;
- settings_->restricted_by_carrier_ = false;
- SetProbeResult(probe_url,
- response,
- FetchResult(initially_enabled,
- request_succeeded && (response == "OK")),
- request_succeeded,
- initially_enabled ? 1 : 0);
- settings_->MaybeActivateDataReductionProxy(false);
- base::MessageLoop::current()->RunUntilIdle();
- CheckProxyConfigs(expected_enabled,
- expected_restricted,
- expected_fallback_restricted);
-}
-
-void DataReductionProxySettingsTestBase::CheckProbeOnIPChange(
- const std::string& probe_url,
- const std::string& response,
- bool request_succeeded,
- bool expected_restricted,
- bool expected_fallback_restricted) {
- SetProbeResult(probe_url,
- response,
- FetchResult(!settings_->restricted_by_carrier_,
- request_succeeded && (response == "OK")),
- request_succeeded,
- 1);
- settings_->OnIPAddressChanged();
- base::MessageLoop::current()->RunUntilIdle();
- CheckProxyConfigs(true, expected_restricted, expected_fallback_restricted);
+ bool expected_alternate_enabled,
+ bool expected_at_startup) {
+ MockDataReductionProxyConfig* config =
+ static_cast<MockDataReductionProxyConfig*>(test_context_->config());
+ EXPECT_CALL(*config,
+ SetProxyPrefs(expected_enabled, expected_alternate_enabled,
+ expected_at_startup));
}
void DataReductionProxySettingsTestBase::CheckOnPrefChange(
bool enabled,
bool expected_enabled,
bool managed) {
- // Always have a sucessful probe for pref change tests.
- SetProbeResult(kProbeURLWithOKResponse,
- "OK",
- FetchResult(enabled, true),
- true,
- expected_enabled ? 1 : 0);
+ ExpectSetProxyPrefs(expected_enabled, false, false);
if (managed) {
- pref_service_.SetManagedPref(prefs::kDataReductionProxyEnabled,
- new base::FundamentalValue(enabled));
+ test_context_->pref_service()->SetManagedPref(
+ prefs::kDataReductionProxyEnabled, new base::FundamentalValue(enabled));
} else {
- pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled, enabled);
+ test_context_->pref_service()->SetBoolean(prefs::kDataReductionProxyEnabled,
+ enabled);
}
- base::MessageLoop::current()->RunUntilIdle();
+ test_context_->RunUntilIdle();
// Never expect the proxy to be restricted for pref change tests.
- CheckProxyConfigs(expected_enabled, false, false);
}
void DataReductionProxySettingsTestBase::CheckInitDataReductionProxy(
bool enabled_at_startup) {
- base::MessageLoopForUI loop;
- scoped_ptr<DataReductionProxyConfigurator> configurator(
- new TestDataReductionProxyConfigurator(
- scoped_refptr<base::TestSimpleTaskRunner>(
- new base::TestSimpleTaskRunner()), &net_log_,
- event_store_.get()));
- settings_->SetProxyConfigurator(configurator.get());
- scoped_refptr<net::TestURLRequestContextGetter> request_context =
- new net::TestURLRequestContextGetter(base::MessageLoopProxy::current());
-
- // Delete statistics prefs, otherwise the DCHECK in
- // InitDataReductionProxySettings fails.
- settings_->SetDataReductionProxyStatisticsPrefs(
- scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>());
settings_->InitDataReductionProxySettings(
- &pref_service_,
- scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>(),
- request_context.get(),
- &net_log_,
- event_store_.get(),
- false);
+ test_context_->pref_service(), test_context_->io_data(),
+ test_context_->CreateDataReductionProxyService());
settings_->SetOnDataReductionEnabledCallback(
base::Bind(&DataReductionProxySettingsTestBase::
RegisterSyntheticFieldTrialCallback,
base::Unretained(this)));
- base::MessageLoop::current()->RunUntilIdle();
+ test_context_->RunUntilIdle();
EXPECT_EQ(enabled_at_startup, proxy_enabled_);
}
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h
index ab8b06c..ced835e2 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h
@@ -8,7 +8,6 @@
#include "base/memory/scoped_ptr.h"
#include "base/prefs/testing_pref_service.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
-#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h"
#include "net/base/capturing_net_log.h"
#include "net/base/net_util.h"
#include "net/url_request/test_url_fetcher_factory.h"
@@ -23,52 +22,18 @@ namespace data_reduction_proxy {
class DataReductionProxyConfigurator;
class DataReductionProxyStatisticsPrefs;
+class DataReductionProxyTestContext;
+class MockDataReductionProxyConfig;
template <class C>
class MockDataReductionProxySettings : public C {
public:
- MockDataReductionProxySettings<C>() : DataReductionProxySettings(
- scoped_ptr<TestDataReductionProxyParams>(new TestDataReductionProxyParams(
- DataReductionProxyParams::kAllowed |
- DataReductionProxyParams::kFallbackAllowed |
- DataReductionProxyParams::kPromoAllowed,
- TestDataReductionProxyParams::HAS_EVERYTHING &
- ~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
- ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN)).Pass()) {}
- MockDataReductionProxySettings<C>(int flags)
- : C(scoped_ptr<TestDataReductionProxyParams>(
- new TestDataReductionProxyParams(flags,
- TestDataReductionProxyParams::HAS_EVERYTHING &
- ~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
- ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN))
- .Pass()) {}
- MOCK_METHOD0(GetURLFetcherForAvailabilityCheck, net::URLFetcher*());
+ MockDataReductionProxySettings<C>() : C() {
+ }
MOCK_METHOD0(GetOriginalProfilePrefs, PrefService*());
MOCK_METHOD0(GetLocalStatePrefs, PrefService*());
- MOCK_METHOD3(LogProxyState, void(
- bool enabled, bool restricted, bool at_startup));
- MOCK_METHOD1(RecordProbeURLFetchResult,
- void(ProbeURLFetchResult result));
MOCK_METHOD1(RecordStartupState,
void(ProxyStartupState state));
-
- // SetProxyConfigs should always call LogProxyState exactly once.
- virtual void SetProxyConfigs(bool enabled,
- bool alternative_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);
- }
- virtual void GetNetworkList(net::NetworkInterfaceList* interfaces,
- int policy) override {
- if (!network_interfaces_.get())
- return;
- for (size_t i = 0; i < network_interfaces_->size(); ++i)
- interfaces->push_back(network_interfaces_->at(i));
- }
-
- scoped_ptr<net::NetworkInterfaceList> network_interfaces_;
};
class DataReductionProxySettingsTestBase : public testing::Test {
@@ -97,33 +62,15 @@ class DataReductionProxySettingsTestBase : public testing::Test {
bool promo_allowed,
bool holdback) = 0;
- template <class C> void SetProbeResult(
- const std::string& test_url,
- const std::string& response,
- ProbeURLFetchResult state,
- bool success,
- int expected_calls);
- virtual void SetProbeResult(const std::string& test_url,
- const std::string& response,
- ProbeURLFetchResult result,
- bool success,
- int expected_calls) = 0;
-
- void CheckProxyConfigs(bool expected_enabled,
- bool expected_restricted,
- bool expected_fallback_restricted);
- void CheckProbe(bool initially_enabled,
- const std::string& probe_url,
- const std::string& response,
- bool request_success,
- bool expected_enabled,
- bool expected_restricted,
- bool expected_fallback_restricted);
- void CheckProbeOnIPChange(const std::string& probe_url,
- const std::string& response,
- bool request_success,
- bool expected_enabled,
- bool expected_fallback_restricted);
+ void ExpectSetProxyPrefs(bool expected_enabled,
+ bool expected_alternate_enabled,
+ bool expected_at_startup);
+
+ void CheckMaybeActivateDataReductionProxy(bool initially_enabled,
+ bool request_succeeded,
+ bool expected_enabled,
+ bool expected_restricted,
+ bool expected_fallback_restricted);
void CheckOnPrefChange(bool enabled, bool expected_enabled, bool managed);
void InitWithStatisticsPrefs();
void CheckInitDataReductionProxy(bool enabled_at_startup);
@@ -131,14 +78,10 @@ class DataReductionProxySettingsTestBase : public testing::Test {
proxy_enabled_ = proxy_enabled;
}
- TestingPrefServiceSimple pref_service_;
- scoped_ptr<DataReductionProxyConfigurator> configurator_;
+ scoped_ptr<DataReductionProxyTestContext> test_context_;
scoped_ptr<DataReductionProxySettings> settings_;
- scoped_ptr<TestDataReductionProxyParams> expected_params_;
base::Time last_update_time_;
bool proxy_enabled_;
- net::CapturingNetLog net_log_;
- scoped_ptr<DataReductionProxyEventStore> event_store_;
};
// Test implementations should be subclasses of an instantiation of this
@@ -157,19 +100,6 @@ class ConcreteDataReductionProxySettingsTest
return DataReductionProxySettingsTestBase::ResetSettings<C>(
allowed, fallback_allowed, alt_allowed, promo_allowed, holdback);
}
-
- virtual void SetProbeResult(const std::string& test_url,
- const std::string& response,
- ProbeURLFetchResult result,
- bool success,
- int expected_calls) override {
- return DataReductionProxySettingsTestBase::SetProbeResult<C>(
- test_url,
- response,
- result,
- success,
- expected_calls);
- }
};
} // namespace data_reduction_proxy
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc
index d36d686..93fec58 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_unittest.cc
@@ -6,12 +6,13 @@
#include "base/command_line.h"
#include "base/md5.h"
-#include "base/message_loop/message_loop.h"
#include "base/metrics/field_trial.h"
#include "base/strings/utf_string_conversions.h"
-#include "base/test/test_simple_task_runner.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_test_utils.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h"
@@ -20,18 +21,8 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
-namespace {
-
-const char kProbeURLWithOKResponse[] = "http://ok.org/";
-const char kProbeURLWithBadResponse[] = "http://bad.org/";
-const char kProbeURLWithNoResponse[] = "http://no.org/";
-
-} // namespace
-
namespace data_reduction_proxy {
-class DataReductionProxyStatisticsPrefs;
-
class BadEntropyProvider : public base::FieldTrial::EntropyProvider {
public:
~BadEntropyProvider() override {}
@@ -45,121 +36,26 @@ class BadEntropyProvider : public base::FieldTrial::EntropyProvider {
class DataReductionProxySettingsTest
: public ConcreteDataReductionProxySettingsTest<
DataReductionProxySettings> {
+ public:
+ void CheckMaybeActivateDataReductionProxy(bool initially_enabled,
+ bool request_succeeded,
+ bool expected_enabled,
+ bool expected_restricted,
+ bool expected_fallback_restricted) {
+ test_context_->pref_service()->SetBoolean(prefs::kDataReductionProxyEnabled,
+ initially_enabled);
+ test_context_->config()->SetStateForTest(initially_enabled, false,
+ !request_succeeded, false);
+ ExpectSetProxyPrefs(expected_enabled, false, false);
+ settings_->MaybeActivateDataReductionProxy(false);
+ test_context_->RunUntilIdle();
+ }
};
-TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyOrigin) {
- // SetUp() adds the origin to the command line, which should be returned here.
- std::string result =
- settings_->params()->origin().ToURI();
- EXPECT_EQ(expected_params_->DefaultOrigin(), result);
-}
-
-TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxyDevOrigin) {
- base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kDataReductionProxyDev, expected_params_->DefaultDevOrigin());
- ResetSettings(true, true, false, true, false);
- std::string result =
- settings_->params()->origin().ToURI();
- EXPECT_EQ(expected_params_->DefaultDevOrigin(), result);
-}
-
-
-TEST_F(DataReductionProxySettingsTest, TestGetDataReductionProxies) {
- DataReductionProxyParams::DataReductionProxyList proxies =
- expected_params_->GetAllowedProxies();
-
- unsigned int expected_proxy_size = 2u;
- EXPECT_EQ(expected_proxy_size, proxies.size());
-
- EXPECT_EQ(net::ProxyServer::FromURI(expected_params_->DefaultOrigin(),
- net::ProxyServer::SCHEME_HTTP),
- proxies[0]);
- EXPECT_EQ(net::ProxyServer::FromURI(expected_params_->DefaultFallbackOrigin(),
- net::ProxyServer::SCHEME_HTTP),
- proxies[1]);
-}
-
-TEST_F(DataReductionProxySettingsTest, TestSetProxyConfigs) {
- TestDataReductionProxyParams drp_params(
- DataReductionProxyParams::kAllowed |
- DataReductionProxyParams::kFallbackAllowed |
- DataReductionProxyParams::kPromoAllowed,
- TestDataReductionProxyParams::HAS_EVERYTHING &
- ~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
- ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN);
- base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kDataReductionProxyAlt, drp_params.DefaultAltOrigin());
- base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kDataReductionProxyAltFallback,
- drp_params.DefaultAltFallbackOrigin());
- base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kDataReductionSSLProxy, drp_params.DefaultSSLOrigin());
- ResetSettings(true, true, true, true, false);
- TestDataReductionProxyConfigurator* configurator =
- static_cast<TestDataReductionProxyConfigurator*>(
- settings_->configurator());
-
- settings_->SetProxyConfigs(true, true, false, false);
- EXPECT_TRUE(configurator->enabled());
- EXPECT_EQ(net::ProxyServer::FromURI(expected_params_->DefaultAltOrigin(),
- net::ProxyServer::SCHEME_HTTP),
- net::ProxyServer::FromURI(configurator->origin(),
- net::ProxyServer::SCHEME_HTTP));
- EXPECT_TRUE(
- net::ProxyServer::FromURI(expected_params_->DefaultAltFallbackOrigin(),
- net::ProxyServer::SCHEME_HTTP).is_valid());
- EXPECT_TRUE(configurator->fallback_origin().empty());
- EXPECT_EQ(net::ProxyServer::FromURI(expected_params_->DefaultSSLOrigin(),
- net::ProxyServer::SCHEME_HTTP),
- net::ProxyServer::FromURI(configurator->ssl_origin(),
- net::ProxyServer::SCHEME_HTTP));
-
- settings_->SetProxyConfigs(true, false, false, false);
- EXPECT_TRUE(configurator->enabled());
- EXPECT_EQ(net::ProxyServer::FromURI(drp_params.DefaultOrigin(),
- net::ProxyServer::SCHEME_HTTP),
- net::ProxyServer::FromURI(configurator->origin(),
- net::ProxyServer::SCHEME_HTTP));
- EXPECT_EQ(net::ProxyServer::FromURI(drp_params.DefaultFallbackOrigin(),
- net::ProxyServer::SCHEME_HTTP),
- net::ProxyServer::FromURI(
- configurator->fallback_origin(),
- net::ProxyServer::SCHEME_HTTP));
- EXPECT_TRUE(configurator->ssl_origin().empty());
-
- settings_->SetProxyConfigs(false, true, false, false);
- EXPECT_FALSE(configurator->enabled());
- EXPECT_TRUE(configurator->origin().empty());
- EXPECT_TRUE(configurator->fallback_origin().empty());
- EXPECT_TRUE(configurator->ssl_origin().empty());
-
- settings_->SetProxyConfigs(false, false, false, false);
- EXPECT_FALSE(configurator->enabled());
- EXPECT_TRUE(configurator->origin().empty());
- EXPECT_TRUE(configurator->fallback_origin().empty());
- EXPECT_TRUE(configurator->ssl_origin().empty());
-}
-
-TEST_F(DataReductionProxySettingsTest, TestSetProxyConfigsHoldback) {
- ResetSettings(true, true, true, true, true);
- TestDataReductionProxyConfigurator* configurator =
- static_cast<TestDataReductionProxyConfigurator*>(
- settings_->configurator());
-
- // Holdback.
- settings_->SetProxyConfigs(true, true, false, false);
- EXPECT_FALSE(configurator->enabled());
- EXPECT_EQ("", configurator->origin());
- EXPECT_EQ("", configurator->fallback_origin());
- EXPECT_EQ("", configurator->ssl_origin());
-}
-
TEST_F(DataReductionProxySettingsTest, TestIsProxyEnabledOrManaged) {
settings_->InitPrefMembers();
- base::MessageLoopForUI loop;
// The proxy is disabled initially.
- settings_->enabled_by_user_ = false;
- settings_->SetProxyConfigs(false, false, false, false);
+ test_context_->config()->SetStateForTest(false, false, false, false);
EXPECT_FALSE(settings_->IsDataReductionProxyEnabled());
EXPECT_FALSE(settings_->IsDataReductionProxyManaged());
@@ -172,7 +68,7 @@ TEST_F(DataReductionProxySettingsTest, TestIsProxyEnabledOrManaged) {
EXPECT_TRUE(settings_->IsDataReductionProxyEnabled());
EXPECT_TRUE(settings_->IsDataReductionProxyManaged());
- base::MessageLoop::current()->RunUntilIdle();
+ test_context_->RunUntilIdle();
}
TEST_F(DataReductionProxySettingsTest, TestResetDataReductionStatistics) {
@@ -252,121 +148,22 @@ TEST_F(DataReductionProxySettingsTest, TestMaybeActivateDataReductionProxy) {
settings_->GetOriginalProfilePrefs());
// TODO(bengr): Test enabling/disabling while a probe is outstanding.
- base::MessageLoopForUI loop;
// The proxy is enabled and unrestructed initially.
// Request succeeded but with bad response, expect proxy to be restricted.
- CheckProbe(true,
- kProbeURLWithBadResponse,
- "Bad",
- true,
- true,
- true,
- false);
+ CheckMaybeActivateDataReductionProxy(true, true, true, true, false);
// Request succeeded with valid response, expect proxy to be unrestricted.
- CheckProbe(true,
- kProbeURLWithOKResponse,
- "OK",
- true,
- true,
- false,
- false);
+ CheckMaybeActivateDataReductionProxy(true, true, true, false, false);
// Request failed, expect proxy to be enabled but restricted.
- CheckProbe(true,
- kProbeURLWithNoResponse,
- "",
- false,
- true,
- true,
- false);
+ CheckMaybeActivateDataReductionProxy(true, false, true, true, false);
// The proxy is disabled initially. Probes should not be emitted to change
// state.
- CheckProbe(false,
- kProbeURLWithOKResponse,
- "OK",
- true,
- false,
- false,
- false);
-}
-
-TEST_F(DataReductionProxySettingsTest, TestOnIPAddressChanged) {
- 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);
- // IP address change triggers a probe that succeeds. Proxy remains
- // unrestricted.
- CheckProbeOnIPChange(kProbeURLWithOKResponse,
- "OK",
- true,
- false,
- false);
- // IP address change triggers a probe that fails. Proxy is restricted.
- CheckProbeOnIPChange(kProbeURLWithBadResponse,
- "Bad",
- true,
- true,
- false);
- // IP address change triggers a probe that fails. Proxy remains restricted.
- CheckProbeOnIPChange(kProbeURLWithBadResponse,
- "Bad",
- true,
- true,
- false);
- // IP address change triggers a probe that succeeds. Proxy is unrestricted.
- CheckProbeOnIPChange(kProbeURLWithOKResponse,
- "OK",
- true,
- false,
- false);
- // Simulate a VPN connection. The proxy should be disabled.
- MockSettings* settings = static_cast<MockSettings*>(settings_.get());
- settings->network_interfaces_.reset(new net::NetworkInterfaceList());
- settings->network_interfaces_->push_back(net::NetworkInterface(
- "tun0", /* network interface name */
- "tun0", /* network interface friendly name */
- 0, /* interface index */
- net::NetworkChangeNotifier::CONNECTION_WIFI,
- net::IPAddressNumber(), /* IP address */
- 0, /* network prefix */
- net::IP_ADDRESS_ATTRIBUTE_NONE /* ip address attribute */
- ));
- settings_->OnIPAddressChanged();
- base::MessageLoop::current()->RunUntilIdle();
- CheckProxyConfigs(false, false, false);
-
- // Check that the proxy is re-enabled if a non-VPN connection is later used.
- settings->network_interfaces_.reset(new net::NetworkInterfaceList());
- settings->network_interfaces_->push_back(net::NetworkInterface(
- "eth0", /* network interface name */
- "eth0", /* network interface friendly name */
- 0, /* interface index */
- net::NetworkChangeNotifier::CONNECTION_WIFI,
- net::IPAddressNumber(),
- 0, /* network prefix */
- net::IP_ADDRESS_ATTRIBUTE_NONE /* ip address attribute */
- ));
- CheckProbeOnIPChange(kProbeURLWithOKResponse,
- "OK",
- true,
- false,
- false);
+ CheckMaybeActivateDataReductionProxy(false, true, false, false, false);
}
TEST_F(DataReductionProxySettingsTest, TestOnProxyEnabledPrefChange) {
settings_->InitPrefMembers();
- base::MessageLoopForUI loop;
// The proxy is enabled initially.
- settings_->enabled_by_user_ = true;
- settings_->SetProxyConfigs(true, false, false, true);
+ test_context_->config()->SetStateForTest(true, false, 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.
@@ -377,7 +174,8 @@ TEST_F(DataReductionProxySettingsTest, TestInitDataReductionProxyOn) {
MockSettings* settings = static_cast<MockSettings*>(settings_.get());
EXPECT_CALL(*settings, RecordStartupState(PROXY_ENABLED));
- pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled, true);
+ test_context_->pref_service()->SetBoolean(prefs::kDataReductionProxyEnabled,
+ true);
CheckInitDataReductionProxy(true);
}
@@ -387,7 +185,8 @@ TEST_F(DataReductionProxySettingsTest, TestInitDataReductionProxyOff) {
MockSettings* settings = static_cast<MockSettings*>(settings_.get());
EXPECT_CALL(*settings, RecordStartupState(PROXY_DISABLED));
- pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled, false);
+ test_context_->pref_service()->SetBoolean(prefs::kDataReductionProxyEnabled,
+ false);
CheckInitDataReductionProxy(false);
}
@@ -417,36 +216,23 @@ TEST_F(DataReductionProxySettingsTest, TestGetDailyContentLengths) {
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.
base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
ResetSettings(false, false, false, false, false);
MockSettings* settings = static_cast<MockSettings*>(settings_.get());
- EXPECT_FALSE(settings->params()->allowed());
+ EXPECT_FALSE(settings->allowed_);
EXPECT_CALL(*settings, RecordStartupState(PROXY_NOT_AVAILABLE));
- scoped_ptr<DataReductionProxyConfigurator> configurator(
- new TestDataReductionProxyConfigurator(
- scoped_refptr<base::TestSimpleTaskRunner>(
- new base::TestSimpleTaskRunner()),
- &net_log_, event_store_.get()));
- settings_->SetProxyConfigurator(configurator.get());
- scoped_refptr<net::TestURLRequestContextGetter> request_context =
- new net::TestURLRequestContextGetter(base::MessageLoopProxy::current());
settings_->InitDataReductionProxySettings(
- &pref_service_,
- scoped_ptr<DataReductionProxyStatisticsPrefs>(),
- request_context.get(),
- &net_log_,
- event_store_.get(),
- false);
+ test_context_->pref_service(), test_context_->io_data(),
+ test_context_->CreateDataReductionProxyService());
settings_->SetOnDataReductionEnabledCallback(
base::Bind(&DataReductionProxySettingsTestBase::
RegisterSyntheticFieldTrialCallback,
base::Unretained(this)));
- base::MessageLoop::current()->RunUntilIdle();
+ test_context_->RunUntilIdle();
}
TEST_F(DataReductionProxySettingsTest, CheckQUICFieldTrials) {
@@ -454,31 +240,17 @@ TEST_F(DataReductionProxySettingsTest, CheckQUICFieldTrials) {
bool enable_quic = i == 0;
// 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.
base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL);
ResetSettings(false, false, false, false, false);
MockSettings* settings = static_cast<MockSettings*>(settings_.get());
- EXPECT_FALSE(settings->params()->allowed());
+ EXPECT_FALSE(settings->Allowed());
EXPECT_CALL(*settings, RecordStartupState(PROXY_NOT_AVAILABLE));
- scoped_ptr<DataReductionProxyConfigurator> configurator(
- new TestDataReductionProxyConfigurator(
- scoped_refptr<base::TestSimpleTaskRunner>(
- new base::TestSimpleTaskRunner()),
- &net_log_, event_store_.get()));
- settings_->SetProxyConfigurator(configurator.get());
- scoped_refptr<net::TestURLRequestContextGetter> request_context =
- new net::TestURLRequestContextGetter(base::MessageLoopProxy::current());
-
settings_->InitDataReductionProxySettings(
- &pref_service_,
- scoped_ptr<DataReductionProxyStatisticsPrefs>(),
- request_context.get(),
- &net_log_,
- event_store_.get(),
- false);
+ test_context_->pref_service(), test_context_->io_data(),
+ test_context_->CreateDataReductionProxyService());
base::FieldTrialList field_trial_list(new BadEntropyProvider());
if (enable_quic) {
@@ -490,7 +262,7 @@ TEST_F(DataReductionProxySettingsTest, CheckQUICFieldTrials) {
DataReductionProxyParams::GetQuicFieldTrialName(),
"Disabled");
}
- settings_->params()->EnableQuic(enable_quic);
+ test_context_->config()->params()->EnableQuic(enable_quic);
settings_->SetOnDataReductionEnabledCallback(
base::Bind(&DataReductionProxySettingsTestBase::
@@ -498,7 +270,7 @@ TEST_F(DataReductionProxySettingsTest, CheckQUICFieldTrials) {
base::Unretained(this)));
EXPECT_EQ(enable_quic,
- settings->params()->origin().is_quic()) << i;
+ test_context_->config()->params()->origin().is_quic()) << i;
}
}
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc
index b9dbb69..cb081ac 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.cc
@@ -16,15 +16,25 @@
namespace data_reduction_proxy {
-TestDataReductionProxyIOData::TestDataReductionProxyIOData(
+MockDataReductionProxyService::MockDataReductionProxyService(
+ scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs,
DataReductionProxySettings* settings,
+ net::URLRequestContextGetter* request_context)
+ : DataReductionProxyService(
+ statistics_prefs.Pass(), settings, request_context) {
+}
+
+MockDataReductionProxyService::~MockDataReductionProxyService() {
+}
+
+TestDataReductionProxyIOData::TestDataReductionProxyIOData(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
+ scoped_ptr<TestDataReductionProxyConfig> config,
scoped_ptr<DataReductionProxyEventStore> event_store,
scoped_ptr<DataReductionProxyRequestOptions> request_options,
scoped_ptr<DataReductionProxyConfigurator> configurator)
: DataReductionProxyIOData() {
- settings_ = settings;
- params_ = settings_->params()->Clone();
+ config_ = config.Pass();
event_store_ = event_store.Pass();
request_options_ = request_options.Pass();
configurator_ = configurator.Pass();
@@ -44,7 +54,7 @@ DataReductionProxyTestContext::DataReductionProxyTestContext(
task_runner_(base::MessageLoopProxy::current()),
request_context_(scoped_refptr<net::URLRequestContextGetter>(
new net::TestURLRequestContextGetter(task_runner_))),
- statistics_prefs_pointer_(nullptr) {
+ service_(nullptr) {
scoped_ptr<DataReductionProxyEventStore> event_store =
make_scoped_ptr(new DataReductionProxyEventStore(task_runner_));
scoped_ptr<DataReductionProxyConfigurator> configurator;
@@ -59,33 +69,37 @@ DataReductionProxyTestContext::DataReductionProxyTestContext(
scoped_ptr<TestDataReductionProxyConfig> config;
if (test_context_flags_ & DataReductionProxyTestContext::USE_MOCK_CONFIG) {
- config.reset(new MockDataReductionProxyConfig(params_flags));
+ config.reset(new MockDataReductionProxyConfig(
+ params_flags, params_definitions, task_runner_, &net_log_,
+ configurator.get(), event_store.get()));
} else {
- config.reset(new TestDataReductionProxyConfig(params_flags));
+ config.reset(new TestDataReductionProxyConfig(
+ params_flags, params_definitions, task_runner_, &net_log_,
+ configurator.get(), event_store.get()));
}
-
- settings_.reset(new DataReductionProxySettings(make_scoped_ptr(
- new DataReductionProxyParams(params_flags))));
- settings_->config_ = config.Pass();
-
scoped_ptr<DataReductionProxyRequestOptions> request_options =
make_scoped_ptr(new DataReductionProxyRequestOptions(
- Client::UNKNOWN, settings_->config_->params(), task_runner_));
+ Client::UNKNOWN, config->params(), task_runner_));
+ settings_.reset(new DataReductionProxySettings());
+
io_data_.reset(new TestDataReductionProxyIOData(
- settings_.get(), task_runner_.get(), event_store.Pass(),
+ task_runner_.get(), config.Pass(), event_store.Pass(),
request_options.Pass(), configurator.Pass()));
- settings_->config_->InitDataReductionProxyConfig(
- task_runner_, &net_log_, request_context_.get(),
- io_data_->configurator(), io_data_->event_store());
if (!(test_context_flags_ &
DataReductionProxyTestContext::SKIP_SETTINGS_INITIALIZATION)) {
scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs =
make_scoped_ptr(new DataReductionProxyStatisticsPrefs(
&simple_pref_service_, task_runner_, base::TimeDelta()));
- statistics_prefs_pointer_ = statistics_prefs.get();
- io_data_->SetDataReductionProxyStatisticsPrefs(
- statistics_prefs_pointer_->GetWeakPtr());
+ scoped_ptr<MockDataReductionProxyService> data_reduction_proxy_service =
+ make_scoped_ptr(new MockDataReductionProxyService(
+ statistics_prefs.Pass(), settings_.get(), request_context_.get()));
+ service_ = data_reduction_proxy_service.get();
+ settings_->data_reduction_proxy_service_ =
+ data_reduction_proxy_service.Pass();
+ io_data_->SetDataReductionProxyService(service_->GetWeakPtr());
}
+
+ settings_->config_ = io_data_->config();
}
DataReductionProxyTestContext::~DataReductionProxyTestContext() {
@@ -99,17 +113,22 @@ void DataReductionProxyTestContext::InitSettings() {
DCHECK(test_context_flags_ &
DataReductionProxyTestContext::SKIP_SETTINGS_INITIALIZATION);
settings_->InitDataReductionProxySettings(
- &simple_pref_service_, CreateStatisticsPrefs(), request_context_.get(),
- io_data_->net_log(), io_data_->event_store(), false);
- io_data_->SetDataReductionProxyStatisticsPrefs(settings_->statistics_prefs());
+ &simple_pref_service_, io_data_.get(), CreateDataReductionProxyService());
+ io_data_->SetDataReductionProxyService(
+ settings_->data_reduction_proxy_service()->GetWeakPtr());
}
-scoped_ptr<DataReductionProxyStatisticsPrefs>
-DataReductionProxyTestContext::CreateStatisticsPrefs() {
+scoped_ptr<MockDataReductionProxyService>
+DataReductionProxyTestContext::CreateDataReductionProxyService() {
DCHECK(test_context_flags_ &
DataReductionProxyTestContext::SKIP_SETTINGS_INITIALIZATION);
- return make_scoped_ptr(new DataReductionProxyStatisticsPrefs(
- &simple_pref_service_, task_runner_, base::TimeDelta()));
+ scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs =
+ make_scoped_ptr(new DataReductionProxyStatisticsPrefs(
+ &simple_pref_service_, task_runner_, base::TimeDelta()));
+ scoped_ptr<MockDataReductionProxyService> service =
+ make_scoped_ptr(new MockDataReductionProxyService(
+ statistics_prefs.Pass(), settings_.get(), request_context_.get()));
+ return service.Pass();
}
TestDataReductionProxyConfigurator*
@@ -123,16 +142,15 @@ DataReductionProxyTestContext::test_configurator() const {
MockDataReductionProxyConfig* DataReductionProxyTestContext::mock_config()
const {
DCHECK(test_context_flags_ & DataReductionProxyTestContext::USE_MOCK_CONFIG);
- return reinterpret_cast<MockDataReductionProxyConfig*>(
- settings_->config_.get());
+ return reinterpret_cast<MockDataReductionProxyConfig*>(io_data_->config());
}
-DataReductionProxyStatisticsPrefs*
-DataReductionProxyTestContext::statistics_prefs()
+MockDataReductionProxyService*
+DataReductionProxyTestContext::data_reduction_proxy_service()
const {
DCHECK(!(test_context_flags_ &
DataReductionProxyTestContext::SKIP_SETTINGS_INITIALIZATION));
- return statistics_prefs_pointer_;
+ return service_;
}
} // namespace data_reduction_proxy
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h
index e1d0b4b..3c0b30e 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h
@@ -7,6 +7,7 @@
#include "base/macros.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.h"
#include "net/base/capturing_net_log.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -34,14 +35,28 @@ class MockDataReductionProxyConfig;
class TestDataReductionProxyConfig;
class TestDataReductionProxyConfigurator;
+// Test version of |DataReductionProxyService|, which permits mocking of various
+// methods.
+class MockDataReductionProxyService : public DataReductionProxyService {
+ public:
+ MockDataReductionProxyService(
+ scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs,
+ DataReductionProxySettings* settings,
+ net::URLRequestContextGetter* request_context);
+ ~MockDataReductionProxyService() override;
+
+ MOCK_METHOD2(CheckProbeURL,
+ void(const GURL& probe_url, FetcherResponseCallback fetcher_callback));
+};
+
// Test version of |DataReductionProxyIOData|, which bypasses initialization in
// the constructor in favor of explicitly passing in its owned classes. This
// permits the use of test/mock versions of those classes.
class TestDataReductionProxyIOData : public DataReductionProxyIOData {
public:
TestDataReductionProxyIOData(
- DataReductionProxySettings* settings,
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
+ scoped_ptr<TestDataReductionProxyConfig> config,
scoped_ptr<DataReductionProxyEventStore> event_store,
scoped_ptr<DataReductionProxyRequestOptions> request_options,
scoped_ptr<DataReductionProxyConfigurator> configurator);
@@ -50,10 +65,6 @@ class TestDataReductionProxyIOData : public DataReductionProxyIOData {
DataReductionProxyConfigurator* configurator() const {
return configurator_.get();
}
-
- TestDataReductionProxyParams* test_params() const {
- return reinterpret_cast<TestDataReductionProxyParams*>(params_.get());
- }
};
// Builds a test version of the Data Reduction Proxy stack for use in tests.
@@ -93,9 +104,9 @@ class DataReductionProxyTestContext {
// |SKIP_SETTINGS_INITIALIZATION| was specified.
void InitSettings();
- // Creates a |DataReductionProxyStatisticsPrefs| object. Can only be called if
+ // Creates a |MockDataReductionProxyService| object. Can only be called if
// |SKIP_SETTINGS_INITIALIZATION| was specified.
- scoped_ptr<DataReductionProxyStatisticsPrefs> CreateStatisticsPrefs();
+ scoped_ptr<MockDataReductionProxyService> CreateDataReductionProxyService();
// Returns the underlying |TestDataReductionProxyConfigurator|. This can only
// be called if |USE_TEST_CONFIGURATOR| was specified.
@@ -105,9 +116,9 @@ class DataReductionProxyTestContext {
// called if |USE_MOCK_CONFIG| was specified.
MockDataReductionProxyConfig* mock_config() const;
- // Returns the underlying |DataReductionProxyStatisticsPrefs|. This can only
+ // Returns the underlying |MockDataReductionProxyService|. This can only
// be called if |SKIP_SETTINGS_INITIALIZATION| was not specified.
- DataReductionProxyStatisticsPrefs* statistics_prefs() const;
+ MockDataReductionProxyService* data_reduction_proxy_service() const;
scoped_refptr<base::SingleThreadTaskRunner> task_runner() const {
return task_runner_;
@@ -134,8 +145,7 @@ class DataReductionProxyTestContext {
}
TestDataReductionProxyConfig* config() const {
- return reinterpret_cast<TestDataReductionProxyConfig*>(
- settings_->config_.get());
+ return reinterpret_cast<TestDataReductionProxyConfig*>(io_data_->config());
}
TestDataReductionProxyIOData* io_data() const {
@@ -159,7 +169,7 @@ class DataReductionProxyTestContext {
scoped_ptr<TestDataReductionProxyIOData> io_data_;
scoped_ptr<DataReductionProxySettings> settings_;
- DataReductionProxyStatisticsPrefs* statistics_prefs_pointer_;
+ MockDataReductionProxyService* service_;
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyTestContext);
};
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.cc
index ef14fbd..4fb9547 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.cc
@@ -10,6 +10,7 @@
#include "base/metrics/sparse_histogram.h"
#include "base/prefs/pref_member.h"
#include "base/single_thread_task_runner.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_tamper_detection.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h"
@@ -104,10 +105,10 @@ void DataReductionProxyUsageStats::DetectAndRecordMissingViaHeaderResponseCode(
DataReductionProxyUsageStats::DataReductionProxyUsageStats(
DataReductionProxyParams* params,
- DataReductionProxySettings* settings,
+ base::WeakPtr<DataReductionProxyService> service,
const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner)
: data_reduction_proxy_params_(params),
- settings_(settings),
+ service_(service),
last_bypass_type_(BYPASS_EVENT_TYPE_MAX),
triggering_request_(true),
ui_task_runner_(ui_task_runner),
@@ -115,7 +116,6 @@ DataReductionProxyUsageStats::DataReductionProxyUsageStats(
proxy_net_errors_count_(0),
unavailable_(false) {
DCHECK(params);
- DCHECK(settings);
NetworkChangeNotifier::AddNetworkChangeObserver(this);
};
@@ -386,7 +386,8 @@ void DataReductionProxyUsageStats::NotifyUnavailabilityIfChanged() {
void DataReductionProxyUsageStats::NotifyUnavailabilityOnUIThread(
bool unavailable) {
DCHECK(ui_task_runner_->BelongsToCurrentThread());
- settings_->SetUnreachable(unavailable);
+ if (service_)
+ service_->settings()->SetUnreachable(unavailable);
}
void DataReductionProxyUsageStats::RecordBypassedBytes(
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h
index 5e159e7..8636d69 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h
@@ -6,6 +6,7 @@
#define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_USAGE_STATS_H_
#include "base/callback.h"
+#include "base/memory/weak_ptr.h"
#include "base/prefs/pref_member.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_checker.h"
@@ -23,7 +24,7 @@ class ProxyServer;
namespace data_reduction_proxy {
-class DataReductionProxySettings;
+class DataReductionProxyService;
// TODO(bengr): Rename as DataReductionProxyBypassStats.
class DataReductionProxyUsageStats
@@ -45,13 +46,12 @@ class DataReductionProxyUsageStats
bool is_primary,
const net::HttpResponseHeaders* headers);
- // |params| outlives this class instance. |settings| provides a hook to inform
+ // |params| outlives this class instance. |service| provides a hook to inform
// the user that the Data Reduction Proxy is unreachable, which occurs on the
- // UI thread, hence the |ui_task_runner|. |settings| and |params| must not be
- // null.
+ // UI thread, hence the |ui_task_runner|. |params| must not be null.
DataReductionProxyUsageStats(
DataReductionProxyParams* params,
- DataReductionProxySettings* settings,
+ base::WeakPtr<DataReductionProxyService> service,
const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner);
~DataReductionProxyUsageStats() override;
@@ -137,7 +137,7 @@ class DataReductionProxyUsageStats
DataReductionProxyParams* data_reduction_proxy_params_;
- DataReductionProxySettings* settings_;
+ base::WeakPtr<DataReductionProxyService> service_;
// The last reason for bypass as determined by
// MaybeBypassProxyAndPrepareToRetry
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats_unittest.cc
index 8518980..8683a27 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats_unittest.cc
@@ -182,7 +182,8 @@ TEST_F(DataReductionProxyUsageStatsTest, IsDataReductionProxyUnreachable) {
scoped_ptr<DataReductionProxyUsageStats> usage_stats(
new DataReductionProxyUsageStats(
- &mock_params_, test_context_->settings(),
+ &mock_params_,
+ test_context_->data_reduction_proxy_service()->GetWeakPtr(),
test_context_->task_runner()));
usage_stats->OnProxyFallback(fallback_proxy_server,
@@ -199,7 +200,8 @@ TEST_F(DataReductionProxyUsageStatsTest, ProxyUnreachableThenReachable) {
net::ProxyServer::FromURI("foo.com", net::ProxyServer::SCHEME_HTTP);
scoped_ptr<DataReductionProxyUsageStats> usage_stats(
new DataReductionProxyUsageStats(
- &mock_params_, test_context_->settings(),
+ &mock_params_,
+ test_context_->data_reduction_proxy_service()->GetWeakPtr(),
test_context_->task_runner()));
EXPECT_CALL(mock_params_, IsDataReductionProxy(testing::_, testing::_))
.WillOnce(testing::Return(true));
@@ -224,7 +226,8 @@ TEST_F(DataReductionProxyUsageStatsTest, ProxyReachableThenUnreachable) {
net::ProxyServer::FromURI("foo.com", net::ProxyServer::SCHEME_HTTP);
scoped_ptr<DataReductionProxyUsageStats> usage_stats(
new DataReductionProxyUsageStats(
- &mock_params_, test_context_->settings(),
+ &mock_params_,
+ test_context_->data_reduction_proxy_service()->GetWeakPtr(),
test_context_->task_runner()));
EXPECT_CALL(mock_params_,
WasDataReductionProxyUsed(mock_url_request_.get(), testing::_))
@@ -430,7 +433,8 @@ TEST_F(DataReductionProxyUsageStatsTest, RecordMissingViaHeaderBytes) {
base::HistogramTester histogram_tester;
scoped_ptr<DataReductionProxyUsageStats> usage_stats(
new DataReductionProxyUsageStats(
- &mock_params_, test_context_->settings(),
+ &mock_params_,
+ test_context_->data_reduction_proxy_service()->GetWeakPtr(),
test_context_->task_runner()));
std::string raw_headers(test_cases[i].headers);
@@ -500,7 +504,8 @@ TEST_F(DataReductionProxyUsageStatsTest, RequestCompletionErrorCodes) {
base::HistogramTester histogram_tester;
scoped_ptr<DataReductionProxyUsageStats> usage_stats(
new DataReductionProxyUsageStats(
- &mock_params_, test_context_->settings(),
+ &mock_params_,
+ test_context_->data_reduction_proxy_service()->GetWeakPtr(),
test_context_->task_runner()));
std::string raw_headers("HTTP/1.1 200 OK\n"
@@ -591,13 +596,7 @@ class DataReductionProxyUsageStatsEndToEndTest : public testing::Test {
enabled.SetValue(true);
enabled.Destroy();
- settings()->SetProxyConfigurator(test_context_->configurator());
- settings()->InitDataReductionProxySettings(
- test_context_->pref_service(), test_context_->CreateStatisticsPrefs(),
- test_context_->request_context(), test_context_->net_log(),
- test_context_->event_store(), false);
- test_context_->io_data()->SetDataReductionProxyStatisticsPrefs(
- settings()->statistics_prefs());
+ test_context_->InitSettings();
network_delegate_ = test_context_->io_data()->CreateNetworkDelegate(
scoped_ptr<net::NetworkDelegate>(new net::TestNetworkDelegate()), true);
@@ -674,7 +673,7 @@ class DataReductionProxyUsageStatsEndToEndTest : public testing::Test {
context_.set_host_resolver(host_resolver);
}
- DataReductionProxySettings* settings() const {
+ const DataReductionProxySettings* settings() const {
return test_context_->settings();
}
@@ -942,7 +941,7 @@ TEST_F(DataReductionProxyUsageStatsEndToEndTest, BypassedBytesNetErrorOther) {
// Make the data reduction proxy host fail to resolve.
scoped_ptr<net::MockHostResolver> host_resolver(new net::MockHostResolver());
host_resolver->rules()->AddSimulatedFailure(
- settings()->params()->origin().host_port_pair().host());
+ params()->origin().host_port_pair().host());
set_host_resolver(host_resolver.get());
InitializeContext();