Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ios/cronet_environment.h" | 5 #include "components/cronet/ios/cronet_environment.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 #include "net/http/http_util.h" | 46 #include "net/http/http_util.h" |
| 47 #include "net/log/net_log.h" | 47 #include "net/log/net_log.h" |
| 48 #include "net/log/net_log_capture_mode.h" | 48 #include "net/log/net_log_capture_mode.h" |
| 49 #include "net/log/write_to_file_net_log_observer.h" | 49 #include "net/log/write_to_file_net_log_observer.h" |
| 50 #include "net/proxy/proxy_service.h" | 50 #include "net/proxy/proxy_service.h" |
| 51 #include "net/socket/ssl_client_socket.h" | 51 #include "net/socket/ssl_client_socket.h" |
| 52 #include "net/ssl/channel_id_service.h" | 52 #include "net/ssl/channel_id_service.h" |
| 53 #include "net/ssl/default_channel_id_store.h" | 53 #include "net/ssl/default_channel_id_store.h" |
| 54 #include "net/ssl/ssl_config_service_defaults.h" | 54 #include "net/ssl/ssl_config_service_defaults.h" |
| 55 #include "net/url_request/static_http_user_agent_settings.h" | 55 #include "net/url_request/static_http_user_agent_settings.h" |
| 56 #include "net/url_request/url_request_context.h" | |
| 57 #include "net/url_request/url_request_context_builder.h" | |
| 56 #include "net/url_request/url_request_context_storage.h" | 58 #include "net/url_request/url_request_context_storage.h" |
| 57 #include "net/url_request/url_request_job_factory_impl.h" | 59 #include "net/url_request/url_request_job_factory_impl.h" |
| 58 #include "url/scheme_host_port.h" | 60 #include "url/scheme_host_port.h" |
| 59 #include "url/url_util.h" | 61 #include "url/url_util.h" |
| 60 | 62 |
| 61 namespace { | 63 namespace { |
| 62 | 64 |
| 63 base::AtExitManager* g_at_exit_ = nullptr; | 65 base::AtExitManager* g_at_exit_ = nullptr; |
| 64 net::NetworkChangeNotifier* g_network_change_notifier = nullptr; | 66 net::NetworkChangeNotifier* g_network_change_notifier = nullptr; |
| 65 // MessageLoop on the main thread. | 67 // MessageLoop on the main thread. |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 base::Unretained(this))); | 268 base::Unretained(this))); |
| 267 } | 269 } |
| 268 | 270 |
| 269 CronetEnvironment::~CronetEnvironment() { | 271 CronetEnvironment::~CronetEnvironment() { |
| 270 // net::HTTPProtocolHandlerDelegate::SetInstance(nullptr); | 272 // net::HTTPProtocolHandlerDelegate::SetInstance(nullptr); |
| 271 } | 273 } |
| 272 | 274 |
| 273 void CronetEnvironment::InitializeOnNetworkThread() { | 275 void CronetEnvironment::InitializeOnNetworkThread() { |
| 274 DCHECK(network_io_thread_->task_runner()->BelongsToCurrentThread()); | 276 DCHECK(network_io_thread_->task_runner()->BelongsToCurrentThread()); |
| 275 base::FeatureList::InitializeInstance(std::string(), std::string()); | 277 base::FeatureList::InitializeInstance(std::string(), std::string()); |
| 276 // TODO(mef): Use net:UrlRequestContextBuilder instead of manual build. | |
| 277 main_context_.reset(new net::URLRequestContext); | |
| 278 main_context_->set_net_log(net_log_.get()); | |
| 279 | 278 |
| 280 if (user_agent_partial_) | 279 if (user_agent_partial_) |
| 281 user_agent_ = web::BuildUserAgentFromProduct(user_agent_); | 280 user_agent_ = web::BuildUserAgentFromProduct(user_agent_); |
| 282 | 281 |
| 283 main_context_->set_http_user_agent_settings( | |
| 284 new net::StaticHttpUserAgentSettings(accept_language_, user_agent_)); | |
| 285 | |
| 286 main_context_->set_ssl_config_service(new net::SSLConfigServiceDefaults); | |
| 287 main_context_->set_transport_security_state( | |
| 288 new net::TransportSecurityState()); | |
| 289 http_server_properties_.reset(new net::HttpServerPropertiesImpl()); | |
| 290 main_context_->set_http_server_properties(http_server_properties_.get()); | |
| 291 | |
| 292 // TODO(rdsmith): Note that the ".release()" calls below are leaking | |
| 293 // the objects in question; this should be fixed by having an object | |
| 294 // corresponding to URLRequestContextStorage that actually owns those | |
| 295 // objects. See http://crbug.com/523858. | |
| 296 std::unique_ptr<net::MappedHostResolver> mapped_host_resolver( | |
| 297 new net::MappedHostResolver( | |
| 298 net::HostResolver::CreateDefaultResolver(nullptr))); | |
| 299 | |
| 300 mapped_host_resolver->SetRulesFromString(host_resolver_rules_); | |
| 301 main_context_->set_host_resolver(mapped_host_resolver.release()); | |
| 302 | |
| 303 if (!cert_verifier_) | 282 if (!cert_verifier_) |
| 304 cert_verifier_ = net::CertVerifier::CreateDefault(); | 283 cert_verifier_ = net::CertVerifier::CreateDefault(); |
|
mmenke
2016/11/16 16:41:20
Not needed: URLRequestContextConfig will do this
lilyhoughton
2016/11/22 19:44:01
Done.
| |
| 305 main_context_->set_cert_verifier(cert_verifier_.get()); | |
| 306 | |
| 307 std::unique_ptr<net::MultiLogCTVerifier> ct_verifier = | |
| 308 base::MakeUnique<net::MultiLogCTVerifier>(); | |
| 309 ct_verifier->AddLogs(net::ct::CreateLogVerifiersForKnownLogs()); | |
| 310 main_context_->set_cert_transparency_verifier(ct_verifier.release()); | |
| 311 main_context_->set_ct_policy_enforcer(new net::CTPolicyEnforcer()); | |
| 312 | |
| 313 main_context_->set_http_auth_handler_factory( | |
| 314 net::HttpAuthHandlerRegistryFactory::CreateDefault( | |
| 315 main_context_->host_resolver()) | |
| 316 .release()); | |
| 317 main_context_->set_proxy_service( | |
| 318 net::ProxyService::CreateUsingSystemProxyResolver( | |
| 319 std::move(proxy_config_service_), 0, nullptr) | |
| 320 .release()); | |
| 321 | 284 |
| 322 // Cache | 285 // Cache |
| 323 base::FilePath cache_path; | 286 base::FilePath cache_path; |
| 324 if (!PathService::Get(base::DIR_CACHE, &cache_path)) | 287 if (!PathService::Get(base::DIR_CACHE, &cache_path)) |
| 325 return; | 288 return; |
| 326 cache_path = cache_path.Append(FILE_PATH_LITERAL("cronet")); | 289 cache_path = cache_path.Append(FILE_PATH_LITERAL("cronet")); |
| 327 std::unique_ptr<net::HttpCache::DefaultBackend> main_backend( | |
| 328 new net::HttpCache::DefaultBackend(net::DISK_CACHE, | |
| 329 net::CACHE_BACKEND_SIMPLE, cache_path, | |
| 330 0, // Default cache size. | |
| 331 network_cache_thread_->task_runner())); | |
| 332 | 290 |
| 333 net::HttpNetworkSession::Params params; | 291 std::unique_ptr<URLRequestContextConfig> config(new URLRequestContextConfig( |
|
mmenke
2016/11/16 16:41:20
include components/cronet/url_request_context_conf
lilyhoughton
2016/11/22 19:44:01
This was in cronet_environment.h. That file didn'
| |
| 292 quic_enabled_, "", http2_enabled_, false, URLRequestContextConfig::DISK, | |
| 293 0, false, cache_path.value(), user_agent_, "{}", "", "", "", "", | |
| 294 std::move(cert_verifier_), false, true, "")); | |
|
mmenke
2016/11/16 16:41:20
Should have comments labeling all the inscrutable
lilyhoughton
2016/11/22 19:44:01
Done.
| |
| 334 | 295 |
| 335 params.host_resolver = main_context_->host_resolver(); | 296 net::URLRequestContextBuilder context_builder; |
| 336 params.cert_verifier = main_context_->cert_verifier(); | |
| 337 params.cert_transparency_verifier = | |
| 338 main_context_->cert_transparency_verifier(); | |
| 339 params.ct_policy_enforcer = main_context_->ct_policy_enforcer(); | |
| 340 params.channel_id_service = main_context_->channel_id_service(); | |
| 341 params.transport_security_state = main_context_->transport_security_state(); | |
| 342 params.proxy_service = main_context_->proxy_service(); | |
| 343 params.ssl_config_service = main_context_->ssl_config_service(); | |
| 344 params.http_auth_handler_factory = main_context_->http_auth_handler_factory(); | |
| 345 params.http_server_properties = main_context_->http_server_properties(); | |
| 346 params.net_log = main_context_->net_log(); | |
| 347 params.enable_http2 = http2_enabled(); | |
| 348 params.enable_quic = quic_enabled(); | |
| 349 | 297 |
| 298 context_builder.set_accept_language(accept_language_); | |
| 299 | |
| 300 config->ConfigureURLRequestContextBuilder(&context_builder, net_log_.get(), | |
| 301 file_thread_.get()->task_runner()); | |
| 302 | |
| 303 std::unique_ptr<net::MappedHostResolver> mapped_host_resolver( | |
| 304 new net::MappedHostResolver( | |
| 305 net::HostResolver::CreateDefaultResolver(nullptr))); | |
|
mmenke
2016/11/16 16:41:20
nullptr -> net_log_.get() (That was a bug in the o
lilyhoughton
2016/11/22 19:44:01
Done.
What's the bug / would it be nontrivial to
mmenke
2016/11/22 19:50:42
It means we wouldn't have been emitting DNS lookup
| |
| 306 | |
| 307 mapped_host_resolver->SetRulesFromString(host_resolver_rules_); | |
| 308 context_builder.set_host_resolver(std::move(mapped_host_resolver)); | |
| 309 | |
| 310 std::unordered_set<std::string> quic_host_whitelist; | |
| 311 std::unique_ptr<net::HttpServerProperties> http_server_properties( | |
| 312 new net::HttpServerPropertiesImpl()); | |
| 350 for (const auto& quic_hint : quic_hints_) { | 313 for (const auto& quic_hint : quic_hints_) { |
| 351 net::AlternativeService alternative_service(net::AlternateProtocol::QUIC, | 314 net::AlternativeService alternative_service(net::AlternateProtocol::QUIC, |
| 352 "", quic_hint.port()); | 315 "", quic_hint.port()); |
| 353 url::SchemeHostPort quic_hint_server("https", quic_hint.host(), | 316 url::SchemeHostPort quic_hint_server("https", quic_hint.host(), |
| 354 quic_hint.port()); | 317 quic_hint.port()); |
| 355 main_context_->http_server_properties()->SetAlternativeService( | 318 http_server_properties->SetAlternativeService( |
| 356 quic_hint_server, alternative_service, base::Time::Max()); | 319 quic_hint_server, alternative_service, base::Time::Max()); |
| 357 params.quic_host_whitelist.insert(quic_hint.host()); | 320 quic_host_whitelist.insert(quic_hint.host()); |
| 358 } | 321 } |
| 359 | 322 |
| 360 if (!params.channel_id_service) { | 323 context_builder.SetHttpServerProperties(std::move(http_server_properties)); |
| 361 // The main context may not have a ChannelIDService, since it is lazily | 324 context_builder.set_quic_host_whitelist(quic_host_whitelist); |
| 362 // constructed. If not, build an ephemeral ChannelIDService with no backing | |
| 363 // disk store. | |
| 364 // TODO(ellyjones): support persisting ChannelID. | |
| 365 params.channel_id_service = | |
| 366 new net::ChannelIDService(new net::DefaultChannelIDStore(NULL), | |
| 367 base::WorkerPool::GetTaskRunner(true)); | |
| 368 } | |
| 369 | 325 |
| 370 // TODO(mmenke): These really shouldn't be leaked. | 326 main_context_ = context_builder.Build(); |
| 371 // See https://crbug.com/523858. | |
| 372 net::HttpNetworkSession* http_network_session = | |
| 373 new net::HttpNetworkSession(params); | |
| 374 net::HttpCache* main_cache = | |
| 375 new net::HttpCache(http_network_session, std::move(main_backend), | |
| 376 true /* set_up_quic_server_info */); | |
| 377 main_context_->set_http_transaction_factory(main_cache); | |
| 378 | |
| 379 net::URLRequestJobFactoryImpl* job_factory = | |
| 380 new net::URLRequestJobFactoryImpl; | |
| 381 main_context_->set_job_factory(job_factory); | |
| 382 main_context_->set_net_log(net_log_.get()); | |
| 383 } | 327 } |
| 384 | 328 |
| 385 std::string CronetEnvironment::user_agent() { | 329 std::string CronetEnvironment::user_agent() { |
| 386 const net::HttpUserAgentSettings* user_agent_settings = | 330 const net::HttpUserAgentSettings* user_agent_settings = |
| 387 main_context_->http_user_agent_settings(); | 331 main_context_->http_user_agent_settings(); |
| 388 if (!user_agent_settings) { | 332 if (!user_agent_settings) { |
| 389 return nullptr; | 333 return nullptr; |
| 390 } | 334 } |
| 391 | 335 |
| 392 return user_agent_settings->GetUserAgent(); | 336 return user_agent_settings->GetUserAgent(); |
| 393 } | 337 } |
| 394 | 338 |
| 395 std::vector<uint8_t> CronetEnvironment::GetHistogramDeltas() { | 339 std::vector<uint8_t> CronetEnvironment::GetHistogramDeltas() { |
| 396 base::StatisticsRecorder::Initialize(); | 340 base::StatisticsRecorder::Initialize(); |
| 397 std::vector<uint8_t> data; | 341 std::vector<uint8_t> data; |
| 398 if (!HistogramManager::GetInstance()->GetDeltas(&data)) | 342 if (!HistogramManager::GetInstance()->GetDeltas(&data)) |
| 399 return std::vector<uint8_t>(); | 343 return std::vector<uint8_t>(); |
| 400 return data; | 344 return data; |
| 401 } | 345 } |
| 402 | 346 |
| 403 } // namespace cronet | 347 } // namespace cronet |
| OLD | NEW |