Chromium Code Reviews| 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..f5438d4fef450159015d315a72456e1bf1416b92 |
| --- /dev/null |
| +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc |
| @@ -0,0 +1,111 @@ |
| +// 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_bypass_protocol.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_usage_stats.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 "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h" |
| +#include "net/base/net_log.h" |
| + |
| +namespace data_reduction_proxy { |
|
sclittle
2015/01/14 22:54:46
nit: add blank line before constructor
bengr
2015/01/15 00:30:31
Done.
|
| +DataReductionProxyIOData::DataReductionProxyIOData( |
| + const Client& client, |
| + scoped_ptr<DataReductionProxyParams> params, |
| + scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs, |
| + DataReductionProxySettings* settings, |
| + net::NetLog* net_log, |
| + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) |
| + : client_(client), |
| + params_(params.Pass()), |
| + compression_stats_(statistics_prefs.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_)); |
| + 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( |
| + auth_request_handler_.get(), params_.get())); |
| +} |
| + |
| + |
|
sclittle
2015/01/14 22:54:46
nit: remove blank line
bengr
2015/01/15 00:30:31
Done.
|
| +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() || |
| + base::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 track_proxy_bypass_statistics) { |
| + scoped_ptr<DataReductionProxyNetworkDelegate> network_delegate( |
| + new DataReductionProxyNetworkDelegate( |
| + wrapped_network_delegate.Pass(), params_.get(), |
| + auth_request_handler_.get(), configurator_.get())); |
| + 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(); |
| +} |
| + |
| +} // namespace data_reduction_proxy |