OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/cronet/android/cronet_data_reduction_proxy.h" |
| 6 |
| 7 #include "base/prefs/pref_registry_simple.h" |
| 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/prefs/pref_service_factory.h" |
| 10 #include "base/single_thread_task_runner.h" |
| 11 #include "components/cronet/android/cronet_pref_store.h" |
| 12 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d
ata.h" |
| 13 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_netw
ork_delegate.h" |
| 14 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_pref
s.h" |
| 15 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ
est_options.h" |
| 16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv
ice.h" |
| 17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett
ings.h" |
| 18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_stat
istics_prefs.h" |
| 19 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" |
| 20 #include "net/base/net_log.h" |
| 21 #include "net/url_request/url_request_context_getter.h" |
| 22 #include "net/url_request/url_request_interceptor.h" |
| 23 |
| 24 namespace { |
| 25 // Shows notifications which correspond to PersistentPrefStore's reading errors. |
| 26 void HandleReadError(PersistentPrefStore::PrefReadError error) { |
| 27 } |
| 28 } // namespace |
| 29 |
| 30 namespace cronet { |
| 31 namespace { |
| 32 scoped_ptr<PrefService> CreatePrefService() { |
| 33 PrefRegistrySimple* pref_registry = new PrefRegistrySimple(); |
| 34 data_reduction_proxy::RegisterSimpleProfilePrefs(pref_registry); |
| 35 base::PrefServiceFactory pref_service_factory; |
| 36 pref_service_factory.set_user_prefs( |
| 37 make_scoped_refptr(new CronetPrefStore())); |
| 38 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); |
| 39 return pref_service_factory.Create(pref_registry).Pass(); |
| 40 } |
| 41 } // namespace |
| 42 |
| 43 CronetDataReductionProxy::CronetDataReductionProxy( |
| 44 const std::string& key, |
| 45 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 46 net::NetLog* net_log) |
| 47 : task_runner_(task_runner) { |
| 48 prefs_ = CreatePrefService(); |
| 49 settings_.reset( |
| 50 new data_reduction_proxy::DataReductionProxySettings()); |
| 51 io_data_.reset( |
| 52 new data_reduction_proxy::DataReductionProxyIOData( |
| 53 data_reduction_proxy::Client::CRONET_ANDROID, |
| 54 data_reduction_proxy::DataReductionProxyParams::kAllowed | |
| 55 data_reduction_proxy::DataReductionProxyParams::kFallbackAllowed, |
| 56 net_log, task_runner, task_runner, false)); |
| 57 io_data_->request_options()->SetKeyOnIO(key); |
| 58 } |
| 59 |
| 60 CronetDataReductionProxy::~CronetDataReductionProxy() { |
| 61 io_data_->ShutdownOnUIThread(); |
| 62 } |
| 63 |
| 64 scoped_ptr<net::NetworkDelegate> |
| 65 CronetDataReductionProxy::CreateNetworkDelegate( |
| 66 scoped_ptr<net::NetworkDelegate> wrapped_network_delegate) { |
| 67 return io_data_->CreateNetworkDelegate(wrapped_network_delegate.Pass(), |
| 68 false /* No bypass UMA */ ); |
| 69 } |
| 70 |
| 71 scoped_ptr<net::URLRequestInterceptor> |
| 72 CronetDataReductionProxy::CreateInterceptor() { |
| 73 return io_data_->CreateInterceptor(); |
| 74 } |
| 75 |
| 76 void CronetDataReductionProxy::Init(bool enable, |
| 77 net::URLRequestContext* context) { |
| 78 url_request_context_getter_ = |
| 79 new net::TrivialURLRequestContextGetter( |
| 80 context, task_runner_); |
| 81 scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs> |
| 82 statistics_prefs( |
| 83 new data_reduction_proxy::DataReductionProxyStatisticsPrefs( |
| 84 prefs_.get(), task_runner_, base::TimeDelta())); |
| 85 scoped_ptr<data_reduction_proxy::DataReductionProxyService> |
| 86 data_reduction_proxy_service( |
| 87 new data_reduction_proxy::DataReductionProxyService( |
| 88 statistics_prefs.Pass(), settings_.get(), |
| 89 url_request_context_getter_.get())); |
| 90 io_data_->SetDataReductionProxyService( |
| 91 data_reduction_proxy_service->GetWeakPtr()); |
| 92 settings_->InitDataReductionProxySettings( |
| 93 prefs_.get(), io_data_.get(), data_reduction_proxy_service.Pass()); |
| 94 settings_->SetDataReductionProxyEnabled(enable); |
| 95 } |
| 96 |
| 97 } // namespace cronet |
OLD | NEW |