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 <string> | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/command_line.h" | |
| 11 #include "base/prefs/pref_registry_simple.h" | |
| 12 #include "base/prefs/pref_service.h" | |
| 13 #include "base/prefs/pref_service_factory.h" | |
| 14 #include "base/single_thread_task_runner.h" | |
| 15 #include "base/strings/string_split.h" | |
| 16 #include "components/cronet/android/cronet_pref_store.h" | |
| 17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d ata.h" | |
| 18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_netw ork_delegate.h" | |
| 19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_pref s.h" | |
| 20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ est_options.h" | |
| 21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h" | |
| 22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h" | |
| 23 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_stat istics_prefs.h" | |
| 24 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" | |
| 25 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h" | |
| 26 #include "net/base/net_log.h" | |
| 27 #include "net/url_request/url_request_context_getter.h" | |
| 28 #include "net/url_request/url_request_interceptor.h" | |
| 29 | |
| 30 namespace { | |
| 31 // Shows notifications which correspond to PersistentPrefStore's reading errors. | |
| 32 void HandleReadError(PersistentPrefStore::PrefReadError error) { | |
| 33 } | |
| 34 } // namespace | |
| 35 | |
| 36 namespace cronet { | |
| 37 namespace { | |
| 38 scoped_ptr<PrefService> CreatePrefService() { | |
| 39 PrefRegistrySimple* pref_registry = new PrefRegistrySimple(); | |
| 40 data_reduction_proxy::RegisterSimpleProfilePrefs(pref_registry); | |
| 41 base::PrefServiceFactory pref_service_factory; | |
| 42 pref_service_factory.set_user_prefs( | |
| 43 make_scoped_refptr(new CronetPrefStore())); | |
| 44 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); | |
| 45 return pref_service_factory.Create(pref_registry).Pass(); | |
| 46 } | |
| 47 | |
| 48 void AddOptionsToCommandLine(const std::string& options, | |
| 49 base::CommandLine* command_line) { | |
| 50 if (options.empty()) | |
| 51 return; | |
| 52 std::vector<std::string> option; | |
| 53 base::SplitString(options, ',', &option); | |
| 54 DCHECK_EQ(3u, option.size()); | |
| 55 command_line->AppendSwitchASCII( | |
| 56 data_reduction_proxy::switches::kDataReductionProxy, option[0]); | |
| 57 command_line->AppendSwitchASCII( | |
| 58 data_reduction_proxy::switches::kDataReductionProxyFallback,option[1]); | |
| 59 command_line->AppendSwitchASCII( | |
| 60 data_reduction_proxy::switches::kDataReductionProxySecureProxyCheckURL, | |
| 61 option[2]); | |
| 62 } | |
| 63 } // namespace | |
| 64 | |
| 65 CronetDataReductionProxy::CronetDataReductionProxy( | |
| 66 const std::string& key, | |
| 67 const std::string& options, | |
| 68 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
| 69 net::NetLog* net_log) | |
| 70 : task_runner_(task_runner) { | |
| 71 AddOptionsToCommandLine(options, base::CommandLine::ForCurrentProcess()); | |
| 72 prefs_ = CreatePrefService(); | |
| 73 settings_.reset( | |
| 74 new data_reduction_proxy::DataReductionProxySettings()); | |
| 75 io_data_.reset( | |
| 76 new data_reduction_proxy::DataReductionProxyIOData( | |
| 77 data_reduction_proxy::Client::CRONET_ANDROID, | |
| 78 data_reduction_proxy::DataReductionProxyParams::kAllowed | | |
| 79 data_reduction_proxy::DataReductionProxyParams::kFallbackAllowed, | |
| 80 net_log, task_runner, task_runner, false)); | |
| 81 io_data_->request_options()->SetKeyOnIO(key); | |
| 82 } | |
| 83 | |
| 84 CronetDataReductionProxy::~CronetDataReductionProxy() { | |
| 85 io_data_->ShutdownOnUIThread(); | |
| 86 } | |
| 87 | |
| 88 scoped_ptr<net::NetworkDelegate> | |
| 89 CronetDataReductionProxy::CreateNetworkDelegate( | |
| 90 scoped_ptr<net::NetworkDelegate> wrapped_network_delegate) { | |
| 91 return io_data_->CreateNetworkDelegate(wrapped_network_delegate.Pass(), | |
| 92 false /* No bypass UMA */ ); | |
| 93 } | |
| 94 | |
| 95 scoped_ptr<net::URLRequestInterceptor> | |
| 96 CronetDataReductionProxy::CreateInterceptor() { | |
| 97 return io_data_->CreateInterceptor(); | |
| 98 } | |
| 99 | |
| 100 void CronetDataReductionProxy::Init(bool enable, | |
| 101 net::URLRequestContext* context) { | |
| 102 url_request_context_getter_ = | |
| 103 new net::TrivialURLRequestContextGetter( | |
| 104 context, task_runner_); | |
| 105 scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs> | |
| 106 statistics_prefs( | |
| 107 new data_reduction_proxy::DataReductionProxyStatisticsPrefs( | |
| 108 prefs_.get(), task_runner_, base::TimeDelta())); | |
| 109 scoped_ptr<data_reduction_proxy::DataReductionProxyService> | |
| 110 data_reduction_proxy_service( | |
| 111 new data_reduction_proxy::DataReductionProxyService( | |
| 112 statistics_prefs.Pass(), settings_.get(), | |
| 113 url_request_context_getter_.get())); | |
|
mmenke
2015/04/01 15:46:14
Before landing this, could you land a small CL tha
bengr
2015/04/24 02:30:42
We can't because we get it as a raw pointer in Chr
| |
| 114 io_data_->SetDataReductionProxyService( | |
| 115 data_reduction_proxy_service->GetWeakPtr()); | |
| 116 settings_->InitDataReductionProxySettings( | |
| 117 prefs_.get(), io_data_.get(), data_reduction_proxy_service.Pass()); | |
| 118 settings_->SetDataReductionProxyEnabled(enable); | |
| 119 } | |
| 120 | |
| 121 } // namespace cronet | |
| OLD | NEW |