Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Unified Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc

Issue 778463002: Wrapped data reduction proxy initialization into its own class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@network-delegate
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc
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
new file mode 100644
index 0000000000000000000000000000000000000000..37bffcc4174933982e4474b39314650604135ee6
--- /dev/null
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc
@@ -0,0 +1,115 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h"
+
+#include "base/bind.h"
+#include "base/command_line.h"
+#include "base/prefs/pref_member.h"
+#include "base/single_thread_task_runner.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler.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_protocol.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/data_reduction_proxy/core/common/data_reduction_proxy_switches.h"
+
+namespace data_reduction_proxy {
+DataReductionProxyIOData::DataReductionProxyIOData(
+ const Client& client,
+ scoped_ptr<DataReductionProxyParams> params,
+ scoped_ptr<DataReductionProxyConfigurator> configurator,
+ scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs,
+ scoped_ptr<DataReductionProxyEventStore> event_store,
+ const DataReductionProxyNetworkDelegate::ProxyConfigGetter&
+ proxy_config_getter,
+ const base::Callback<void(bool)>& unavailable_callback,
+ scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
+ scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)
+ : client_(client),
+ params_(params.Pass()),
+ configurator_(configurator.Pass()),
+ statistics_prefs_(statistics_prefs.Pass()),
+ event_store_(event_store.Pass()),
+ proxy_config_getter_(proxy_config_getter),
+ unavailable_callback_(unavailable_callback),
+ io_task_runner_(io_task_runner),
+ ui_task_runner_(ui_task_runner) {
+}
+
+
+DataReductionProxyIOData::~DataReductionProxyIOData() {
+}
+
+void DataReductionProxyIOData::InitPrefsOnUIThread(
+ PrefService* pref_service,
+ scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) {
+ enabled_.Init(prefs::kDataReductionProxyEnabled, pref_service);
+ enabled_.MoveToThread(io_task_runner);
+}
+
+void DataReductionProxyIOData::DestroyPrefsOnUIThread() {
+ if (statistics_prefs_.get())
+ statistics_prefs_->WritePrefs();
+ enabled_.Destroy();
+}
+
+void DataReductionProxyIOData::ShutdownStatisicsPrefsOnUIThread() {
+ if (statistics_prefs_.get())
+ statistics_prefs_->ShutdownOnUIThread();
+}
+
+bool DataReductionProxyIOData::IsEnabled() const {
+ return enabled_.GetValue() || CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableDataReductionProxy);
+}
+
+net::URLRequestInterceptor* DataReductionProxyIOData::CreateInterceptor() {
+ return new DataReductionProxyInterceptor(params_.get(), usage_stats_.get(),
+ event_store_.get());
+}
+
+void DataReductionProxyIOData::CreateStatisticsPrefs(
mmenke 2014/12/17 21:37:22 I'd suggest calling this EnableStatisticsLogging.
bengr 2014/12/19 20:05:58 Done.
+ PrefService* prefs,
+ const base::TimeDelta& commit_delay) {
+ DCHECK(ui_task_runner_.get());
+ statistics_prefs_.reset(
+ new DataReductionProxyStatisticsPrefs(
+ prefs, ui_task_runner_, commit_delay));
+}
+
+void DataReductionProxyIOData::Init(
+ scoped_ptr<net::NetworkDelegate> wrapped_network_delegate,
+ bool allow_proxy_config_overrides,
+ bool capture_statistics,
+ bool create_proxy_delegate) {
+ auth_request_handler_.reset(new DataReductionProxyAuthRequestHandler(
+ client_, params_.get(), io_task_runner_));
+ usage_stats_.reset(new data_reduction_proxy::DataReductionProxyUsageStats(
+ params_.get(), ui_task_runner_));
+ usage_stats_->set_unavailable_callback(unavailable_callback_);
+ network_delegate_.reset(
+ new DataReductionProxyNetworkDelegate(
+ wrapped_network_delegate.Pass(), params_.get(),
+ auth_request_handler_.get(), proxy_config_getter_));
+ if (allow_proxy_config_overrides) {
+ network_delegate_->InitProxyConfigOverrider(
+ base::Bind(data_reduction_proxy::OnResolveProxyHandler));
+ }
+ if (capture_statistics) {
mmenke 2014/12/17 21:37:22 Can we just automatically do this if we have a sta
bengr 2014/12/19 20:05:58 No. This is for UMA, the other is for metrics that
+ network_delegate_->InitStatisticsPrefsAndUMA(
+ ui_task_runner_, statistics_prefs_.get(), &enabled_,
+ usage_stats_.get());
+ }
+ if (create_proxy_delegate) {
+ proxy_delegate_.reset(
+ new data_reduction_proxy::DataReductionProxyDelegate(
+ auth_request_handler_.get(), params_.get()));
+ }
+}
+
+} // namespace data_reduction_proxy

Powered by Google App Engine
This is Rietveld 408576698