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..9d93ec6818e01239c85c31a3062e3d48f042517e |
--- /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_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/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, |
+ DataReductionProxySettings* settings, |
+ scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
+ scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) |
+ : client_(client), |
+ params_(params.Pass()), |
+ configurator_(configurator.Pass()), |
+ compression_stats_(statistics_prefs.Pass()), |
+ event_store_(event_store.Pass()), |
+ settings_(settings), |
+ io_task_runner_(io_task_runner), |
+ ui_task_runner_(ui_task_runner) { |
+ auth_request_handler_.reset(new DataReductionProxyAuthRequestHandler( |
+ client_, params_.get(), io_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 (compression_stats_.get()) |
+ compression_stats_->WritePrefs(); |
+ enabled_.Destroy(); |
+} |
+ |
+void DataReductionProxyIOData::ShutdownStatisicsPrefsOnUIThread() { |
+ if (compression_stats_.get()) |
+ compression_stats_->ShutdownOnUIThread(); |
+} |
+ |
+bool DataReductionProxyIOData::IsEnabled() const { |
+ return enabled_.GetValue() || CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kEnableDataReductionProxy); |
+} |
+ |
+net::URLRequestInterceptor* DataReductionProxyIOData::CreateInterceptor() { |
+ return new DataReductionProxyInterceptor(params_.get(), bypass_stats_.get(), |
+ event_store_.get()); |
+} |
+ |
+void DataReductionProxyIOData::EnableCompressionStatisticsLogging( |
+ PrefService* prefs, |
+ const base::TimeDelta& commit_delay) { |
+ DCHECK(ui_task_runner_.get()); |
+ compression_stats_.reset( |
+ new DataReductionProxyStatisticsPrefs( |
+ prefs, ui_task_runner_, commit_delay)); |
+} |
+ |
+scoped_ptr<DataReductionProxyNetworkDelegate> |
+DataReductionProxyIOData::CreateNetworkDelegate( |
+ scoped_ptr<net::NetworkDelegate> wrapped_network_delegate, |
+ bool allow_proxy_config_overrides, |
+ bool track_proxy_bypass_statistics) { |
+ scoped_ptr<DataReductionProxyNetworkDelegate> network_delegate( |
+ new DataReductionProxyNetworkDelegate( |
+ wrapped_network_delegate.Pass(), params_.get(), |
+ auth_request_handler_.get(), configurator_.get())); |
+ if (allow_proxy_config_overrides) { |
+ network_delegate->InitProxyConfigOverrider( |
+ base::Bind(data_reduction_proxy::OnResolveProxyHandler)); |
+ } |
+ if (track_proxy_bypass_statistics) { |
+ bypass_stats_.reset( |
+ new data_reduction_proxy::DataReductionProxyUsageStats( |
+ params_.get(), settings_, ui_task_runner_)); |
+ network_delegate->InitStatisticsPrefsAndUMA( |
+ ui_task_runner_, compression_stats_.get(), &enabled_, |
+ bypass_stats_.get()); |
+ } |
+ return network_delegate.Pass(); |
+} |
+ |
+void DataReductionProxyIOData::CreateProxyDelegate() { |
+ proxy_delegate_.reset( |
+ new data_reduction_proxy::DataReductionProxyDelegate( |
+ auth_request_handler_.get(), params_.get())); |
+} |
+ |
+} // namespace data_reduction_proxy |