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/command_line.h" | |
8 #include "base/prefs/pref_registry_simple.h" | |
9 #include "base/prefs/pref_service.h" | |
10 #include "base/prefs/pref_service_factory.h" | |
11 #include "base/single_thread_task_runner.h" | |
12 #include "components/cronet/android/cronet_in_memory_pref_store.h" | |
13 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_comp ression_stats.h" | |
14 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d ata.h" | |
15 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_netw ork_delegate.h" | |
16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_pref s.h" | |
17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ est_options.h" | |
18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h" | |
19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h" | |
20 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" | |
21 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h" | |
22 #include "net/url_request/url_request_context_getter.h" | |
23 #include "net/url_request/url_request_interceptor.h" | |
24 | |
25 namespace net { | |
26 class NetLog; | |
mmenke
2015/04/24 19:10:28
This is also forward declared in the header, so no
bengr
2015/04/24 21:13:50
Done.
| |
27 } | |
28 | |
29 namespace { | |
30 // Shows notifications which correspond to PersistentPrefStore's reading errors. | |
31 void HandleReadError(PersistentPrefStore::PrefReadError error) { | |
32 } | |
33 } // namespace | |
mmenke
2015/04/24 19:10:27
This block can be removed, per later comment.
bengr
2015/04/24 21:13:50
Done.
| |
34 | |
35 namespace cronet { | |
36 namespace { | |
mmenke
2015/04/24 19:10:27
int break after start of namespace (Can include on
bengr
2015/04/24 21:13:50
Done.
| |
37 scoped_ptr<PrefService> CreatePrefService() { | |
38 PrefRegistrySimple* pref_registry = new PrefRegistrySimple(); | |
mmenke
2015/04/24 19:27:23
using a scoped_refptr here makes it clearer this i
bengr
2015/04/24 21:13:50
Done.
| |
39 data_reduction_proxy::RegisterSimpleProfilePrefs(pref_registry); | |
40 base::PrefServiceFactory pref_service_factory; | |
41 pref_service_factory.set_user_prefs( | |
42 make_scoped_refptr(new CronetInMemoryPrefStore())); | |
43 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); | |
mmenke
2015/04/24 19:10:28
This isn't needed. PrefServiceFactory does this e
bengr
2015/04/24 21:13:50
Done.
| |
44 return pref_service_factory.Create(pref_registry).Pass(); | |
45 } | |
46 | |
47 void AddOptionsToCommandLine(const std::string& primary_proxy, | |
48 const std::string& fallback_proxy, | |
49 const std::string& secure_proxy_check_url, | |
50 base::CommandLine* command_line) { | |
51 DCHECK((primary_proxy.empty() && fallback_proxy.empty() && | |
mmenke
2015/04/24 19:10:27
include base/logging.h for DCHECK
bengr
2015/04/24 21:13:50
Done.
| |
52 secure_proxy_check_url.empty()) || | |
mmenke
2015/04/24 19:10:27
If these are all empty, can we just not create thi
bengr
2015/04/24 21:13:50
These override statically configured defaults, so
| |
53 (!primary_proxy.empty() && !fallback_proxy.empty() && | |
54 !secure_proxy_check_url.empty())); | |
mmenke
2015/04/24 19:27:23
You're using 3 space indent here for both of the a
bengr
2015/04/24 21:13:50
Done.
| |
55 if (primary_proxy.empty()) | |
56 return; | |
57 command_line->AppendSwitchASCII( | |
58 data_reduction_proxy::switches::kDataReductionProxy, primary_proxy); | |
59 command_line->AppendSwitchASCII( | |
60 data_reduction_proxy::switches::kDataReductionProxyFallback, | |
61 fallback_proxy); | |
62 command_line->AppendSwitchASCII( | |
63 data_reduction_proxy::switches::kDataReductionProxySecureProxyCheckURL, | |
64 secure_proxy_check_url); | |
65 } | |
66 } // namespace | |
mmenke
2015/04/24 19:10:27
line break before end of namespace.
bengr
2015/04/24 21:13:50
Done.
| |
67 | |
68 CronetDataReductionProxy::CronetDataReductionProxy( | |
69 const std::string& key, | |
70 const std::string& primary_proxy, | |
71 const std::string& fallback_proxy, | |
72 const std::string& secure_proxy_check_url, | |
73 const std::string& user_agent, | |
74 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
75 net::NetLog* net_log) | |
76 : task_runner_(task_runner) { | |
77 AddOptionsToCommandLine(primary_proxy, fallback_proxy, secure_proxy_check_url, | |
78 base::CommandLine::ForCurrentProcess()); | |
mmenke
2015/04/24 19:10:27
Hrm... This isn't threadsafe. If we were creatin
bengr
2015/04/24 21:13:50
This is here only for tests. I've added a TODO to
| |
79 prefs_ = CreatePrefService(); | |
80 settings_.reset( | |
81 new data_reduction_proxy::DataReductionProxySettings()); | |
82 io_data_.reset( | |
83 new data_reduction_proxy::DataReductionProxyIOData( | |
84 data_reduction_proxy::Client::CRONET_ANDROID, | |
85 data_reduction_proxy::DataReductionProxyParams::kAllowed | | |
86 data_reduction_proxy::DataReductionProxyParams::kFallbackAllowed, | |
87 net_log, task_runner, task_runner, false, user_agent)); | |
88 io_data_->request_options()->SetKeyOnIO(key); | |
89 io_data_->InitOnUIThread(prefs_.get()); | |
90 } | |
91 | |
92 CronetDataReductionProxy::~CronetDataReductionProxy() { | |
93 io_data_->ShutdownOnUIThread(); | |
94 } | |
95 | |
96 scoped_ptr<net::NetworkDelegate> | |
97 CronetDataReductionProxy::CreateNetworkDelegate( | |
98 scoped_ptr<net::NetworkDelegate> wrapped_network_delegate) { | |
99 return io_data_->CreateNetworkDelegate(wrapped_network_delegate.Pass(), | |
100 false /* No bypass UMA */ ); | |
101 } | |
102 | |
103 scoped_ptr<net::URLRequestInterceptor> | |
104 CronetDataReductionProxy::CreateInterceptor() { | |
105 return io_data_->CreateInterceptor(); | |
106 } | |
107 | |
108 void CronetDataReductionProxy::Init(bool enable, | |
109 net::URLRequestContext* context) { | |
110 url_request_context_getter_ = | |
111 new net::TrivialURLRequestContextGetter( | |
112 context, task_runner_); | |
113 scoped_ptr<data_reduction_proxy::DataReductionProxyCompressionStats> | |
114 compression_stats( | |
115 new data_reduction_proxy::DataReductionProxyCompressionStats( | |
116 prefs_.get(), task_runner_, base::TimeDelta())); | |
117 scoped_ptr<data_reduction_proxy::DataReductionProxyService> | |
118 data_reduction_proxy_service( | |
119 new data_reduction_proxy::DataReductionProxyService( | |
120 compression_stats.Pass(), settings_.get(), | |
121 url_request_context_getter_.get(), task_runner_)); | |
122 io_data_->SetDataReductionProxyService( | |
123 data_reduction_proxy_service->GetWeakPtr()); | |
124 settings_->InitDataReductionProxySettings( | |
125 prefs_.get(), io_data_.get(), data_reduction_proxy_service.Pass()); | |
126 settings_->SetDataReductionProxyEnabled(enable); | |
127 settings_->MaybeActivateDataReductionProxy(true); | |
128 } | |
129 | |
130 } // namespace cronet | |
OLD | NEW |