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

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: 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/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "components/cronet/url_request_context_config.h" 10 #include "components/cronet/url_request_context_config.h"
11 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
12 #include "net/base/net_log_logger.h" 12 #include "net/base/net_log_logger.h"
13 #include "net/cert/cert_verifier.h" 13 #include "net/cert/cert_verifier.h"
14 #include "net/http/http_auth_handler_factory.h" 14 #include "net/http/http_auth_handler_factory.h"
15 #include "net/http/http_network_layer.h" 15 #include "net/http/http_network_layer.h"
16 #include "net/http/http_server_properties.h" 16 #include "net/http/http_server_properties.h"
17 #include "net/proxy/proxy_config_service_fixed.h" 17 #include "net/proxy/proxy_config_service.h"
18 #include "net/proxy/proxy_service.h" 18 #include "net/proxy/proxy_service.h"
19 #include "net/ssl/ssl_config_service_defaults.h" 19 #include "net/ssl/ssl_config_service_defaults.h"
20 #include "net/url_request/static_http_user_agent_settings.h" 20 #include "net/url_request/static_http_user_agent_settings.h"
21 #include "net/url_request/url_request_context_builder.h" 21 #include "net/url_request/url_request_context_builder.h"
22 #include "net/url_request/url_request_context_storage.h" 22 #include "net/url_request/url_request_context_storage.h"
23 #include "net/url_request/url_request_job_factory_impl.h" 23 #include "net/url_request/url_request_job_factory_impl.h"
24 24
25 namespace { 25 namespace {
26 26
27 class BasicNetworkDelegate : public net::NetworkDelegate { 27 class BasicNetworkDelegate : public net::NetworkDelegate {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 delegate_ = delegate; 118 delegate_ = delegate;
119 user_agent_ = user_agent; 119 user_agent_ = user_agent;
120 } 120 }
121 121
122 void URLRequestContextAdapter::Initialize( 122 void URLRequestContextAdapter::Initialize(
123 scoped_ptr<URLRequestContextConfig> config) { 123 scoped_ptr<URLRequestContextConfig> config) {
124 network_thread_ = new base::Thread("network"); 124 network_thread_ = new base::Thread("network");
125 base::Thread::Options options; 125 base::Thread::Options options;
126 options.message_loop_type = base::MessageLoop::TYPE_IO; 126 options.message_loop_type = base::MessageLoop::TYPE_IO;
127 network_thread_->StartWithOptions(options); 127 network_thread_->StartWithOptions(options);
128 config_ = config.Pass();
128 129
130 delegate_->InitProxyConfigService();
131 }
132
133 // Called on application's main UI thread.
134 void URLRequestContextAdapter::InitProxyConfigServiceOnUIThread() {
135 if (!base::MessageLoop::current()) {
136 main_message_loop_.reset(new base::MessageLoopForUI);
137 base::MessageLoopForUI::current()->Start();
mmenke 2014/10/02 16:17:26 I hadn't realized it was so easy to set up a base:
138 }
139 net::ProxyConfigService* service =
140 net::ProxyService::CreateSystemProxyConfigService(GetNetworkTaskRunner(),
141 NULL);
142 proxy_config_service_.reset(service);
mmenke 2014/10/02 16:17:25 Hrm...So we ensure that the Java URLRequestContext
xunjieli 2014/10/02 17:21:31 I am open to suggestions :) There is probably a be
129 GetNetworkTaskRunner()->PostTask( 143 GetNetworkTaskRunner()->PostTask(
130 FROM_HERE, 144 FROM_HERE,
131 base::Bind(&URLRequestContextAdapter::InitializeURLRequestContext, 145 base::Bind(&URLRequestContextAdapter::InitializeURLRequestContext,
132 this, 146 this,
133 Passed(&config))); 147 Passed(&config_)));
134 } 148 }
135 149
136 void URLRequestContextAdapter::InitializeURLRequestContext( 150 void URLRequestContextAdapter::InitializeURLRequestContext(
137 scoped_ptr<URLRequestContextConfig> config) { 151 scoped_ptr<URLRequestContextConfig> config) {
mmenke 2014/10/02 16:17:25 What happens if the embedder tries to use the URLR
xunjieli 2014/10/02 17:21:31 I guess they will have a context-not-setup error j
138 // TODO(mmenke): Add method to have the builder enable SPDY. 152 // TODO(mmenke): Add method to have the builder enable SPDY.
139 net::URLRequestContextBuilder context_builder; 153 net::URLRequestContextBuilder context_builder;
140 context_builder.set_network_delegate(new BasicNetworkDelegate()); 154 context_builder.set_network_delegate(new BasicNetworkDelegate());
141 context_builder.set_proxy_config_service( 155 context_builder.set_proxy_config_service(proxy_config_service_.get());
142 new net::ProxyConfigServiceFixed(net::ProxyConfig()));
143 config->ConfigureURLRequestContextBuilder(&context_builder); 156 config->ConfigureURLRequestContextBuilder(&context_builder);
144 157
145 context_.reset(context_builder.Build()); 158 context_.reset(context_builder.Build());
146 159
147 // Currently (circa M39) enabling QUIC requires setting probability threshold. 160 // Currently (circa M39) enabling QUIC requires setting probability threshold.
148 if (config->enable_quic) { 161 if (config->enable_quic) {
149 context_->http_server_properties() 162 context_->http_server_properties()
150 ->SetAlternateProtocolProbabilityThreshold(1.0f); 163 ->SetAlternateProtocolProbabilityThreshold(1.0f);
151 for (size_t hint = 0; hint < config->quic_hints.size(); ++hint) { 164 for (size_t hint = 0; hint < config->quic_hints.size(); ++hint) {
152 const URLRequestContextConfig::QuicHint& quic_hint = 165 const URLRequestContextConfig::QuicHint& quic_hint =
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 net_log_logger_.reset(); 249 net_log_logger_.reset();
237 } 250 }
238 } 251 }
239 252
240 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { 253 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) {
241 VLOG(2) << "Net log entry: type=" << entry.type() 254 VLOG(2) << "Net log entry: type=" << entry.type()
242 << ", source=" << entry.source().type << ", phase=" << entry.phase(); 255 << ", source=" << entry.source().type << ", phase=" << entry.phase();
243 } 256 }
244 257
245 } // namespace cronet 258 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698