Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(645)

Side by Side Diff: components/cronet/android/url_request_context_adapter.cc

Issue 624443003: Setup ProxyConfigServiceAndroid in Cronet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/cronet/android/url_request_context_adapter.h" 5 #include "components/cronet/android/url_request_context_adapter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/message_loop/message_loop.h"
9 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
10 #include "components/cronet/url_request_context_config.h" 11 #include "components/cronet/url_request_context_config.h"
11 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
12 #include "net/base/net_log_logger.h" 13 #include "net/base/net_log_logger.h"
13 #include "net/cert/cert_verifier.h" 14 #include "net/cert/cert_verifier.h"
14 #include "net/http/http_auth_handler_factory.h" 15 #include "net/http/http_auth_handler_factory.h"
15 #include "net/http/http_network_layer.h" 16 #include "net/http/http_network_layer.h"
16 #include "net/http/http_server_properties.h" 17 #include "net/http/http_server_properties.h"
17 #include "net/proxy/proxy_config_service_fixed.h" 18 #include "net/proxy/proxy_config_service.h"
18 #include "net/proxy/proxy_service.h" 19 #include "net/proxy/proxy_service.h"
19 #include "net/ssl/ssl_config_service_defaults.h" 20 #include "net/ssl/ssl_config_service_defaults.h"
20 #include "net/url_request/static_http_user_agent_settings.h" 21 #include "net/url_request/static_http_user_agent_settings.h"
21 #include "net/url_request/url_request_context_builder.h" 22 #include "net/url_request/url_request_context_builder.h"
22 #include "net/url_request/url_request_context_storage.h" 23 #include "net/url_request/url_request_context_storage.h"
23 #include "net/url_request/url_request_job_factory_impl.h" 24 #include "net/url_request/url_request_job_factory_impl.h"
24 25
25 namespace { 26 namespace {
26 27
27 class BasicNetworkDelegate : public net::NetworkDelegate { 28 class BasicNetworkDelegate : public net::NetworkDelegate {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 102
102 virtual int OnBeforeSocketStreamConnect( 103 virtual int OnBeforeSocketStreamConnect(
103 net::SocketStream* stream, 104 net::SocketStream* stream,
104 const net::CompletionCallback& callback) override { 105 const net::CompletionCallback& callback) override {
105 return net::OK; 106 return net::OK;
106 } 107 }
107 108
108 DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate); 109 DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate);
109 }; 110 };
110 111
112 // Android specific UI MessageLoop.
113 base::MessageLoop* g_main_message_loop = nullptr;
114
111 } // namespace 115 } // namespace
112 116
113 namespace cronet { 117 namespace cronet {
114 118
115 URLRequestContextAdapter::URLRequestContextAdapter( 119 URLRequestContextAdapter::URLRequestContextAdapter(
116 URLRequestContextAdapterDelegate* delegate, 120 URLRequestContextAdapterDelegate* delegate,
117 std::string user_agent) { 121 std::string user_agent) {
118 delegate_ = delegate; 122 delegate_ = delegate;
119 user_agent_ = user_agent; 123 user_agent_ = user_agent;
120 } 124 }
121 125
122 void URLRequestContextAdapter::Initialize( 126 void URLRequestContextAdapter::Initialize(
123 scoped_ptr<URLRequestContextConfig> config) { 127 scoped_ptr<URLRequestContextConfig> config) {
124 network_thread_ = new base::Thread("network"); 128 network_thread_ = new base::Thread("network");
125 base::Thread::Options options; 129 base::Thread::Options options;
126 options.message_loop_type = base::MessageLoop::TYPE_IO; 130 options.message_loop_type = base::MessageLoop::TYPE_IO;
127 network_thread_->StartWithOptions(options); 131 network_thread_->StartWithOptions(options);
132 config_ = config.Pass();
133 }
128 134
135 void URLRequestContextAdapter::InitRequestContextOnUIThread() {
136 if (!base::MessageLoop::current()) {
137 DCHECK(!g_main_message_loop);
138 g_main_message_loop = new base::MessageLoopForUI;
139 base::MessageLoopForUI::current()->Start();
140 }
141
142 net::ProxyConfigService* service =
143 net::ProxyService::CreateSystemProxyConfigService(GetNetworkTaskRunner(),
144 NULL);
145 proxy_config_service_.reset(service);
129 GetNetworkTaskRunner()->PostTask( 146 GetNetworkTaskRunner()->PostTask(
130 FROM_HERE, 147 FROM_HERE,
131 base::Bind(&URLRequestContextAdapter::InitializeURLRequestContext, 148 base::Bind(&URLRequestContextAdapter::InitializeURLRequestContext,
mef 2014/10/10 21:20:37 I'd rename this InitRequestContextOnNetworkThread
xunjieli 2014/10/14 19:14:48 Done. Good idea! Thanks!
132 this, 149 this,
133 Passed(&config))); 150 Passed(&config_)));
134 } 151 }
135 152
136 void URLRequestContextAdapter::InitializeURLRequestContext( 153 void URLRequestContextAdapter::InitializeURLRequestContext(
137 scoped_ptr<URLRequestContextConfig> config) { 154 scoped_ptr<URLRequestContextConfig> config) {
138 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); 155 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
139 // TODO(mmenke): Add method to have the builder enable SPDY. 156 // TODO(mmenke): Add method to have the builder enable SPDY.
140 net::URLRequestContextBuilder context_builder; 157 net::URLRequestContextBuilder context_builder;
141 context_builder.set_network_delegate(new BasicNetworkDelegate()); 158 context_builder.set_network_delegate(new BasicNetworkDelegate());
142 context_builder.set_proxy_config_service( 159 context_builder.set_proxy_config_service(proxy_config_service_.get());
143 new net::ProxyConfigServiceFixed(net::ProxyConfig()));
144 config->ConfigureURLRequestContextBuilder(&context_builder); 160 config->ConfigureURLRequestContextBuilder(&context_builder);
145 161
146 context_.reset(context_builder.Build()); 162 context_.reset(context_builder.Build());
147 163
148 // Currently (circa M39) enabling QUIC requires setting probability threshold. 164 // Currently (circa M39) enabling QUIC requires setting probability threshold.
149 if (config->enable_quic) { 165 if (config->enable_quic) {
150 context_->http_server_properties() 166 context_->http_server_properties()
151 ->SetAlternateProtocolProbabilityThreshold(0.0f); 167 ->SetAlternateProtocolProbabilityThreshold(0.0f);
152 for (size_t hint = 0; hint < config->quic_hints.size(); ++hint) { 168 for (size_t hint = 0; hint < config->quic_hints.size(); ++hint) {
153 const URLRequestContextConfig::QuicHint& quic_hint = 169 const URLRequestContextConfig::QuicHint& quic_hint =
(...skipping 19 matching lines...) Expand all
173 189
174 net::HostPortPair quic_hint_host_port_pair(quic_hint.host, 190 net::HostPortPair quic_hint_host_port_pair(quic_hint.host,
175 quic_hint.port); 191 quic_hint.port);
176 context_->http_server_properties()->SetAlternateProtocol( 192 context_->http_server_properties()->SetAlternateProtocol(
177 quic_hint_host_port_pair, 193 quic_hint_host_port_pair,
178 static_cast<uint16>(quic_hint.alternate_port), 194 static_cast<uint16>(quic_hint.alternate_port),
179 net::AlternateProtocol::QUIC, 195 net::AlternateProtocol::QUIC,
180 1.0f); 196 1.0f);
181 } 197 }
182 is_context_initialized_ = true; 198 is_context_initialized_ = true;
183 while (!tasks_waiting_for_context_.empty()) { 199 while (!tasks_waiting_for_context_.empty()) {
mef 2014/10/10 21:20:37 this seems to be inside of 'if (config->enable_qui
xunjieli 2014/10/14 19:14:48 Done. This is very bad. thanks for catching it!
184 tasks_waiting_for_context_.front().Run(); 200 tasks_waiting_for_context_.front().Run();
185 tasks_waiting_for_context_.pop(); 201 tasks_waiting_for_context_.pop();
186 } 202 }
187 } 203 }
188 204
189 if (VLOG_IS_ON(2)) { 205 if (VLOG_IS_ON(2)) {
190 net_log_observer_.reset(new NetLogObserver()); 206 net_log_observer_.reset(new NetLogObserver());
191 context_->net_log()->AddThreadSafeObserver(net_log_observer_.get(), 207 context_->net_log()->AddThreadSafeObserver(net_log_observer_.get(),
192 net::NetLog::LOG_ALL_BUT_BYTES); 208 net::NetLog::LOG_ALL_BUT_BYTES);
193 } 209 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 net_log_logger_.reset(); 296 net_log_logger_.reset();
281 } 297 }
282 } 298 }
283 299
284 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { 300 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) {
285 VLOG(2) << "Net log entry: type=" << entry.type() 301 VLOG(2) << "Net log entry: type=" << entry.type()
286 << ", source=" << entry.source().type << ", phase=" << entry.phase(); 302 << ", source=" << entry.source().type << ", phase=" << entry.phase();
287 } 303 }
288 304
289 } // namespace cronet 305 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698