Chromium Code Reviews| 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 | |
| 32 // static | |
| 33 scoped_ptr<PrefService> | |
| 34 CronetDataReductionProxy::CreatePrefService() { | |
| 35 PrefRegistrySimple* pref_registry = new PrefRegistrySimple(); | |
| 36 data_reduction_proxy::RegisterSimpleProfilePrefs(pref_registry); | |
| 37 base::PrefServiceFactory pref_service_factory; | |
| 38 pref_service_factory.set_user_prefs( | |
| 39 make_scoped_refptr(new CronetPrefStore())); | |
| 40 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); | |
| 41 return pref_service_factory.Create(pref_registry).Pass(); | |
| 42 } | |
| 43 | |
| 44 CronetDataReductionProxy::CronetDataReductionProxy( | |
| 45 const std::string& key, | |
| 46 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
| 47 net::NetLog* net_log) | |
| 48 : task_runner_(task_runner) { | |
| 49 prefs_ = CreatePrefService(); | |
| 50 settings_.reset( | |
| 51 new data_reduction_proxy::DataReductionProxySettings()); | |
| 52 io_data_.reset( | |
| 53 new data_reduction_proxy::DataReductionProxyIOData( | |
| 54 data_reduction_proxy::Client::CRONET_ANDROID, | |
| 55 data_reduction_proxy::DataReductionProxyParams::kAllowed | | |
| 56 data_reduction_proxy::DataReductionProxyParams::kFallbackAllowed, | |
| 57 net_log, task_runner, task_runner, false)); | |
| 58 io_data_->request_options()->SetKeyOnIO(key); | |
| 59 } | |
| 60 | |
| 61 CronetDataReductionProxy::~CronetDataReductionProxy() { | |
| 62 io_data_->ShutdownOnUIThread(); | |
| 63 } | |
| 64 | |
| 65 net::NetworkDelegate* CronetDataReductionProxy::CreateNetworkDelegate( | |
| 66 scoped_ptr<net::NetworkDelegate> wrapped_network_delegate) { | |
| 67 return io_data_->CreateNetworkDelegate( | |
| 68 wrapped_network_delegate.Pass(), | |
| 69 false /* No UMA is produced to track bypasses*/ ).release(); | |
| 70 } | |
| 71 | |
| 72 scoped_ptr<net::URLRequestInterceptor> | |
| 73 CronetDataReductionProxy::CreateInterceptor() { | |
| 74 return io_data_->CreateInterceptor(); | |
| 75 } | |
| 76 | |
| 77 void CronetDataReductionProxy::Init(bool enable, | |
| 78 net::URLRequestContext* context) { | |
| 79 url_request_context_getter_ = | |
| 80 new net::TrivialURLRequestContextGetter( | |
| 81 context, task_runner_); | |
| 82 base::TimeDelta commit_delay = base::TimeDelta(); | |
|
mmenke
2015/03/13 18:16:47
explicit initialization not needed. Suggest just
bengr
2015/03/19 01:03:50
Done.
| |
| 83 scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs> | |
| 84 statistics_prefs = make_scoped_ptr( | |
|
mmenke
2015/03/13 18:16:47
"make_scoped_ptr(" not needed. Can just use
scop
bengr
2015/03/19 01:03:50
I thought make_scoped pointer was just shorthand f
mmenke
2015/03/19 02:50:17
You're missing that the "shorthand" is longer in t
bengr
2015/03/19 17:56:24
Oh. I misread my own code. Yes, of course. I compl
| |
| 85 new data_reduction_proxy::DataReductionProxyStatisticsPrefs( | |
| 86 prefs_.get(), task_runner_, commit_delay)); | |
| 87 scoped_ptr<data_reduction_proxy::DataReductionProxyService> | |
| 88 data_reduction_proxy_service( | |
| 89 new data_reduction_proxy::DataReductionProxyService( | |
| 90 statistics_prefs.Pass(), settings_.get(), | |
| 91 url_request_context_getter_.get())); | |
| 92 io_data_->SetDataReductionProxyService( | |
| 93 data_reduction_proxy_service->GetWeakPtr()); | |
| 94 settings_->InitDataReductionProxySettings( | |
| 95 prefs_.get(), io_data_.get(), data_reduction_proxy_service.Pass()); | |
| 96 settings_->SetDataReductionProxyEnabled(enable); | |
| 97 } | |
| 98 | |
| 99 } // namespace cronet | |
| OLD | NEW |