summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbengr@chromium.org <bengr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-08 09:50:46 +0000
committerbengr@chromium.org <bengr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-08 09:52:25 +0000
commitf4bfa767edafe51e6780dfac3b80ff55c1fcf31b (patch)
tree013c9ff4e9d5dd158b07f7b2307bcc4ce7968667
parent10e75e406dae19310d52a548d39a4db4c694eeab (diff)
downloadchromium_src-f4bfa767edafe51e6780dfac3b80ff55c1fcf31b.zip
chromium_src-f4bfa767edafe51e6780dfac3b80ff55c1fcf31b.tar.gz
chromium_src-f4bfa767edafe51e6780dfac3b80ff55c1fcf31b.tar.bz2
Moved data reduction proxy initialization logic from ProfileIOData,
where it would be available to all profiles, including Incognito, to ProfileImplIOData, where it would only be available to non- Incognito profiles. In the process, (1) refactored and simplified DataReductionProxyUsageStats so that it could live on the IO thread. (2) Added a keyed service called DataReductionProxyChromeSettings, so chrome browsers on all platforms could use the same pattern. BUG=396695 Review URL: https://codereview.chromium.org/412143009 Cr-Commit-Position: refs/heads/master@{#288288} git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288288 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--android_webview/browser/aw_browser_context.cc39
-rw-r--r--android_webview/browser/aw_browser_context.h15
-rw-r--r--android_webview/browser/net/aw_url_request_context_getter.cc49
-rw-r--r--android_webview/browser/net/aw_url_request_context_getter.h18
-rw-r--r--android_webview/native/aw_contents_statics.cc16
-rw-r--r--chrome/browser/io_thread.cc70
-rw-r--r--chrome/browser/io_thread.h23
-rw-r--r--chrome/browser/net/chrome_network_delegate.cc2
-rw-r--r--chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc21
-rw-r--r--chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h23
-rw-r--r--chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.cc19
-rw-r--r--chrome/browser/profiles/profile.cc4
-rw-r--r--chrome/browser/profiles/profile_impl.cc36
-rw-r--r--chrome/browser/profiles/profile_impl.h6
-rw-r--r--chrome/browser/profiles/profile_impl_io_data.cc52
-rw-r--r--chrome/browser/profiles/profile_impl_io_data.h24
-rw-r--r--chrome/browser/profiles/profile_io_data.cc50
-rw-r--r--chrome/browser/profiles/profile_io_data.h9
-rw-r--r--components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.cc48
-rw-r--r--components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h29
-rw-r--r--components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler_unittest.cc21
-rw-r--r--components/data_reduction_proxy/browser/data_reduction_proxy_config_service.cc12
-rw-r--r--components/data_reduction_proxy/browser/data_reduction_proxy_config_service.h5
-rw-r--r--components/data_reduction_proxy/browser/data_reduction_proxy_config_service_unittest.cc29
-rw-r--r--components/data_reduction_proxy/browser/data_reduction_proxy_params.cc23
-rw-r--r--components/data_reduction_proxy/browser/data_reduction_proxy_params.h17
-rw-r--r--components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc12
-rw-r--r--components/data_reduction_proxy/browser/data_reduction_proxy_settings.h14
-rw-r--r--components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc68
-rw-r--r--components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h49
-rw-r--r--components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats_unittest.cc20
31 files changed, 509 insertions, 314 deletions
diff --git a/android_webview/browser/aw_browser_context.cc b/android_webview/browser/aw_browser_context.cc
index 614bd82..9b510e5 100644
--- a/android_webview/browser/aw_browser_context.cc
+++ b/android_webview/browser/aw_browser_context.cc
@@ -11,11 +11,11 @@
#include "android_webview/browser/jni_dependency_factory.h"
#include "android_webview/browser/net/aw_url_request_context_getter.h"
#include "android_webview/browser/net/init_native_callback.h"
+#include "base/bind.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h"
#include "base/prefs/pref_service_factory.h"
#include "components/autofill/core/common/autofill_pref_names.h"
-#include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_config_service.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_prefs.h"
@@ -27,10 +27,11 @@
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "net/cookies/cookie_store.h"
+#include "net/proxy/proxy_service.h"
using base::FilePath;
using content::BrowserThread;
-using data_reduction_proxy::DataReductionProxyAuthRequestHandler;
+using data_reduction_proxy::DataReductionProxyConfigService;
using data_reduction_proxy::DataReductionProxySettings;
namespace android_webview {
@@ -103,23 +104,30 @@ void AwBrowserContext::PreMainMessageLoopRun() {
new DataReductionProxySettings(
new data_reduction_proxy::DataReductionProxyParams(
data_reduction_proxy::DataReductionProxyParams::kAllowed)));
- data_reduction_proxy_auth_request_handler_.reset(
- new DataReductionProxyAuthRequestHandler(
- data_reduction_proxy::kClientAndroidWebview,
- data_reduction_proxy::kAndroidWebViewProtocolVersion,
- data_reduction_proxy_settings_->params()));
#endif
-
- url_request_context_getter_ =
- new AwURLRequestContextGetter(GetPath(), cookie_store_.get());
-
- if (data_reduction_proxy_settings_.get()) {
+ scoped_ptr<DataReductionProxyConfigService>
+ data_reduction_proxy_config_service(
+ new DataReductionProxyConfigService(
+ scoped_ptr<net::ProxyConfigService>(
+ net::ProxyService::CreateSystemProxyConfigService(
+ BrowserThread::GetMessageLoopProxyForThread(
+ BrowserThread::IO),
+ NULL /* Ignored on Android */)).Pass()));
+ if (data_reduction_proxy_settings_.get()) {
scoped_ptr<data_reduction_proxy::DataReductionProxyConfigurator>
configurator(new data_reduction_proxy::DataReductionProxyConfigTracker(
- url_request_context_getter_->proxy_config_service(),
+ base::Bind(&DataReductionProxyConfigService::UpdateProxyConfig,
+ base::Unretained(
+ data_reduction_proxy_config_service.get())),
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
data_reduction_proxy_settings_->SetProxyConfigurator(configurator.Pass());
}
+
+ url_request_context_getter_ =
+ new AwURLRequestContextGetter(GetPath(),
+ cookie_store_.get(),
+ data_reduction_proxy_config_service.Pass());
+
visitedlink_master_.reset(
new visitedlink::VisitedLinkMaster(this, this, false));
visitedlink_master_->Init();
@@ -172,11 +180,6 @@ DataReductionProxySettings* AwBrowserContext::GetDataReductionProxySettings() {
return data_reduction_proxy_settings_.get();
}
-DataReductionProxyAuthRequestHandler*
-AwBrowserContext::GetDataReductionProxyAuthRequestHandler() {
- return data_reduction_proxy_auth_request_handler_.get();
-}
-
// Create user pref service for autofill functionality.
void AwBrowserContext::CreateUserPrefServiceIfNecessary() {
if (user_pref_service_)
diff --git a/android_webview/browser/aw_browser_context.h b/android_webview/browser/aw_browser_context.h
index 7a008bf..ab0ebef 100644
--- a/android_webview/browser/aw_browser_context.h
+++ b/android_webview/browser/aw_browser_context.h
@@ -28,7 +28,6 @@ class WebContents;
}
namespace data_reduction_proxy {
-class DataReductionProxyAuthRequestHandler;
class DataReductionProxySettings;
}
@@ -40,9 +39,6 @@ namespace visitedlink {
class VisitedLinkMaster;
}
-using data_reduction_proxy::DataReductionProxyAuthRequestHandler;
-using data_reduction_proxy::DataReductionProxySettings;
-
namespace android_webview {
class AwFormDatabaseService;
@@ -87,10 +83,8 @@ class AwBrowserContext : public content::BrowserContext,
AwFormDatabaseService* GetFormDatabaseService();
- DataReductionProxySettings* GetDataReductionProxySettings();
-
- DataReductionProxyAuthRequestHandler*
- GetDataReductionProxyAuthRequestHandler();
+ data_reduction_proxy::DataReductionProxySettings*
+ GetDataReductionProxySettings();
void CreateUserPrefServiceIfNecessary();
@@ -137,9 +131,8 @@ class AwBrowserContext : public content::BrowserContext,
scoped_ptr<PrefService> user_pref_service_;
- scoped_ptr<DataReductionProxySettings> data_reduction_proxy_settings_;
- scoped_ptr<DataReductionProxyAuthRequestHandler>
- data_reduction_proxy_auth_request_handler_;
+ scoped_ptr<data_reduction_proxy::DataReductionProxySettings>
+ data_reduction_proxy_settings_;
DISALLOW_COPY_AND_ASSIGN(AwBrowserContext);
};
diff --git a/android_webview/browser/net/aw_url_request_context_getter.cc b/android_webview/browser/net/aw_url_request_context_getter.cc
index 94da736..a1d02a5 100644
--- a/android_webview/browser/net/aw_url_request_context_getter.cc
+++ b/android_webview/browser/net/aw_url_request_context_getter.cc
@@ -17,6 +17,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/threading/sequenced_worker_pool.h"
#include "base/threading/worker_pool.h"
+#include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_config_service.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h"
#include "content/public/browser/browser_thread.h"
@@ -167,14 +168,12 @@ scoped_ptr<net::URLRequestJobFactory> CreateJobFactory(
} // namespace
AwURLRequestContextGetter::AwURLRequestContextGetter(
- const base::FilePath& partition_path, net::CookieStore* cookie_store)
+ const base::FilePath& partition_path, net::CookieStore* cookie_store,
+ scoped_ptr<data_reduction_proxy::DataReductionProxyConfigService>
+ config_service)
: partition_path_(partition_path),
- cookie_store_(cookie_store),
- proxy_config_service_(new DataReductionProxyConfigService(
- scoped_ptr<net::ProxyConfigService>(
- net::ProxyService::CreateSystemProxyConfigService(
- GetNetworkTaskRunner(),
- NULL /* Ignored on Android */)).Pass())) {
+ cookie_store_(cookie_store) {
+ data_reduction_proxy_config_service_ = config_service.Pass();
// CreateSystemProxyConfigService for Android must be called on main thread.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
}
@@ -193,7 +192,14 @@ void AwURLRequestContextGetter::InitializeURLRequestContext() {
#if !defined(DISABLE_FTP_SUPPORT)
builder.set_ftp_enabled(false); // Android WebView does not support ftp yet.
#endif
- builder.set_proxy_config_service(proxy_config_service_.release());
+ if (data_reduction_proxy_config_service_.get()) {
+ builder.set_proxy_config_service(
+ data_reduction_proxy_config_service_.release());
+ } else {
+ builder.set_proxy_config_service(
+ net::ProxyService::CreateSystemProxyConfigService(
+ GetNetworkTaskRunner(), NULL /* Ignored on Android */ ));
+ }
builder.set_accept_language(net::HttpUtil::GenerateAcceptLanguageHeader(
AwContentBrowserClient::GetAcceptLangsImpl()));
ApplyCmdlineOverridesToURLRequestContextBuilder(&builder);
@@ -222,14 +228,20 @@ void AwURLRequestContextGetter::InitializeURLRequestContext() {
#if defined(SPDY_PROXY_AUTH_ORIGIN)
AwBrowserContext* browser_context = AwBrowserContext::GetDefault();
DCHECK(browser_context);
- DataReductionProxySettings* drp_settings =
+ DataReductionProxySettings* data_reduction_proxy_settings =
browser_context->GetDataReductionProxySettings();
- if (drp_settings) {
- aw_network_delegate->set_data_reduction_proxy_params(
- drp_settings->params());
- aw_network_delegate->set_data_reduction_proxy_auth_request_handler(
- browser_context->GetDataReductionProxyAuthRequestHandler());
- }
+ DCHECK(data_reduction_proxy_settings);
+ data_reduction_proxy_auth_request_handler_.reset(
+ new data_reduction_proxy::DataReductionProxyAuthRequestHandler(
+ data_reduction_proxy::kClientAndroidWebview,
+ data_reduction_proxy::kAndroidWebViewProtocolVersion,
+ data_reduction_proxy_settings->params(),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
+
+ aw_network_delegate->set_data_reduction_proxy_params(
+ data_reduction_proxy_settings->params());
+ aw_network_delegate->set_data_reduction_proxy_auth_request_handler(
+ data_reduction_proxy_auth_request_handler_.get());
#endif
main_http_factory_.reset(main_cache);
@@ -261,10 +273,9 @@ void AwURLRequestContextGetter::SetHandlersAndInterceptors(
request_interceptors_.swap(request_interceptors);
}
-DataReductionProxyConfigService*
-AwURLRequestContextGetter::proxy_config_service() {
- // TODO(bengr): return system config if data reduction proxy is disabled.
- return proxy_config_service_.get();
+data_reduction_proxy::DataReductionProxyAuthRequestHandler*
+AwURLRequestContextGetter::GetDataReductionProxyAuthRequestHandler() const {
+ return data_reduction_proxy_auth_request_handler_.get();
}
} // namespace android_webview
diff --git a/android_webview/browser/net/aw_url_request_context_getter.h b/android_webview/browser/net/aw_url_request_context_getter.h
index 6e4f81e..712893a 100644
--- a/android_webview/browser/net/aw_url_request_context_getter.h
+++ b/android_webview/browser/net/aw_url_request_context_getter.h
@@ -24,19 +24,21 @@ class URLRequestJobFactory;
}
namespace data_reduction_proxy {
+class DataReductionProxyAuthRequestHandler;
class DataReductionProxyConfigService;
}
-using data_reduction_proxy::DataReductionProxyConfigService;
-
namespace android_webview {
class AwNetworkDelegate;
class AwURLRequestContextGetter : public net::URLRequestContextGetter {
public:
- AwURLRequestContextGetter(const base::FilePath& partition_path,
- net::CookieStore* cookie_store);
+ AwURLRequestContextGetter(
+ const base::FilePath& partition_path,
+ net::CookieStore* cookie_store,
+ scoped_ptr<data_reduction_proxy::DataReductionProxyConfigService>
+ config_service);
void InitializeOnNetworkThread();
@@ -45,7 +47,8 @@ class AwURLRequestContextGetter : public net::URLRequestContextGetter {
virtual scoped_refptr<base::SingleThreadTaskRunner>
GetNetworkTaskRunner() const OVERRIDE;
- DataReductionProxyConfigService* proxy_config_service();
+ data_reduction_proxy::DataReductionProxyAuthRequestHandler*
+ GetDataReductionProxyAuthRequestHandler() const;
private:
friend class AwBrowserContext;
@@ -66,7 +69,10 @@ class AwURLRequestContextGetter : public net::URLRequestContextGetter {
const base::FilePath partition_path_;
scoped_refptr<net::CookieStore> cookie_store_;
scoped_ptr<net::URLRequestContext> url_request_context_;
- scoped_ptr<DataReductionProxyConfigService> proxy_config_service_;
+ scoped_ptr<data_reduction_proxy::DataReductionProxyConfigService>
+ data_reduction_proxy_config_service_;
+ scoped_ptr<data_reduction_proxy::DataReductionProxyAuthRequestHandler>
+ data_reduction_proxy_auth_request_handler_;
scoped_ptr<net::URLRequestJobFactory> job_factory_;
scoped_ptr<net::HttpTransactionFactory> main_http_factory_;
scoped_ptr<net::ChannelIDService> channel_id_service_;
diff --git a/android_webview/native/aw_contents_statics.cc b/android_webview/native/aw_contents_statics.cc
index 9888aad..5a6e130 100644
--- a/android_webview/native/aw_contents_statics.cc
+++ b/android_webview/native/aw_contents_statics.cc
@@ -5,6 +5,7 @@
#include "android_webview/native/aw_contents_statics.h"
#include "android_webview/browser/aw_browser_context.h"
+#include "android_webview/browser/net/aw_url_request_context_getter.h"
#include "base/android/jni_string.h"
#include "base/android/scoped_java_ref.h"
#include "base/callback.h"
@@ -54,11 +55,18 @@ void ClearClientCertPreferences(JNIEnv* env, jclass, jobject callback) {
void SetDataReductionProxyKey(JNIEnv* env, jclass, jstring key) {
AwBrowserContext* browser_context = AwBrowserContext::GetDefault();
DCHECK(browser_context);
- DataReductionProxyAuthRequestHandler* drp_auth_request_handler =
- browser_context->GetDataReductionProxyAuthRequestHandler();
- if (drp_auth_request_handler)
- drp_auth_request_handler->SetKey(
+ DCHECK(browser_context->GetRequestContext());
+ AwURLRequestContextGetter* aw_url_request_context_getter =
+ static_cast<AwURLRequestContextGetter*>(
+ browser_context->GetRequestContext());
+ DataReductionProxyAuthRequestHandler* auth_request_handler =
+ aw_url_request_context_getter->GetDataReductionProxyAuthRequestHandler();
+ if (auth_request_handler) {
+ auth_request_handler->SetKeyOnUI(
ConvertJavaStringToUTF8(env, key));
+ } else {
+ DLOG(ERROR) << "Data reduction proxy auth request handler does not exist";
+ }
}
// static
diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc
index 82bfdac..a3773f6 100644
--- a/chrome/browser/io_thread.cc
+++ b/chrome/browser/io_thread.cc
@@ -96,12 +96,12 @@
#include "net/ocsp/nss_ocsp.h"
#endif
-#if defined(OS_ANDROID) || defined(OS_IOS)
+#if defined(SPDY_PROXY_AUTH_ORIGIN)
+#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/browser/data_reduction_proxy_auth_request_handler.h"
-#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol.h"
-#include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h"
-#endif
+#endif // defined(SPDY_PROXY_AUTH_ORIGIN)
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/login/users/user_manager.h"
@@ -111,13 +111,6 @@
using content::BrowserThread;
-#if defined(OS_ANDROID) || defined(OS_IOS)
-using data_reduction_proxy::DataReductionProxyAuthRequestHandler;
-using data_reduction_proxy::DataReductionProxyParams;
-using data_reduction_proxy::DataReductionProxyUsageStats;
-using data_reduction_proxy::DataReductionProxySettings;
-#endif
-
class SafeBrowsingURLRequestContext;
// The IOThread object must outlive any tasks posted to the IO thread before the
@@ -642,39 +635,44 @@ void IOThread::InitAsync() {
}
#endif
globals_->ssl_config_service = GetSSLConfigService();
-#if defined(OS_ANDROID) || defined(OS_IOS)
+
#if defined(SPDY_PROXY_AUTH_ORIGIN)
- int drp_flags = DataReductionProxyParams::kFallbackAllowed;
- if (DataReductionProxyParams::IsIncludedInFieldTrial())
- drp_flags |= DataReductionProxyParams::kAllowed;
- if (DataReductionProxyParams::IsIncludedInAlternativeFieldTrial())
- drp_flags |= DataReductionProxyParams::kAlternativeAllowed;
- if (DataReductionProxyParams::IsIncludedInPromoFieldTrial())
- drp_flags |= DataReductionProxyParams::kPromoAllowed;
- DataReductionProxyParams* proxy_params =
- new DataReductionProxyParams(drp_flags);
- globals_->data_reduction_proxy_params.reset(proxy_params);
+ int drp_flags = 0;
+ if (data_reduction_proxy::DataReductionProxyParams::
+ IsIncludedInFieldTrial()) {
+ drp_flags |=
+ (data_reduction_proxy::DataReductionProxyParams::kAllowed |
+ data_reduction_proxy::DataReductionProxyParams::kFallbackAllowed);
+ }
+ if (data_reduction_proxy::DataReductionProxyParams::
+ IsIncludedInAlternativeFieldTrial()) {
+ drp_flags |=
+ data_reduction_proxy::DataReductionProxyParams::kAlternativeAllowed;
+ }
+ if (data_reduction_proxy::DataReductionProxyParams::
+ IsIncludedInPromoFieldTrial())
+ drp_flags |= data_reduction_proxy::DataReductionProxyParams::kPromoAllowed;
+ if (data_reduction_proxy::DataReductionProxyParams::
+ IsIncludedInHoldbackFieldTrial())
+ drp_flags |= data_reduction_proxy::DataReductionProxyParams::kHoldback;
+ globals_->data_reduction_proxy_params.reset(
+ new data_reduction_proxy::DataReductionProxyParams(drp_flags));
globals_->data_reduction_proxy_auth_request_handler.reset(
- new DataReductionProxyAuthRequestHandler(
+ new data_reduction_proxy::DataReductionProxyAuthRequestHandler(
DataReductionProxyChromeSettings::GetClient(),
DataReductionProxyChromeSettings::GetBuildAndPatchNumber(),
- proxy_params));
- globals_->on_resolve_proxy_handler =
- ChromeNetworkDelegate::OnResolveProxyHandler(
- base::Bind(data_reduction_proxy::OnResolveProxyHandler));
- DataReductionProxyUsageStats* proxy_usage_stats =
- new DataReductionProxyUsageStats(proxy_params,
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
- network_delegate->set_data_reduction_proxy_params(proxy_params);
- globals_->data_reduction_proxy_usage_stats.reset(proxy_usage_stats);
- network_delegate->set_data_reduction_proxy_usage_stats(proxy_usage_stats);
+ globals_->data_reduction_proxy_params.get(),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
+ // This is the same as in ProfileImplIOData except that we do not collect
+ // usage stats.
+ network_delegate->set_data_reduction_proxy_params(
+ globals_->data_reduction_proxy_params.get());
network_delegate->set_data_reduction_proxy_auth_request_handler(
globals_->data_reduction_proxy_auth_request_handler.get());
network_delegate->set_on_resolve_proxy_handler(
- globals_->on_resolve_proxy_handler);
+ base::Bind(data_reduction_proxy::OnResolveProxyHandler));
#endif // defined(SPDY_PROXY_AUTH_ORIGIN)
-#endif // defined(OS_ANDROID) || defined(OS_IOS)
+
globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory(
globals_->host_resolver.get()));
globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl());
diff --git a/chrome/browser/io_thread.h b/chrome/browser/io_thread.h
index 24be526..b7cc3d3 100644
--- a/chrome/browser/io_thread.h
+++ b/chrome/browser/io_thread.h
@@ -17,9 +17,6 @@
#include "base/time/time.h"
#include "chrome/browser/net/chrome_network_delegate.h"
#include "chrome/browser/net/ssl_config_service_manager.h"
-#include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h"
-#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
-#include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/browser_thread_delegate.h"
#include "net/base/network_change_notifier.h"
@@ -40,6 +37,13 @@ namespace chrome_browser_net {
class DnsProbeService;
}
+#if defined(SPDY_PROXY_AUTH_ORIGIN)
+namespace data_reduction_proxy {
+class DataReductionProxyAuthRequestHandler;
+class DataReductionProxyParams;
+}
+#endif // defined(SPDY_PROXY_AUTH_ORIGIN)
+
namespace extensions {
class EventRouterForwarder;
}
@@ -194,13 +198,12 @@ class IOThread : public content::BrowserThreadDelegate {
// main frame load fails with a DNS error in order to provide more useful
// information to the renderer so it can show a more specific error page.
scoped_ptr<chrome_browser_net::DnsProbeService> dns_probe_service;
- scoped_ptr<data_reduction_proxy::DataReductionProxyParams>
- data_reduction_proxy_params;
- scoped_ptr<data_reduction_proxy::DataReductionProxyUsageStats>
- data_reduction_proxy_usage_stats;
- scoped_ptr<data_reduction_proxy::DataReductionProxyAuthRequestHandler>
- data_reduction_proxy_auth_request_handler;
- ChromeNetworkDelegate::OnResolveProxyHandler on_resolve_proxy_handler;
+#if defined(SPDY_PROXY_AUTH_ORIGIN)
+ scoped_ptr<data_reduction_proxy::DataReductionProxyParams>
+ data_reduction_proxy_params;
+ scoped_ptr<data_reduction_proxy::DataReductionProxyAuthRequestHandler>
+ data_reduction_proxy_auth_request_handler;
+#endif
};
// |net_log| must either outlive the IOThread or be NULL.
diff --git a/chrome/browser/net/chrome_network_delegate.cc b/chrome/browser/net/chrome_network_delegate.cc
index b0c1616..74ecef7 100644
--- a/chrome/browser/net/chrome_network_delegate.cc
+++ b/chrome/browser/net/chrome_network_delegate.cc
@@ -132,7 +132,7 @@ void UpdateContentLengthPrefs(
profile->IsOffTheRecord()) {
return;
}
-#if defined(OS_ANDROID)
+#if defined(OS_ANDROID) && defined(SPDY_PROXY_AUTH_ORIGIN)
// If Android ever goes multi profile, the profile should be passed so that
// the browser preference will be taken.
bool with_data_reduction_proxy_enabled =
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 1faf4aa..19ac6f1 100644
--- a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc
+++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/prefs/pref_service.h"
#include "base/strings/string_split.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
@@ -15,6 +17,7 @@
#include "components/data_reduction_proxy/browser/data_reduction_proxy_configurator.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h"
+#include "net/url_request/url_request_context_getter.h"
using data_reduction_proxy::DataReductionProxyParams;
using data_reduction_proxy::DataReductionProxySettings;
@@ -27,21 +30,19 @@ DataReductionProxyChromeSettings::~DataReductionProxyChromeSettings() {
}
void DataReductionProxyChromeSettings::InitDataReductionProxySettings(
- Profile* profile) {
- DCHECK(profile);
- PrefService* prefs = profile->GetPrefs();
-
- scoped_ptr<data_reduction_proxy::DataReductionProxyConfigurator>
- configurator(new DataReductionProxyChromeConfigurator(prefs));
+ scoped_ptr<data_reduction_proxy::DataReductionProxyConfigurator>
+ configurator,
+ PrefService* profile_prefs,
+ PrefService* local_state_prefs,
+ net::URLRequestContextGetter* request_context) {
SetProxyConfigurator(configurator.Pass());
DataReductionProxySettings::InitDataReductionProxySettings(
- prefs,
- g_browser_process->local_state(),
- ProfileManager::GetActiveUserProfile()->GetRequestContext());
+ profile_prefs,
+ local_state_prefs,
+ request_context);
DataReductionProxySettings::SetOnDataReductionEnabledCallback(
base::Bind(&DataReductionProxyChromeSettings::RegisterSyntheticFieldTrial,
base::Unretained(this)));
-
SetDataReductionProxyAlternativeEnabled(
DataReductionProxyParams::IsIncludedInAlternativeFieldTrial());
}
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 12882d4..b095cb0 100644
--- a/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h
+++ b/chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h
@@ -5,14 +5,24 @@
#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/browser/data_reduction_proxy_settings.h"
#include "components/keyed_service/core/keyed_service.h"
+namespace base {
+class PrefService;
+}
+
namespace data_reduction_proxy {
+class DataReductionProxyConfigurator;
class DataReductionProxyParams;
}
-class Profile;
+namespace net {
+class URLRequestContextGetter;
+}
+
+class PrefService;
// Data reduction proxy settings class suitable for use with a Chrome browser.
// It is keyed to a browser context.
@@ -28,9 +38,14 @@ class DataReductionProxyChromeSettings
// Destructs the settings object.
virtual ~DataReductionProxyChromeSettings();
- // Initialize the settings object with the given profile, which it uses to
- // get the appropriate pref service.
- virtual void InitDataReductionProxySettings(Profile* profile);
+ // Initialize the settings object with the given configurator, prefs services,
+ // and request context.
+ void InitDataReductionProxySettings(
+ scoped_ptr<data_reduction_proxy::DataReductionProxyConfigurator>
+ configurator,
+ PrefService* profile_prefs,
+ PrefService* local_state_prefs,
+ net::URLRequestContextGetter* request_context);
// Using the chrome::VersionInfo version, returns the build and patch portion
// of the string delimited by a period. If the chrome::VersionInfo version
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 cf8ed37..42ad1ac 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,7 +7,6 @@
#include "base/bind.h"
#include "base/memory/singleton.h"
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
-#include "chrome/browser/profiles/profile.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
@@ -53,10 +52,11 @@ DataReductionProxyChromeSettingsFactory::
KeyedService* DataReductionProxyChromeSettingsFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
- Profile* profile = static_cast<Profile*>(context);
- int flags = DataReductionProxyParams::kFallbackAllowed;
- if (DataReductionProxyParams::IsIncludedInFieldTrial())
- flags |= DataReductionProxyParams::kAllowed;
+ int flags = 0;
+ if (DataReductionProxyParams::IsIncludedInFieldTrial()) {
+ flags |= (DataReductionProxyParams::kAllowed |
+ DataReductionProxyParams::kFallbackAllowed);
+ }
if (DataReductionProxyParams::IsIncludedInAlternativeFieldTrial())
flags |= DataReductionProxyParams::kAlternativeAllowed;
if (DataReductionProxyParams::IsIncludedInPromoFieldTrial())
@@ -64,11 +64,6 @@ KeyedService* DataReductionProxyChromeSettingsFactory::BuildServiceInstanceFor(
if (DataReductionProxyParams::IsIncludedInHoldbackFieldTrial())
flags |= DataReductionProxyParams::kHoldback;
- DataReductionProxyParams* params = new DataReductionProxyParams(flags);
-
- // Takes ownership of params.
- DataReductionProxyChromeSettings* settings =
- new DataReductionProxyChromeSettings(params);
- settings->InitDataReductionProxySettings(profile);
- return settings;
+ return new DataReductionProxyChromeSettings(
+ new DataReductionProxyParams(flags));
}
diff --git a/chrome/browser/profiles/profile.cc b/chrome/browser/profiles/profile.cc
index 994eb95..06b7d17 100644
--- a/chrome/browser/profiles/profile.cc
+++ b/chrome/browser/profiles/profile.cc
@@ -193,9 +193,9 @@ void Profile::RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
false,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
#endif
-#if defined(OS_ANDROID) || defined(OS_IOS)
+#if defined(SPDY_PROXY_AUTH_ORIGIN)
data_reduction_proxy::RegisterSyncableProfilePrefs(registry);
-#endif // defined(OS_ANDROID) || defined(OS_IOS)
+#endif // defined(SPDY_PROXY_AUTH_ORIGIN)
#if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && !defined(OS_IOS)
// Preferences related to the avatar bubble and user manager tutorials.
registry->RegisterIntegerPref(
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index 8c67ad0..bd6fa63 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -45,6 +45,7 @@
#include "chrome/browser/net/predictor.h"
#include "chrome/browser/net/pref_proxy_config_tracker.h"
#include "chrome/browser/net/proxy_service_factory.h"
+#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
#include "chrome/browser/net/ssl_config_service_manager.h"
#include "chrome/browser/plugins/chrome_plugin_service_filter.h"
#include "chrome/browser/plugins/plugin_prefs.h"
@@ -113,6 +114,13 @@
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#endif
+#if defined(SPDY_PROXY_AUTH_ORIGIN)
+#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.h"
+#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h"
+#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
+#include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h"
+#endif
+
#if defined(ENABLE_CONFIGURATION_POLICY)
#include "chrome/browser/policy/schema_registry_service.h"
#include "chrome/browser/policy/schema_registry_service_factory.h"
@@ -621,6 +629,20 @@ void ProfileImpl::DoFinalInit() {
InitHostZoomMap();
+ base::Callback<void(bool)> data_reduction_proxy_unavailable;
+ scoped_ptr<data_reduction_proxy::DataReductionProxyParams>
+ data_reduction_proxy_params;
+#if defined(SPDY_PROXY_AUTH_ORIGIN)
+ DataReductionProxyChromeSettings* data_reduction_proxy_chrome_settings =
+ DataReductionProxyChromeSettingsFactory::GetForBrowserContext(this);
+ data_reduction_proxy_params =
+ data_reduction_proxy_chrome_settings->params()->Clone();
+ data_reduction_proxy_unavailable =
+ base::Bind(
+ &data_reduction_proxy::DataReductionProxySettings::SetUnreachable,
+ base::Unretained(data_reduction_proxy_chrome_settings));
+#endif
+
// Make sure we initialize the ProfileIOData after everything else has been
// initialized that we might be reading from the IO thread.
@@ -628,7 +650,19 @@ void ProfileImpl::DoFinalInit() {
cache_max_size, media_cache_path, media_cache_max_size,
extensions_cookie_path, GetPath(), infinite_cache_path,
predictor_, session_cookie_mode, GetSpecialStoragePolicy(),
- CreateDomainReliabilityMonitor());
+ CreateDomainReliabilityMonitor(),
+ data_reduction_proxy_unavailable,
+ data_reduction_proxy_params.Pass());
+
+#if defined(SPDY_PROXY_AUTH_ORIGIN)
+ scoped_ptr<data_reduction_proxy::DataReductionProxyConfigurator>
+ configurator(new DataReductionProxyChromeConfigurator(prefs_.get()));
+ data_reduction_proxy_chrome_settings->InitDataReductionProxySettings(
+ configurator.Pass(),
+ prefs_.get(),
+ g_browser_process->local_state(),
+ GetRequestContext());
+#endif
#if defined(ENABLE_PLUGINS)
ChromePluginServiceFilter::GetInstance()->RegisterResourceContext(
diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h
index b9a6c98..3869b9a 100644
--- a/chrome/browser/profiles/profile_impl.h
+++ b/chrome/browser/profiles/profile_impl.h
@@ -40,6 +40,12 @@ namespace base {
class SequencedTaskRunner;
}
+namespace data_reduction_proxy {
+class DataReductionProxyParams;
+}
+
+class DataReductionProxyChromeSettings;
+
namespace domain_reliability {
class DomainReliabilityMonitor;
}
diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc
index 4d12e68..1c49b31 100644
--- a/chrome/browser/profiles/profile_impl_io_data.cc
+++ b/chrome/browser/profiles/profile_impl_io_data.cc
@@ -50,6 +50,14 @@
#include "net/url_request/url_request_job_factory_impl.h"
#include "webkit/browser/quota/special_storage_policy.h"
+#if defined(SPDY_PROXY_AUTH_ORIGIN)
+#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
+#include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h"
+#include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol.h"
+#include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h"
+#include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names.h"
+#endif // defined(SPDY_PROXY_AUTH_ORIGIN)
+
namespace {
net::BackendType ChooseCacheBackendType() {
@@ -78,6 +86,9 @@ net::BackendType ChooseCacheBackendType() {
} // namespace
using content::BrowserThread;
+#if defined(SPDY_PROXY_AUTH_ORIGIN)
+using data_reduction_proxy::DataReductionProxyParams;
+#endif // defined(SPDY_PROXY_AUTH_ORIGIN)
ProfileImplIOData::Handle::Handle(Profile* profile)
: io_data_(new ProfileImplIOData),
@@ -140,7 +151,10 @@ void ProfileImplIOData::Handle::Init(
content::CookieStoreConfig::SessionCookieMode session_cookie_mode,
quota::SpecialStoragePolicy* special_storage_policy,
scoped_ptr<domain_reliability::DomainReliabilityMonitor>
- domain_reliability_monitor) {
+ domain_reliability_monitor,
+ const base::Callback<void(bool)>& data_reduction_proxy_unavailable,
+ scoped_ptr<data_reduction_proxy::DataReductionProxyParams>
+ data_reduction_proxy_params) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!io_data_->lazy_params_);
DCHECK(predictor);
@@ -170,6 +184,13 @@ void ProfileImplIOData::Handle::Init(
io_data_->domain_reliability_monitor_ = domain_reliability_monitor.Pass();
io_data_->InitializeMetricsEnabledStateOnUIThread();
+
+#if defined(SPDY_PROXY_AUTH_ORIGIN)
+ io_data_->data_reduction_proxy_unavailable_callback_ =
+ data_reduction_proxy_unavailable;
+ io_data_->data_reduction_proxy_params_ =
+ data_reduction_proxy_params.Pass();
+#endif // defined(SPDY_PROXY_AUTH_ORIGIN)
}
content::ResourceContext*
@@ -348,12 +369,12 @@ void ProfileImplIOData::Handle::LazyInitialize() const {
io_data_->safe_browsing_enabled()->MoveToThread(
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
#endif
-#if defined(OS_ANDROID) || defined(OS_IOS)
+#if defined(SPDY_PROXY_AUTH_ORIGIN)
io_data_->data_reduction_proxy_enabled()->Init(
data_reduction_proxy::prefs::kDataReductionProxyEnabled, pref_service);
io_data_->data_reduction_proxy_enabled()->MoveToThread(
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
-#endif
+#endif // defined(SPDY_PROXY_AUTH_ORIGIN)
io_data_->InitializeOnUIThread(profile_);
}
@@ -391,6 +412,31 @@ void ProfileImplIOData::InitializeInternal(
IOThread* const io_thread = profile_params->io_thread;
IOThread::Globals* const io_thread_globals = io_thread->globals();
+#if defined(SPDY_PROXY_AUTH_ORIGIN)
+ data_reduction_proxy_auth_request_handler_.reset(
+ new data_reduction_proxy::DataReductionProxyAuthRequestHandler(
+ DataReductionProxyChromeSettings::GetClient(),
+ DataReductionProxyChromeSettings::GetBuildAndPatchNumber(),
+ data_reduction_proxy_params_.get(),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
+ data_reduction_proxy_usage_stats_.reset(
+ new data_reduction_proxy::DataReductionProxyUsageStats(
+ data_reduction_proxy_params_.get(),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)));
+ data_reduction_proxy_usage_stats_->set_unavailable_callback(
+ data_reduction_proxy_unavailable_callback_);
+
+
+ network_delegate()->set_data_reduction_proxy_params(
+ data_reduction_proxy_params_.get());
+ network_delegate()->set_data_reduction_proxy_usage_stats(
+ data_reduction_proxy_usage_stats_.get());
+ network_delegate()->set_data_reduction_proxy_auth_request_handler(
+ data_reduction_proxy_auth_request_handler_.get());
+ network_delegate()->set_on_resolve_proxy_handler(
+ base::Bind(data_reduction_proxy::OnResolveProxyHandler));
+#endif // defined(SPDY_PROXY_AUTH_ORIGIN)
+
network_delegate()->set_predictor(predictor_.get());
// Initialize context members.
diff --git a/chrome/browser/profiles/profile_impl_io_data.h b/chrome/browser/profiles/profile_impl_io_data.h
index a39a780..3a6f529 100644
--- a/chrome/browser/profiles/profile_impl_io_data.h
+++ b/chrome/browser/profiles/profile_impl_io_data.h
@@ -22,6 +22,14 @@ namespace content {
class CookieCryptoDelegate;
} // namespace content
+#if defined(SPDY_PROXY_AUTH_ORIGIN)
+namespace data_reduction_proxy {
+class DataReductionProxyParams;
+class DataReductionProxyUsageStats;
+class DataReductionProxyAuthRequestHandler;
+}
+#endif
+
namespace domain_reliability {
class DomainReliabilityMonitor;
} // namespace domain_reliability
@@ -61,7 +69,11 @@ class ProfileImplIOData : public ProfileIOData {
session_cookie_mode,
quota::SpecialStoragePolicy* special_storage_policy,
scoped_ptr<domain_reliability::DomainReliabilityMonitor>
- domain_reliability_monitor);
+ domain_reliability_monitor,
+ const base::Callback<void(bool)>&
+ data_reduction_proxy_unavailable,
+ scoped_ptr<data_reduction_proxy::DataReductionProxyParams>
+ data_reduction_proxy_params);
// These Create*ContextGetter() functions are only exposed because the
// circular relationship between Profile, ProfileIOData::Handle, and the
@@ -231,6 +243,16 @@ class ProfileImplIOData : public ProfileIOData {
int app_cache_max_size_;
int app_media_cache_max_size_;
+#if defined(SPDY_PROXY_AUTH_ORIGIN)
+ mutable scoped_ptr<data_reduction_proxy::DataReductionProxyParams>
+ data_reduction_proxy_params_;
+ mutable scoped_ptr<data_reduction_proxy::DataReductionProxyUsageStats>
+ data_reduction_proxy_usage_stats_;
+ mutable base::Callback<void(bool)> data_reduction_proxy_unavailable_callback_;
+ mutable scoped_ptr<data_reduction_proxy::DataReductionProxyAuthRequestHandler>
+ data_reduction_proxy_auth_request_handler_;
+#endif // defined(SPDY_PROXY_AUTH_ORIGIN)
+
DISALLOW_COPY_AND_ASSIGN(ProfileImplIOData);
};
diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc
index 07fc92b..d307de0 100644
--- a/chrome/browser/profiles/profile_io_data.cc
+++ b/chrome/browser/profiles/profile_io_data.cc
@@ -143,7 +143,6 @@
using content::BrowserContext;
using content::BrowserThread;
using content::ResourceContext;
-using data_reduction_proxy::DataReductionProxyUsageStats;
namespace {
@@ -505,49 +504,12 @@ void ProfileIOData::InitializeOnUIThread(Profile* profile) {
initialized_on_UI_thread_ = true;
-#if defined(OS_ANDROID)
-#if defined(SPDY_PROXY_AUTH_ORIGIN)
- BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
- base::Bind(&ProfileIOData::SetDataReductionProxyUsageStatsOnIOThread,
- base::Unretained(this), g_browser_process->io_thread(), profile));
-#endif
-#endif
-
// We need to make sure that content initializes its own data structures that
// are associated with each ResourceContext because we might post this
// object to the IO thread after this function.
BrowserContext::EnsureResourceContextInitialized(profile);
}
-#if defined(OS_ANDROID)
-#if defined(SPDY_PROXY_AUTH_ORIGIN)
-void ProfileIOData::SetDataReductionProxyUsageStatsOnIOThread(
- IOThread* io_thread, Profile* profile) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- IOThread::Globals* globals = io_thread->globals();
- DataReductionProxyUsageStats* usage_stats =
- globals->data_reduction_proxy_usage_stats.get();
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- base::Bind(&ProfileIOData::SetDataReductionProxyUsageStatsOnUIThread,
- base::Unretained(this), profile, usage_stats));
-}
-
-void ProfileIOData::SetDataReductionProxyUsageStatsOnUIThread(
- Profile* profile,
- DataReductionProxyUsageStats* usage_stats) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- if (g_browser_process->profile_manager()->IsValidProfile(profile)) {
- DataReductionProxyChromeSettings* data_reduction_proxy_chrome_settings =
- DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile);
- if (data_reduction_proxy_chrome_settings) {
- data_reduction_proxy_chrome_settings->SetDataReductionProxyUsageStats(
- usage_stats);
- }
- }
-}
-#endif
-#endif
-
ProfileIOData::MediaRequestContext::MediaRequestContext() {
}
@@ -878,9 +840,13 @@ bool ProfileIOData::GetMetricsEnabledStateOnIOThread() const {
#if defined(OS_ANDROID)
bool ProfileIOData::IsDataReductionProxyEnabled() const {
+#if defined(SPDY_PROXY_AUTH_ORIGIN)
return data_reduction_proxy_enabled_.GetValue() ||
CommandLine::ForCurrentProcess()->HasSwitch(
data_reduction_proxy::switches::kEnableDataReductionProxy);
+#else
+ return false;
+#endif // defined(SPDY_PROXY_AUTH_ORIGIN)
}
#endif
@@ -1041,14 +1007,6 @@ void ProfileIOData::Init(
NULL,
#endif
&enable_referrers_);
- network_delegate->set_data_reduction_proxy_params(
- io_thread_globals->data_reduction_proxy_params.get());
- network_delegate->set_data_reduction_proxy_usage_stats(
- io_thread_globals->data_reduction_proxy_usage_stats.get());
- network_delegate->set_data_reduction_proxy_auth_request_handler(
- io_thread_globals->data_reduction_proxy_auth_request_handler.get());
- network_delegate->set_on_resolve_proxy_handler(
- io_thread_globals->on_resolve_proxy_handler);
if (command_line.HasSwitch(switches::kEnableClientHints))
network_delegate->SetEnableClientHints();
#if defined(ENABLE_EXTENSIONS)
diff --git a/chrome/browser/profiles/profile_io_data.h b/chrome/browser/profiles/profile_io_data.h
index f0d6149..211ab61 100644
--- a/chrome/browser/profiles/profile_io_data.h
+++ b/chrome/browser/profiles/profile_io_data.h
@@ -346,15 +346,6 @@ class ProfileIOData {
void InitializeOnUIThread(Profile* profile);
void ApplyProfileParamsToContext(net::URLRequestContext* context) const;
-#if defined(OS_ANDROID)
-#if defined(SPDY_PROXY_AUTH_ORIGIN)
- void SetDataReductionProxyUsageStatsOnIOThread(IOThread* io_thread,
- Profile* profile);
- void SetDataReductionProxyUsageStatsOnUIThread(Profile* profile,
- data_reduction_proxy::DataReductionProxyUsageStats* usage_stats);
-#endif
-#endif
-
scoped_ptr<net::URLRequestJobFactory> SetUpJobFactoryDefaults(
scoped_ptr<net::URLRequestJobFactoryImpl> job_factory,
content::URLRequestInterceptorScopedVector request_interceptors,
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.cc
index 36a796f..79fb37e 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.cc
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.cc
@@ -4,7 +4,9 @@
#include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h"
+#include "base/bind.h"
#include "base/command_line.h"
+#include "base/single_thread_task_runner.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
@@ -41,15 +43,17 @@ bool DataReductionProxyAuthRequestHandler::IsKeySetOnCommandLine() {
DataReductionProxyAuthRequestHandler::DataReductionProxyAuthRequestHandler(
const std::string& client,
const std::string& version,
- DataReductionProxyParams* params)
- : data_reduction_proxy_params_(params) {
+ DataReductionProxyParams* params,
+ scoped_refptr<base::SingleThreadTaskRunner> network_task_runner)
+ : data_reduction_proxy_params_(params),
+ network_task_runner_(network_task_runner) {
client_ = client;
version_ = version;
Init();
}
void DataReductionProxyAuthRequestHandler::Init() {
- InitAuthentication(GetDefaultKey());
+ InitAuthenticationOnUI(GetDefaultKey());
}
@@ -83,6 +87,7 @@ void DataReductionProxyAuthRequestHandler::MaybeAddRequestHeader(
net::URLRequest* request,
const net::ProxyServer& proxy_server,
net::HttpRequestHeaders* request_headers) {
+ DCHECK(network_task_runner_->BelongsToCurrentThread());
if (!proxy_server.is_valid())
return;
if (data_reduction_proxy_params_ &&
@@ -108,7 +113,7 @@ void DataReductionProxyAuthRequestHandler::AddAuthorizationHeader(
headers->SetHeader(kChromeProxyHeader, header_value);
}
-void DataReductionProxyAuthRequestHandler::InitAuthentication(
+void DataReductionProxyAuthRequestHandler::InitAuthenticationOnUI(
const std::string& key) {
key_ = key;
int64 timestamp =
@@ -116,20 +121,33 @@ void DataReductionProxyAuthRequestHandler::InitAuthentication(
int32 rand[3];
RandBytes(rand, 3 * sizeof(rand[0]));
- session_ = base::StringPrintf("%lld-%u-%u-%u",
- static_cast<long long>(timestamp),
- rand[0],
- rand[1],
- rand[2]);
- credentials_ = base::UTF16ToUTF8(AuthHashForSalt(timestamp, key_));
-
- DVLOG(1) << "session: [" << session_ << "] "
- << "password: [" << credentials_ << "]";
+ std::string session = base::StringPrintf("%lld-%u-%u-%u",
+ static_cast<long long>(timestamp),
+ rand[0],
+ rand[1],
+ rand[2]);
+ std::string credentials = base::UTF16ToUTF8(AuthHashForSalt(timestamp, key_));
+
+ DVLOG(1) << "session: [" << session << "] "
+ << "password: [" << credentials << "]";
+ network_task_runner_->PostTask(FROM_HERE, base::Bind(
+ &DataReductionProxyAuthRequestHandler::InitAuthentication,
+ base::Unretained(this),
+ session,
+ credentials));
+}
+
+void DataReductionProxyAuthRequestHandler::InitAuthentication(
+ const std::string& session,
+ const std::string& credentials) {
+ DCHECK(network_task_runner_->BelongsToCurrentThread());
+ session_ = session;
+ credentials_ = credentials;
}
-void DataReductionProxyAuthRequestHandler::SetKey(const std::string& key) {
+void DataReductionProxyAuthRequestHandler::SetKeyOnUI(const std::string& key) {
if (!key.empty())
- InitAuthentication(key);
+ InitAuthenticationOnUI(key);
}
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h b/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h
index 17ffb37..17b497a 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h
@@ -11,6 +11,10 @@
#include "base/time/time.h"
#include "url/gurl.h"
+namespace base {
+class SingleThreadTaskRunner;
+}
+
namespace net {
class HttpRequestHeaders;
class HttpResponseHeaders;
@@ -34,33 +38,29 @@ class DataReductionProxyAuthRequestHandler {
public:
static bool IsKeySetOnCommandLine();
- // Constructs an authentication request handler. Client is the canonical name
- // for the client. Client names should be defined in this file as one of
- // |kClient...|. Version is the authentication protocol version that the
- // client uses, which should be |kProtocolVersion| unless the client expects
- // to be handled differently from the standard behavior.
DataReductionProxyAuthRequestHandler(
const std::string& client,
const std::string& version,
- DataReductionProxyParams* params);
+ DataReductionProxyParams* params,
+ scoped_refptr<base::SingleThreadTaskRunner> network_task_runner);
virtual ~DataReductionProxyAuthRequestHandler();
// Adds a 'Chrome-Proxy' header to |request_headers| with the data reduction
// proxy authentication credentials. Only adds this header if the provided
- // |proxy_server| is a data reduction proxy.
+ // |proxy_server| is a data reduction proxy. Must be called on the IO thread.
void MaybeAddRequestHeader(net::URLRequest* request,
const net::ProxyServer& proxy_server,
net::HttpRequestHeaders* request_headers);
// Sets a new authentication key. This must be called for platforms that do
// not have a default key defined. See the constructor implementation for
- // those platforms.
- void SetKey(const std::string& key);
+ // those platforms. Must be called on the UI thread.
+ void SetKeyOnUI(const std::string& key);
protected:
void Init();
- void InitAuthentication(const std::string& key);
+ void InitAuthenticationOnUI(const std::string& key);
void AddAuthorizationHeader(net::HttpRequestHeaders* headers);
@@ -82,17 +82,26 @@ class DataReductionProxyAuthRequestHandler {
FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest,
AuthHashForSalt);
+ void InitAuthentication(
+ const std::string& session,
+ const std::string& credentials);
+
// Authentication state.
std::string key_;
+
+ // Lives on the IO thread.
std::string session_;
std::string credentials_;
// Name of the client and version of the data reduction proxy protocol to use.
+ // Both live on the IO thread.
std::string client_;
std::string version_;
DataReductionProxyParams* data_reduction_proxy_params_;
+ scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
+
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyAuthRequestHandler);
};
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler_unittest.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler_unittest.cc
index b5bc709..9a800b6 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler_unittest.cc
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler_unittest.cc
@@ -7,6 +7,7 @@
#include "base/md5.h"
#include "base/memory/scoped_ptr.h"
+#include "base/run_loop.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
@@ -64,8 +65,10 @@ class TestDataReductionProxyAuthRequestHandler
TestDataReductionProxyAuthRequestHandler(
const std::string& client,
const std::string& version,
- DataReductionProxyParams* params)
- : DataReductionProxyAuthRequestHandler(client,version, params) {}
+ DataReductionProxyParams* params,
+ base::MessageLoopProxy* loop_proxy)
+ : DataReductionProxyAuthRequestHandler(
+ client, version, params, loop_proxy) {}
virtual std::string GetDefaultKey() const OVERRIDE {
return kTestKey;
@@ -86,6 +89,13 @@ class TestDataReductionProxyAuthRequestHandler
} // namespace
class DataReductionProxyAuthRequestHandlerTest : public testing::Test {
+ public:
+ DataReductionProxyAuthRequestHandlerTest()
+ : loop_proxy_(base::MessageLoopProxy::current().get()) {
+ }
+ // Required for MessageLoopProxy::current().
+ base::MessageLoopForUI loop_;
+ base::MessageLoopProxy* loop_proxy_;
};
TEST_F(DataReductionProxyAuthRequestHandlerTest, Authorization) {
@@ -99,8 +109,10 @@ TEST_F(DataReductionProxyAuthRequestHandlerTest, Authorization) {
~TestDataReductionProxyParams::HAS_DEV_ORIGIN));
TestDataReductionProxyAuthRequestHandler auth_handler(kClient,
kVersion,
- params.get());
+ params.get(),
+ loop_proxy_);
auth_handler.Init();
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(auth_handler.client_, kClient);
EXPECT_EQ(kVersion, auth_handler.version_);
EXPECT_EQ(auth_handler.key_, kTestKey);
@@ -108,7 +120,8 @@ TEST_F(DataReductionProxyAuthRequestHandlerTest, Authorization) {
EXPECT_EQ(kExpectedSession, auth_handler.session_);
// Now set a key.
- auth_handler.SetKey(kTestKey2);
+ auth_handler.SetKeyOnUI(kTestKey2);
+ base::RunLoop().RunUntilIdle();
EXPECT_EQ(kTestKey2, auth_handler.key_);
EXPECT_EQ(kExpectedCredentials2, auth_handler.credentials_);
EXPECT_EQ(kExpectedSession2, auth_handler.session_);
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_config_service.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_config_service.cc
index 921a2e4..d160578 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_config_service.cc
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_config_service.cc
@@ -116,11 +116,10 @@ void DataReductionProxyConfigService::RegisterObserver() {
}
DataReductionProxyConfigTracker::DataReductionProxyConfigTracker(
- DataReductionProxyConfigService* config_service,
+ base::Callback<void(bool, const net::ProxyConfig&)> update_proxy_config,
base::TaskRunner* task_runner)
- : config_service_(config_service),
+ : update_proxy_config_(update_proxy_config),
task_runner_(task_runner) {
- DCHECK(config_service);
}
DataReductionProxyConfigTracker::~DataReductionProxyConfigTracker() {
@@ -194,11 +193,8 @@ void DataReductionProxyConfigTracker::AddURLPatternToBypass(
void DataReductionProxyConfigTracker::UpdateProxyConfigOnIOThread(
bool enabled,
const net::ProxyConfig& config) {
- task_runner_->PostTask(FROM_HERE,
- base::Bind(
- &DataReductionProxyConfigService::UpdateProxyConfig,
- base::Unretained(config_service_),
- enabled, config));
+ task_runner_->PostTask(
+ FROM_HERE, base::Bind(update_proxy_config_, enabled, config));
}
} // namespace data_reduction_proxy
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_config_service.h b/components/data_reduction_proxy/browser/data_reduction_proxy_config_service.h
index 75addad..7c92938 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_config_service.h
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_config_service.h
@@ -8,6 +8,7 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/callback.h"
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
@@ -91,7 +92,7 @@ class DataReductionProxyConfigService
class DataReductionProxyConfigTracker : public DataReductionProxyConfigurator {
public:
DataReductionProxyConfigTracker(
- DataReductionProxyConfigService* config_service,
+ base::Callback<void(bool, const net::ProxyConfig&)> update_proxy_config,
base::TaskRunner* task_runner);
virtual ~DataReductionProxyConfigTracker();
@@ -115,7 +116,7 @@ class DataReductionProxyConfigTracker : public DataReductionProxyConfigurator {
void UpdateProxyConfigOnIOThread(bool enabled,
const net::ProxyConfig& config);
- DataReductionProxyConfigService* config_service_;
+ base::Callback<void(bool, const net::ProxyConfig&)> update_proxy_config_;
std::vector<std::string> bypass_rules_;
scoped_refptr<base::TaskRunner> task_runner_;
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_config_service_unittest.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_config_service_unittest.cc
index d5624f0..ad46684 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_config_service_unittest.cc
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_config_service_unittest.cc
@@ -6,6 +6,7 @@
#include <string>
+#include "base/bind.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h"
#include "base/test/test_simple_task_runner.h"
@@ -197,8 +198,11 @@ TEST_F(DataReductionProxyConfigServiceTest, TrackerEnable) {
config_service_->AddObserver(&observer);
scoped_refptr<base::TestSimpleTaskRunner> task_runner_(
new base::TestSimpleTaskRunner());
- DataReductionProxyConfigTracker tracker(config_service_.get(),
- task_runner_.get());
+ DataReductionProxyConfigTracker tracker(
+ base::Bind(&data_reduction_proxy::DataReductionProxyConfigService::
+ UpdateProxyConfig,
+ base::Unretained(config_service_.get())),
+ task_runner_.get());
net::ProxyConfig expected_config;
expected_config.proxy_rules().ParseFromString(kDataReductionProxyRules);
EXPECT_CALL(observer, OnProxyConfigChanged(
@@ -221,8 +225,11 @@ TEST_F(DataReductionProxyConfigServiceTest, TrackerEnableRestricted) {
config_service_->AddObserver(&observer);
scoped_refptr<base::TestSimpleTaskRunner> task_runner_(
new base::TestSimpleTaskRunner());
- DataReductionProxyConfigTracker tracker(config_service_.get(),
- task_runner_.get());
+ DataReductionProxyConfigTracker tracker(
+ base::Bind(&data_reduction_proxy::DataReductionProxyConfigService::
+ UpdateProxyConfig,
+ base::Unretained(config_service_.get())),
+ task_runner_.get());
net::ProxyConfig expected_config;
expected_config.proxy_rules().ParseFromString(
kDataReductionProxyRestrictedRules);
@@ -246,8 +253,11 @@ TEST_F(DataReductionProxyConfigServiceTest, TrackerDisable) {
config_service_->AddObserver(&observer);
scoped_refptr<base::TestSimpleTaskRunner> task_runner_(
new base::TestSimpleTaskRunner());
- DataReductionProxyConfigTracker tracker(config_service_.get(),
- task_runner_.get());
+ DataReductionProxyConfigTracker tracker(
+ base::Bind(&data_reduction_proxy::DataReductionProxyConfigService::
+ UpdateProxyConfig,
+ base::Unretained(config_service_.get())),
+ task_runner_.get());
net::ProxyConfig expected_config;
expected_config.proxy_rules().ParseFromString(kSystemProxyRules);
EXPECT_CALL(observer, OnProxyConfigChanged(
@@ -266,8 +276,11 @@ TEST_F(DataReductionProxyConfigServiceTest, TrackerBypassList) {
base::MessageLoopForUI loop;
scoped_refptr<base::TestSimpleTaskRunner> task_runner_(
new base::TestSimpleTaskRunner());
- DataReductionProxyConfigTracker tracker(config_service_.get(),
- task_runner_.get());
+ DataReductionProxyConfigTracker tracker(
+ base::Bind(&data_reduction_proxy::DataReductionProxyConfigService::
+ UpdateProxyConfig,
+ base::Unretained(config_service_.get())),
+ task_runner_.get());
tracker.AddHostPatternToBypass("http://www.google.com");
tracker.AddHostPatternToBypass("fefe:13::abc/33");
tracker.AddURLPatternToBypass("foo.org/images/*");
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_params.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_params.cc
index fa75c6b..9296a20 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_params.cc
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_params.cc
@@ -5,6 +5,7 @@
#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
#include "base/command_line.h"
+#include "base/memory/scoped_ptr.h"
#include "base/metrics/field_trial.h"
#include "base/time/time.h"
#include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h"
@@ -73,6 +74,28 @@ DataReductionProxyParams::DataReductionProxyParams(int flags)
DCHECK(result);
}
+scoped_ptr<DataReductionProxyParams> DataReductionProxyParams::Clone() {
+ return scoped_ptr<DataReductionProxyParams>(
+ new DataReductionProxyParams(*this));
+}
+
+DataReductionProxyParams::DataReductionProxyParams(
+ const DataReductionProxyParams& other)
+ : origin_(other.origin_),
+ fallback_origin_(other.fallback_origin_),
+ ssl_origin_(other.ssl_origin_),
+ alt_origin_(other.alt_origin_),
+ alt_fallback_origin_(other.alt_fallback_origin_),
+ probe_url_(other.probe_url_),
+ warmup_url_(other.warmup_url_),
+ allowed_(other.allowed_),
+ fallback_allowed_(other.fallback_allowed_),
+ alt_allowed_(other.alt_allowed_),
+ promo_allowed_(other.promo_allowed_),
+ holdback_(other.holdback_),
+ configured_on_command_line_(other.configured_on_command_line_) {
+}
+
DataReductionProxyParams::~DataReductionProxyParams() {
}
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_params.h b/components/data_reduction_proxy/browser/data_reduction_proxy_params.h
index ae024b8..78a63a4 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_params.h
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_params.h
@@ -9,7 +9,7 @@
#include <utility>
#include <vector>
-#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
#include "net/base/host_port_pair.h"
#include "net/proxy/proxy_retry_info.h"
#include "url/gurl.h"
@@ -80,8 +80,10 @@ class DataReductionProxyParams {
// A standard configuration has a primary proxy, and a fallback proxy for
// HTTP traffic. The alternative configuration has a different primary and
// fallback proxy for HTTP traffic, and an SSL proxy.
+ explicit DataReductionProxyParams(int flags);
- DataReductionProxyParams(int flags);
+ // Creates a copy of the configuration parameters.
+ scoped_ptr<DataReductionProxyParams> Clone();
virtual ~DataReductionProxyParams();
@@ -207,6 +209,8 @@ class DataReductionProxyParams {
DataReductionProxyParams(int flags,
bool should_call_init);
+ DataReductionProxyParams(const DataReductionProxyParams& params);
+
// Initialize the values of the proxies, and probe URL, from command
// line flags and preprocessor constants, and check that there are
// corresponding definitions for the allowed configurations.
@@ -237,6 +241,9 @@ class DataReductionProxyParams {
const GURL& primary,
const GURL& fallback,
base::TimeDelta* min_retry_delay) const;
+
+ DataReductionProxyParams& operator=(const DataReductionProxyParams& params);
+
GURL origin_;
GURL fallback_origin_;
GURL ssl_origin_;
@@ -246,14 +253,12 @@ class DataReductionProxyParams {
GURL warmup_url_;
bool allowed_;
- const bool fallback_allowed_;
+ bool fallback_allowed_;
bool alt_allowed_;
- const bool promo_allowed_;
+ bool promo_allowed_;
bool holdback_;
bool configured_on_command_line_;
-
- DISALLOW_COPY_AND_ASSIGN(DataReductionProxyParams);
};
} // namespace data_reduction_proxy
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc
index 1e20219..60ec9c1 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc
@@ -91,6 +91,7 @@ DataReductionProxySettings::DataReductionProxySettings(
: restricted_by_carrier_(false),
enabled_by_user_(false),
disabled_on_vpn_(false),
+ unreachable_(false),
prefs_(NULL),
local_state_prefs_(NULL),
url_request_context_getter_(NULL) {
@@ -218,14 +219,13 @@ DataReductionProxySettings::GetDailyOriginalContentLengths() {
return GetDailyContentLengths(prefs::kDailyHttpOriginalContentLength);
}
-bool DataReductionProxySettings::IsDataReductionProxyUnreachable() {
- DCHECK(thread_checker_.CalledOnValidThread());
- return usage_stats_ && usage_stats_->isDataReductionProxyUnreachable();
+void DataReductionProxySettings::SetUnreachable(bool unreachable) {
+ unreachable_ = unreachable;
}
-void DataReductionProxySettings::SetDataReductionProxyUsageStats(
- DataReductionProxyUsageStats* usage_stats) {
- usage_stats_ = usage_stats;
+bool DataReductionProxySettings::IsDataReductionProxyUnreachable() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ return unreachable_;
}
DataReductionProxySettings::ContentLengthList
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_settings.h b/components/data_reduction_proxy/browser/data_reduction_proxy_settings.h
index a493813..f974b66 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_settings.h
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_settings.h
@@ -16,7 +16,6 @@
#include "base/threading/thread_checker.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_configurator.h"
#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
-#include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h"
#include "net/base/net_util.h"
#include "net/base/network_change_notifier.h"
#include "net/url_request/url_fetcher_delegate.h"
@@ -98,10 +97,6 @@ class DataReductionProxySettings
return params_.get();
}
- DataReductionProxyUsageStats* usage_stats() const {
- return usage_stats_;
- }
-
// 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
@@ -165,15 +160,14 @@ class DataReductionProxySettings
int64* received_content_length,
int64* last_update_time);
+ // Records that the data reduction proxy is unreachable or not.
+ void SetUnreachable(bool unreachable);
+
// Returns whether the data reduction proxy is unreachable. Returns true
// if no request has successfully completed through proxy, even though atleast
// some of them should have.
bool IsDataReductionProxyUnreachable();
- // Set the data reduction proxy usage stats.
- void SetDataReductionProxyUsageStats(
- DataReductionProxyUsageStats* usage_stats);
-
// Returns an vector containing the aggregate received HTTP content in the
// last |kNumDaysInHistory| days.
ContentLengthList GetDailyReceivedContentLengths();
@@ -304,6 +298,7 @@ class DataReductionProxySettings
bool restricted_by_carrier_;
bool enabled_by_user_;
bool disabled_on_vpn_;
+ bool unreachable_;
scoped_ptr<net::URLFetcher> fetcher_;
scoped_ptr<net::URLFetcher> warmup_fetcher_;
@@ -323,7 +318,6 @@ class DataReductionProxySettings
base::ThreadChecker thread_checker_;
scoped_ptr<DataReductionProxyParams> params_;
- DataReductionProxyUsageStats* usage_stats_;
DISALLOW_COPY_AND_ASSIGN(DataReductionProxySettings);
};
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc
index d500301..bddfef4 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc
@@ -4,6 +4,9 @@
#include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h"
+#include "base/bind.h"
+#include "base/callback.h"
+#include "base/message_loop/message_loop_proxy.h"
#include "base/metrics/histogram.h"
#include "net/base/net_errors.h"
#include "net/proxy/proxy_retry_info.h"
@@ -23,15 +26,14 @@ namespace data_reduction_proxy {
DataReductionProxyUsageStats::DataReductionProxyUsageStats(
DataReductionProxyParams* params,
- MessageLoopProxy* ui_thread_proxy,
- MessageLoopProxy* io_thread_proxy)
+ MessageLoopProxy* ui_thread_proxy)
: data_reduction_proxy_params_(params),
last_bypass_type_(ProxyService::BYPASS_EVENT_TYPE_MAX),
triggering_request_(true),
ui_thread_proxy_(ui_thread_proxy),
- io_thread_proxy_(io_thread_proxy),
eligible_num_requests_through_proxy_(0),
- actual_num_requests_through_proxy_(0) {
+ actual_num_requests_through_proxy_(0),
+ unavailable_(false) {
NetworkChangeNotifier::AddNetworkChangeObserver(this);
};
@@ -41,47 +43,27 @@ DataReductionProxyUsageStats::~DataReductionProxyUsageStats() {
void DataReductionProxyUsageStats::OnUrlRequestCompleted(
const net::URLRequest* request, bool started) {
- DCHECK(io_thread_proxy_->BelongsToCurrentThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
if (request->status().status() == net::URLRequestStatus::SUCCESS) {
if (data_reduction_proxy_params_->IsDataReductionProxyEligible(request)) {
bool was_received_via_proxy =
data_reduction_proxy_params_->WasDataReductionProxyUsed(
request, NULL);
- ui_thread_proxy_->PostTask(FROM_HERE, base::Bind(
- &DataReductionProxyUsageStats::IncRequestCountsOnUiThread,
- base::Unretained(this), was_received_via_proxy));
+ IncrementRequestCounts(was_received_via_proxy);
}
}
}
-/**
- * Determines if the data reduction proxy is currently unreachable. We keep
- * track of count of requests which go through data reduction proxy as well as
- * count of requests which are eligible to go through the proxy. If and only if
- * no requests go through proxy and some requests were eligible, we conclude
- * that the proxy is unreachable.
- *
- * Returns true if the data reduction proxy is unreachable.
- */
-bool DataReductionProxyUsageStats::isDataReductionProxyUnreachable() {
- DCHECK(ui_thread_proxy_->BelongsToCurrentThread());
-
- return eligible_num_requests_through_proxy_ > 0 &&
- actual_num_requests_through_proxy_ == 0;
-}
-
void DataReductionProxyUsageStats::OnNetworkChanged(
NetworkChangeNotifier::ConnectionType type) {
DCHECK(thread_checker_.CalledOnValidThread());
- ui_thread_proxy_->PostTask(FROM_HERE, base::Bind(
- &DataReductionProxyUsageStats::ClearRequestCountsOnUiThread,
- base::Unretained(this)));
+ ClearRequestCounts();
}
-void DataReductionProxyUsageStats::IncRequestCountsOnUiThread(
+void DataReductionProxyUsageStats::IncrementRequestCounts(
bool was_received_via_proxy) {
- DCHECK(ui_thread_proxy_->BelongsToCurrentThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
if (was_received_via_proxy) {
actual_num_requests_through_proxy_++;
}
@@ -91,14 +73,36 @@ void DataReductionProxyUsageStats::IncRequestCountsOnUiThread(
// gets blocked, we reset the counts occasionally.
if (eligible_num_requests_through_proxy_ > 50
&& actual_num_requests_through_proxy_ > 0) {
- ClearRequestCountsOnUiThread();
+ ClearRequestCounts();
+ } else {
+ MaybeNotifyUnavailability();
}
}
-void DataReductionProxyUsageStats::ClearRequestCountsOnUiThread() {
- DCHECK(ui_thread_proxy_->BelongsToCurrentThread());
+void DataReductionProxyUsageStats::ClearRequestCounts() {
+ DCHECK(thread_checker_.CalledOnValidThread());
eligible_num_requests_through_proxy_ = 0;
actual_num_requests_through_proxy_ = 0;
+ MaybeNotifyUnavailability();
+}
+
+void DataReductionProxyUsageStats::MaybeNotifyUnavailability() {
+ bool prev_unavailable = unavailable_;
+ unavailable_ = (eligible_num_requests_through_proxy_ > 0 &&
+ actual_num_requests_through_proxy_ == 0);
+ if (prev_unavailable != unavailable_) {
+ ui_thread_proxy_->PostTask(FROM_HERE, base::Bind(
+ &DataReductionProxyUsageStats::NotifyUnavailabilityOnUIThread,
+ base::Unretained(this),
+ unavailable_));
+ }
+}
+
+void DataReductionProxyUsageStats::NotifyUnavailabilityOnUIThread(
+ bool unavailable) {
+ DCHECK(ui_thread_proxy_->BelongsToCurrentThread());
+ if (!unavailable_callback_.is_null())
+ unavailable_callback_.Run(unavailable);
}
void DataReductionProxyUsageStats::SetBypassType(
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h b/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h
index 4e3dbfe..4fe9c5e 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h
@@ -5,6 +5,7 @@
#ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_STATS_H_
#define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_STATS_H_
+#include "base/callback.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/prefs/pref_member.h"
#include "base/threading/thread_checker.h"
@@ -19,21 +20,23 @@ namespace data_reduction_proxy {
class DataReductionProxyUsageStats
: public net::NetworkChangeNotifier::NetworkChangeObserver {
public:
- // MessageLoopProxy instances are owned by io_thread. |params| outlives
+ // MessageLoopProxy instance is owned by io_thread. |params| outlives
// this class instance.
DataReductionProxyUsageStats(DataReductionProxyParams* params,
- base::MessageLoopProxy* ui_thread_proxy,
- base::MessageLoopProxy* io_thread_proxy);
+ base::MessageLoopProxy* ui_thread_proxy);
virtual ~DataReductionProxyUsageStats();
+ // Sets the callback to be called on the UI thread when the unavailability
+ // status has changed.
+ void set_unavailable_callback(
+ const base::Callback<void(bool)>& unavailable_callback) {
+ unavailable_callback_ = unavailable_callback;
+ }
+
// Callback intended to be called from |ChromeNetworkDelegate| when a
// request completes. This method is used to gather usage stats.
void OnUrlRequestCompleted(const net::URLRequest* request, bool started);
- // Determines whether the data reduction proxy is unreachable.
- // Returns true if data reduction proxy is unreachable.
- bool isDataReductionProxyUnreachable();
-
// Records the last bypass reason to |bypass_type_| and sets
// |triggering_request_| to true. A triggering request is the first request to
// cause the current bypass.
@@ -58,6 +61,23 @@ class DataReductionProxyUsageStats
BYPASSED_BYTES_TYPE_MAX /* This must always be last.*/
};
+ // NetworkChangeNotifier::NetworkChangeObserver:
+ virtual void OnNetworkChanged(
+ net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
+
+ // Counts requests that went through the data reduction proxy and counts
+ // requests that were eligible to go through the proxy.
+ void IncrementRequestCounts(bool actual);
+ void ClearRequestCounts();
+
+ // Checks if the availability status of the data reduction proxy has changed,
+ // and notifies the UIThread via NotifyUnavailabilityOnUIThread if so. The
+ // data reduction proxy is considered unavailable if and only if no requests
+ // went through the proxy but some eligible requests were service by other
+ // routes.
+ void MaybeNotifyUnavailability();
+ void NotifyUnavailabilityOnUIThread(bool unavailable);
+
DataReductionProxyParams* data_reduction_proxy_params_;
// The last reason for bypass as determined by
// MaybeBypassProxyAndPrepareToRetry
@@ -65,7 +85,6 @@ class DataReductionProxyUsageStats
// True if the last request triggered the current bypass.
bool triggering_request_;
base::MessageLoopProxy* ui_thread_proxy_;
- base::MessageLoopProxy* io_thread_proxy_;
// The following 2 fields are used to determine if data reduction proxy is
// unreachable. We keep a count of requests which should go through
@@ -78,15 +97,12 @@ class DataReductionProxyUsageStats
// Explicit bypasses are not part of this count. This is the desired behavior
// since otherwise both counts would be identical.
unsigned long eligible_num_requests_through_proxy_;
- // Count of successfull requests through data reduction proxy.
- unsigned long actual_num_requests_through_proxy_;
- // NetworkChangeNotifier::NetworkChangeObserver:
- virtual void OnNetworkChanged(
- net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
+ // Count of successful requests through data reduction proxy.
+ unsigned long actual_num_requests_through_proxy_;
- void IncRequestCountsOnUiThread(bool actual);
- void ClearRequestCountsOnUiThread();
+ // Whether or not the data reduction proxy is unavailable.
+ bool unavailable_;
base::ThreadChecker thread_checker_;
@@ -95,6 +111,9 @@ class DataReductionProxyUsageStats
BypassedBytesType bypassed_bytes_type,
int64 content_length);
+ // Called when the unavailability status has changed. Runs on the UI thread.
+ base::Callback<void(bool)> unavailable_callback_;
+
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyUsageStats);
};
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats_unittest.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats_unittest.cc
index 39a951f..3314253 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats_unittest.cc
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats_unittest.cc
@@ -4,6 +4,7 @@
#include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h"
+#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
#include "net/base/request_priority.h"
#include "net/url_request/url_request.h"
@@ -45,9 +46,15 @@ class DataReductionProxyUsageStatsTest : public testing::Test {
DataReductionProxyUsageStatsTest()
: loop_proxy_(MessageLoopProxy::current().get()),
context_(true),
- mock_url_request_(GURL(), net::IDLE, &delegate_, &context_) {
+ mock_url_request_(GURL(), net::IDLE, &delegate_, &context_),
+ unavailable_(false) {
context_.Init();
}
+
+ void NotifyUnavailable(bool unavailable) {
+ unavailable_ = unavailable;
+ }
+
// Required for MessageLoopProxy::current().
base::MessageLoopForUI loop_;
MessageLoopProxy* loop_proxy_;
@@ -57,9 +64,10 @@ class DataReductionProxyUsageStatsTest : public testing::Test {
TestDelegate delegate_;
DataReductionProxyParamsMock mock_params_;
URLRequest mock_url_request_;
+ bool unavailable_;
};
-TEST_F(DataReductionProxyUsageStatsTest, isDataReductionProxyUnreachable) {
+TEST_F(DataReductionProxyUsageStatsTest, IsDataReductionProxyUnreachable) {
struct TestCase {
bool is_proxy_eligible;
bool was_proxy_used;
@@ -93,13 +101,15 @@ TEST_F(DataReductionProxyUsageStatsTest, isDataReductionProxyUnreachable) {
scoped_ptr<DataReductionProxyUsageStats> usage_stats(
new DataReductionProxyUsageStats(
- &mock_params_, loop_proxy_, loop_proxy_));
+ &mock_params_, loop_proxy_));
+ usage_stats->set_unavailable_callback(
+ base::Bind(&DataReductionProxyUsageStatsTest::NotifyUnavailable,
+ base::Unretained(this)));
usage_stats->OnUrlRequestCompleted(&mock_url_request_, false);
MessageLoop::current()->RunUntilIdle();
- EXPECT_EQ(test_case.is_unreachable,
- usage_stats->isDataReductionProxyUnreachable());
+ EXPECT_EQ(test_case.is_unreachable, unavailable_);
}
}