Chromium Code Reviews| 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()) { | |
| 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 server(quic_hint.server); | |
| 156 if (!server.is_valid() || | |
| 157 quic_hint.alternate_port < std::numeric_limits<uint16>::min() || | |
| 158 quic_hint.alternate_port > std::numeric_limits<uint16>::max()) { | |
| 159 LOG(ERROR) << "Invalid QUIC hint: " << quic_hint.server; | |
| 160 continue; | |
| 161 } | |
| 162 | |
| 163 context_->http_server_properties()->SetAlternateProtocol( | |
| 164 net::HostPortPair::FromURL(server), | |
| 165 static_cast<uint16>(quic_hint.alternate_port), | |
| 166 net::AlternateProtocol::QUIC, | |
| 167 0.5f); | |
| 168 } | |
| 169 } | |
| 170 } | |
| 171 | |
| 147 if (VLOG_IS_ON(2)) { | 172 if (VLOG_IS_ON(2)) { |
| 148 net_log_observer_.reset(new NetLogObserver()); | 173 net_log_observer_.reset(new NetLogObserver()); |
| 149 context_->net_log()->AddThreadSafeObserver(net_log_observer_.get(), | 174 context_->net_log()->AddThreadSafeObserver(net_log_observer_.get(), |
| 150 net::NetLog::LOG_ALL_BUT_BYTES); | 175 net::NetLog::LOG_ALL_BUT_BYTES); |
| 151 } | 176 } |
| 152 | 177 |
| 153 delegate_->OnContextInitialized(this); | 178 delegate_->OnContextInitialized(this); |
| 154 } | 179 } |
| 155 | 180 |
| 156 URLRequestContextAdapter::~URLRequestContextAdapter() { | 181 URLRequestContextAdapter::~URLRequestContextAdapter() { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 net_log_logger_->StartObserving(context_->net_log()); | 219 net_log_logger_->StartObserving(context_->net_log()); |
| 195 } | 220 } |
| 196 | 221 |
| 197 void URLRequestContextAdapter::StopNetLog() { | 222 void URLRequestContextAdapter::StopNetLog() { |
| 198 if (net_log_logger_) { | 223 if (net_log_logger_) { |
| 199 net_log_logger_->StopObserving(); | 224 net_log_logger_->StopObserving(); |
| 200 net_log_logger_.reset(); | 225 net_log_logger_.reset(); |
| 201 } | 226 } |
| 202 } | 227 } |
| 203 | 228 |
| 229 void URLRequestContextAdapter::SetQuicHint(const net::HostPortPair& server, | |
|
mmenke
2014/09/09 14:53:35
Do we really need multiple ways of setting per-ser
mef
2014/09/10 16:48:18
Probably not, I'll be happy to remove it.
| |
| 230 uint16 alternate_port, | |
| 231 double probability) { | |
| 232 GetNetworkTaskRunner()->PostTask( | |
| 233 FROM_HERE, | |
| 234 base::Bind(&net::HttpServerProperties::SetAlternateProtocol, | |
| 235 context_->http_server_properties(), | |
| 236 server, | |
| 237 alternate_port, | |
| 238 net::AlternateProtocol::QUIC, | |
| 239 probability)); | |
| 240 } | |
| 241 | |
| 204 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { | 242 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { |
| 205 VLOG(2) << "Net log entry: type=" << entry.type() | 243 VLOG(2) << "Net log entry: type=" << entry.type() |
| 206 << ", source=" << entry.source().type << ", phase=" << entry.phase(); | 244 << ", source=" << entry.source().type << ", phase=" << entry.phase(); |
| 207 } | 245 } |
| 208 | 246 |
| 209 } // namespace cronet | 247 } // namespace cronet |
| OLD | NEW |