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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 void URLRequestContextAdapter::InitializeURLRequestContext( | 136 void URLRequestContextAdapter::InitializeURLRequestContext( |
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 DCHECK(!config->enable_quic || !config->quic_hints.empty()); |
| 147 |
| 148 // Currently (circa M39) enabling QUIC requires setting probability threshold. |
| 149 if (config->enable_quic) { |
| 150 context_->http_server_properties() |
| 151 ->SetAlternateProtocolProbabilityThreshold(1.0f); |
| 152 if (!config->quic_hints.empty()) { |
| 153 for (size_t hint = 0; hint < config->quic_hints.size(); ++hint) { |
| 154 const URLRequestContextConfig::QuicHint& quic_hint = |
| 155 *config->quic_hints[hint]; |
| 156 GURL server(quic_hint.server); |
| 157 if (!server.is_valid() || |
| 158 quic_hint.alternate_port < std::numeric_limits<uint16>::min() || |
| 159 quic_hint.alternate_port > std::numeric_limits<uint16>::max()) { |
| 160 LOG(ERROR) << "Invalid QUIC hint: " << quic_hint.server; |
| 161 DCHECK(0); |
| 162 continue; |
| 163 } |
| 164 |
| 165 net::HostPortPair quic_hint_host(server.HostNoBrackets(), |
| 166 server.EffectiveIntPort()); |
| 167 DCHECK(!quic_hint_host.IsEmpty()); |
| 168 context_->http_server_properties()->SetAlternateProtocol( |
| 169 quic_hint_host, |
| 170 static_cast<uint16>(quic_hint.alternate_port), |
| 171 net::AlternateProtocol::QUIC, |
| 172 1.0f); |
| 173 DCHECK(context_->http_server_properties()->HasAlternateProtocol( |
| 174 quic_hint_host)); |
| 175 } |
| 176 } |
| 177 } |
146 | 178 |
147 if (VLOG_IS_ON(2)) { | 179 if (VLOG_IS_ON(2)) { |
148 net_log_observer_.reset(new NetLogObserver()); | 180 net_log_observer_.reset(new NetLogObserver()); |
149 context_->net_log()->AddThreadSafeObserver(net_log_observer_.get(), | 181 context_->net_log()->AddThreadSafeObserver(net_log_observer_.get(), |
150 net::NetLog::LOG_ALL_BUT_BYTES); | 182 net::NetLog::LOG_ALL_BUT_BYTES); |
151 } | 183 } |
152 | 184 |
153 delegate_->OnContextInitialized(this); | 185 delegate_->OnContextInitialized(this); |
154 } | 186 } |
155 | 187 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 net_log_logger_->StartObserving(context_->net_log()); | 226 net_log_logger_->StartObserving(context_->net_log()); |
195 } | 227 } |
196 | 228 |
197 void URLRequestContextAdapter::StopNetLog() { | 229 void URLRequestContextAdapter::StopNetLog() { |
198 if (net_log_logger_) { | 230 if (net_log_logger_) { |
199 net_log_logger_->StopObserving(); | 231 net_log_logger_->StopObserving(); |
200 net_log_logger_.reset(); | 232 net_log_logger_.reset(); |
201 } | 233 } |
202 } | 234 } |
203 | 235 |
| 236 void URLRequestContextAdapter::SetQuicHint(const net::HostPortPair& server, |
| 237 uint16 alternate_port, |
| 238 double probability) { |
| 239 GetNetworkTaskRunner()->PostTask( |
| 240 FROM_HERE, |
| 241 base::Bind(&net::HttpServerProperties::SetAlternateProtocol, |
| 242 context_->http_server_properties(), |
| 243 server, |
| 244 alternate_port, |
| 245 net::AlternateProtocol::QUIC, |
| 246 probability)); |
| 247 } |
| 248 |
204 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { | 249 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { |
205 VLOG(2) << "Net log entry: type=" << entry.type() | 250 VLOG(2) << "Net log entry: type=" << entry.type() |
206 << ", source=" << entry.source().type << ", phase=" << entry.phase(); | 251 << ", source=" << entry.source().type << ", phase=" << entry.phase(); |
207 } | 252 } |
208 | 253 |
209 } // namespace cronet | 254 } // namespace cronet |
OLD | NEW |