OLD | NEW |
---|---|
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/file_util.h" | 8 #include "base/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_impl.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_fixed.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 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 scoped_ptr<URLRequestContextConfig> config) { | 137 scoped_ptr<URLRequestContextConfig> config) { |
138 // TODO(mmenke): Add method to have the builder enable SPDY. | 138 // TODO(mmenke): Add method to have the builder enable SPDY. |
139 net::URLRequestContextBuilder context_builder; | 139 net::URLRequestContextBuilder context_builder; |
140 context_builder.set_network_delegate(new BasicNetworkDelegate()); | 140 context_builder.set_network_delegate(new BasicNetworkDelegate()); |
141 context_builder.set_proxy_config_service( | 141 context_builder.set_proxy_config_service( |
142 new net::ProxyConfigServiceFixed(net::ProxyConfig())); | 142 new net::ProxyConfigServiceFixed(net::ProxyConfig())); |
143 config->ConfigureURLRequestContextBuilder(&context_builder); | 143 config->ConfigureURLRequestContextBuilder(&context_builder); |
144 | 144 |
145 context_.reset(context_builder.Build()); | 145 context_.reset(context_builder.Build()); |
146 | 146 |
147 // Currently (circa M39) enabling QUIC requires setting probability threshold. | |
148 if (config->enable_quic) { | |
149 context_->http_server_properties() | |
150 ->SetAlternateProtocolProbabilityThreshold(1.0f); | |
151 if (!config->quic_hints.empty()) { | |
Ryan Hamilton
2014/09/10 20:58:19
I'm not sure that this guard saves you anything...
mef
2014/09/12 19:44:33
Done.
| |
152 for (size_t hint = 0; hint < config->quic_hints.size(); ++hint) { | |
153 const URLRequestContextConfig::QuicHint& quic_hint = | |
154 *config->quic_hints[hint]; | |
155 GURL quic_hint_server(quic_hint.server); | |
156 net::HostPortPair quic_hint_host(quic_hint_server.HostNoBrackets(), | |
157 quic_hint_server.EffectiveIntPort()); | |
Ryan Hamilton
2014/09/10 20:58:19
If you change the types of the QuicHint members, I
mef
2014/09/12 19:44:33
As Matt has mention this is de-serialized from JSO
| |
158 if (!quic_hint_server.is_valid() || | |
159 quic_hint.alternate_port <= std::numeric_limits<uint16>::min() || | |
160 quic_hint.alternate_port > std::numeric_limits<uint16>::max() || | |
161 quic_hint_host.IsEmpty()) { | |
162 LOG(ERROR) << "Invalid QUIC hint: " << quic_hint.server; | |
163 continue; | |
164 } | |
Ryan Hamilton
2014/09/10 20:58:19
Does SetAlternateProtocol perform similar checks?
mef
2014/09/12 19:44:33
Umm, SetAlternateProtocol just uses host_port_pair
| |
165 | |
166 context_->http_server_properties()->SetAlternateProtocol( | |
167 quic_hint_host, | |
168 static_cast<uint16>(quic_hint.alternate_port), | |
169 net::AlternateProtocol::QUIC, | |
170 1.0f); | |
171 } | |
172 } | |
173 } | |
174 | |
147 if (VLOG_IS_ON(2)) { | 175 if (VLOG_IS_ON(2)) { |
148 net_log_observer_.reset(new NetLogObserver()); | 176 net_log_observer_.reset(new NetLogObserver()); |
149 context_->net_log()->AddThreadSafeObserver(net_log_observer_.get(), | 177 context_->net_log()->AddThreadSafeObserver(net_log_observer_.get(), |
150 net::NetLog::LOG_ALL_BUT_BYTES); | 178 net::NetLog::LOG_ALL_BUT_BYTES); |
151 } | 179 } |
152 | 180 |
153 delegate_->OnContextInitialized(this); | 181 delegate_->OnContextInitialized(this); |
154 } | 182 } |
155 | 183 |
156 URLRequestContextAdapter::~URLRequestContextAdapter() { | 184 URLRequestContextAdapter::~URLRequestContextAdapter() { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 net_log_logger_->StartObserving(context_->net_log()); | 222 net_log_logger_->StartObserving(context_->net_log()); |
195 } | 223 } |
196 | 224 |
197 void URLRequestContextAdapter::StopNetLog() { | 225 void URLRequestContextAdapter::StopNetLog() { |
198 if (net_log_logger_) { | 226 if (net_log_logger_) { |
199 net_log_logger_->StopObserving(); | 227 net_log_logger_->StopObserving(); |
200 net_log_logger_.reset(); | 228 net_log_logger_.reset(); |
201 } | 229 } |
202 } | 230 } |
203 | 231 |
232 void URLRequestContextAdapter::SetQuicHint(const net::HostPortPair& server, | |
233 uint16 alternate_port, | |
234 double probability) { | |
235 GetNetworkTaskRunner()->PostTask( | |
236 FROM_HERE, | |
237 base::Bind(&net::HttpServerProperties::SetAlternateProtocol, | |
238 context_->http_server_properties(), | |
239 server, | |
240 alternate_port, | |
241 net::AlternateProtocol::QUIC, | |
242 probability)); | |
243 } | |
244 | |
204 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { | 245 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { |
205 VLOG(2) << "Net log entry: type=" << entry.type() | 246 VLOG(2) << "Net log entry: type=" << entry.type() |
206 << ", source=" << entry.source().type << ", phase=" << entry.phase(); | 247 << ", source=" << entry.source().type << ", phase=" << entry.phase(); |
207 } | 248 } |
208 | 249 |
209 } // namespace cronet | 250 } // namespace cronet |
OLD | NEW |