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..0c3ab096ffa6ea8af0d53c428356c4930576949d |
| --- /dev/null |
| +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc |
| @@ -0,0 +1,119 @@ |
| +// Copyright 2015 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 { |
| + |
| +DataReductionProxyIOData::DataReductionProxyIOData( |
| + const Client& client, |
| + 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), |
| + statistics_prefs_(statistics_prefs.Pass()), |
| + settings_(settings), |
| + io_task_runner_(io_task_runner), |
| + ui_task_runner_(ui_task_runner) { |
| + DCHECK(settings); |
| + DCHECK(net_log); |
| + DCHECK(io_task_runner_.get()); |
| + DCHECK(ui_task_runner_.get()); |
| + params_ = settings->params()->Clone(); |
| + 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() { |
|
mmenke
2015/01/22 17:14:49
Can we DCHECK that ShutdownStatisicsPrefsOnUIThrea
bengr
2015/01/23 20:09:04
Done.
|
| +} |
| + |
| +void DataReductionProxyIOData::InitPrefsOnUIThread(PrefService* pref_service) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + enabled_.Init(prefs::kDataReductionProxyEnabled, pref_service); |
| + enabled_.MoveToThread(io_task_runner_); |
| +} |
| + |
| +void DataReductionProxyIOData::DestroyPrefsOnUIThread() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
|
mmenke
2015/01/22 17:14:49
This is really weird. This class is called "...IO
bengr
2015/01/23 20:09:03
Done.
|
| + if (statistics_prefs_) |
| + statistics_prefs_->WritePrefs(); |
| + enabled_.Destroy(); |
| +} |
| + |
| +void DataReductionProxyIOData::ShutdownStatisicsPrefsOnUIThread() { |
|
mmenke
2015/01/22 17:14:49
I don't think we need both this and DestroyPrefsOn
bengr
2015/01/23 20:09:03
Done.
|
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + if (statistics_prefs_) |
| + statistics_prefs_->ShutdownOnUIThread(); |
| +} |
| + |
| +bool DataReductionProxyIOData::IsEnabled() const { |
| + DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| + return enabled_.GetValue() || |
| + base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kEnableDataReductionProxy); |
| +} |
| + |
| +scoped_ptr<net::URLRequestInterceptor> |
| +DataReductionProxyIOData::CreateInterceptor() { |
| + DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| + return make_scoped_ptr(new DataReductionProxyInterceptor( |
| + params_.get(), usage_stats_.get(), event_store_.get())); |
| +} |
| + |
| +void DataReductionProxyIOData::EnableCompressionStatisticsLogging( |
|
mmenke
2015/01/22 17:14:48
Suggest moving this up (Here and in the header fil
bengr
2015/01/23 20:09:03
Done.
|
| + PrefService* prefs, |
| + const base::TimeDelta& commit_delay) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + DCHECK(ui_task_runner_.get()); |
| + statistics_prefs_.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) { |
| + DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| + scoped_ptr<DataReductionProxyNetworkDelegate> network_delegate( |
| + new DataReductionProxyNetworkDelegate( |
| + wrapped_network_delegate.Pass(), params_.get(), |
| + auth_request_handler_.get(), configurator_.get())); |
| + if (track_proxy_bypass_statistics && !usage_stats_) { |
| + usage_stats_.reset( |
| + new data_reduction_proxy::DataReductionProxyUsageStats( |
| + params_.get(), settings_, ui_task_runner_)); |
| + network_delegate->InitStatisticsPrefsAndUMA( |
| + ui_task_runner_, statistics_prefs_.get(), &enabled_, |
| + usage_stats_.get()); |
| + } |
| + return network_delegate.Pass(); |
| +} |
| + |
| +} // namespace data_reduction_proxy |