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..0ef1f7816243766e19c02c9bc50b272c2c3fc1a1 |
| --- /dev/null |
| +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc |
| @@ -0,0 +1,109 @@ |
| +// 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. |
| + |
| + |
|
mmenke
2015/01/16 19:03:21
nit: Remove extra linebreak.
bengr
2015/01/17 00:20:48
Done.
|
| +#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 { |
| + |
| +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) { |
|
mmenke
2015/01/16 19:03:21
Strongly suggest having methods DCHECK that the co
bengr
2015/01/17 00:20:48
Done.
|
| + 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())); |
| +} |
| + |
| +DataReductionProxyIOData::~DataReductionProxyIOData() { |
| +} |
| + |
| +void DataReductionProxyIOData::InitPrefsOnUIThread(PrefService* pref_service) { |
| + enabled_.Init(prefs::kDataReductionProxyEnabled, pref_service); |
| + enabled_.MoveToThread(io_task_runner_); |
| +} |
| + |
| +void DataReductionProxyIOData::DestroyPrefsOnUIThread() { |
| + if (compression_stats_.get()) |
|
mmenke
2015/01/16 19:03:20
Do we ever create one of these without compression
bengr
2015/01/17 00:20:47
Done. Yeah, Webview constructs the io data object
|
| + 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() { |
|
mmenke
2015/01/16 19:03:20
Know you'll have to call release() on it, but this
bengr
2015/01/17 00:20:48
Done.
|
| + 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) { |
|
mmenke
2015/01/16 19:03:21
Is track_proxy_bypass_statistics ever false now?
bengr
2015/01/17 00:20:47
Yeah. in Webview.
|
| + 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 |