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 10 matching lines...) Expand all Loading... | |
| 21 #include "base/metrics/statistics_recorder.h" | 21 #include "base/metrics/statistics_recorder.h" |
| 22 #include "base/path_service.h" | 22 #include "base/path_service.h" |
| 23 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
| 24 #include "base/synchronization/waitable_event.h" | 24 #include "base/synchronization/waitable_event.h" |
| 25 #include "base/threading/worker_pool.h" | 25 #include "base/threading/worker_pool.h" |
| 26 #include "components/cronet/histogram_manager.h" | 26 #include "components/cronet/histogram_manager.h" |
| 27 #include "components/cronet/ios/version.h" | 27 #include "components/cronet/ios/version.h" |
| 28 #include "components/prefs/json_pref_store.h" | 28 #include "components/prefs/json_pref_store.h" |
| 29 #include "components/prefs/pref_filter.h" | 29 #include "components/prefs/pref_filter.h" |
| 30 #include "ios/web/public/user_agent.h" | 30 #include "ios/web/public/user_agent.h" |
| 31 #include "net/base/net_errors.h" | 31 #include "net/base/net_errors.h" |
|
mmenke
2016/11/23 18:41:33
Not used?
lilyhoughton
2016/11/28 16:42:21
Done.
| |
| 32 #include "net/base/network_change_notifier.h" | 32 #include "net/base/network_change_notifier.h" |
| 33 #include "net/cert/cert_verifier.h" | 33 #include "net/cert/cert_verifier.h" |
| 34 #include "net/cert/ct_known_logs.h" | 34 #include "net/cert/ct_known_logs.h" |
| 35 #include "net/cert/ct_log_verifier.h" | 35 #include "net/cert/ct_log_verifier.h" |
| 36 #include "net/cert/ct_policy_enforcer.h" | 36 #include "net/cert/ct_policy_enforcer.h" |
| 37 #include "net/cert/ct_verifier.h" | 37 #include "net/cert/ct_verifier.h" |
| 38 #include "net/cert/multi_log_ct_verifier.h" | 38 #include "net/cert/multi_log_ct_verifier.h" |
|
mmenke
2016/11/23 18:41:33
None of the 5 lines above this are needed.
lilyhoughton
2016/11/28 16:42:21
Done.
| |
| 39 #include "net/dns/host_resolver.h" | 39 #include "net/dns/host_resolver.h" |
| 40 #include "net/dns/mapped_host_resolver.h" | 40 #include "net/dns/mapped_host_resolver.h" |
| 41 #include "net/http/http_auth_handler_factory.h" | 41 #include "net/http/http_auth_handler_factory.h" |
| 42 #include "net/http/http_cache.h" | 42 #include "net/http/http_cache.h" |
| 43 #include "net/http/http_response_headers.h" | 43 #include "net/http/http_response_headers.h" |
|
mmenke
2016/11/23 18:41:32
I don't think any of the three lines above are nee
lilyhoughton
2016/11/28 16:42:21
Removing "net/http/http_cache.h" breaks.
mmenke
2016/11/28 17:35:42
Why? It doesn't look like this class is depending
lilyhoughton
2016/11/29 16:58:54
The depended class appears to be HttpTransactionFa
| |
| 44 #include "net/http/http_server_properties_impl.h" | 44 #include "net/http/http_server_properties_impl.h" |
| 45 #include "net/http/http_stream_factory.h" | 45 #include "net/http/http_stream_factory.h" |
| 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" |
|
mmenke
2016/11/23 18:41:32
None of the 4 includes above this line are needed.
lilyhoughton
2016/11/28 16:42:21
Can you clarify? I get compile errors if I try to
mmenke
2016/11/28 17:35:42
Looks like this file still has a dependency on use
lilyhoughton
2016/11/29 16:58:54
Done.
| |
| 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 ssl_key_log_file_set = true; | 252 ssl_key_log_file_set = true; |
| 251 base::FilePath ssl_key_log_file; | 253 base::FilePath ssl_key_log_file; |
| 252 if (!PathService::Get(base::DIR_HOME, &ssl_key_log_file)) | 254 if (!PathService::Get(base::DIR_HOME, &ssl_key_log_file)) |
| 253 return; | 255 return; |
| 254 net::SSLClientSocket::SetSSLKeyLogFile( | 256 net::SSLClientSocket::SetSSLKeyLogFile( |
| 255 ssl_key_log_file.Append(ssl_key_log_file_name_), | 257 ssl_key_log_file.Append(ssl_key_log_file_name_), |
| 256 file_thread_->task_runner()); | 258 file_thread_->task_runner()); |
| 257 } | 259 } |
| 258 | 260 |
| 259 proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService( | 261 proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService( |
| 260 network_io_thread_->task_runner(), nullptr); | 262 network_io_thread_->task_runner(), nullptr); |
|
mmenke
2016/11/23 18:41:33
This is no longer needed.
lilyhoughton
2016/11/28 16:42:21
Done.
| |
| 261 main_context_getter_ = new CronetURLRequestContextGetter( | 263 main_context_getter_ = new CronetURLRequestContextGetter( |
| 262 this, network_io_thread_->task_runner()); | 264 this, network_io_thread_->task_runner()); |
| 263 base::subtle::MemoryBarrier(); | 265 base::subtle::MemoryBarrier(); |
| 264 PostToNetworkThread(FROM_HERE, | 266 PostToNetworkThread(FROM_HERE, |
| 265 base::Bind(&CronetEnvironment::InitializeOnNetworkThread, | 267 base::Bind(&CronetEnvironment::InitializeOnNetworkThread, |
| 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( | 282 // if (!cert_verifier_) |
| 284 new net::StaticHttpUserAgentSettings(accept_language_, user_agent_)); | 283 // cert_verifier_ = net::CertVerifier::CreateDefault(); |
|
mmenke
2016/11/23 18:41:32
Remove this.
lilyhoughton
2016/11/28 16:42:21
Done.
| |
| 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_) | |
| 304 cert_verifier_ = net::CertVerifier::CreateDefault(); | |
| 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( |
| 292 quic_enabled_, // Enable QUIC. | |
| 293 "", // QUIC User Agent ID. | |
| 294 http2_enabled_, // Enable SPDY. | |
| 295 false, // Enable SDCH | |
| 296 URLRequestContextConfig::DISK, // Type of http cache. | |
| 297 0, // Max size of http cache in bytes. | |
| 298 false, // Disable caching for HTTP responses. | |
| 299 cache_path.value(), // Storage path for http cache and cookie storage. | |
| 300 user_agent_, // User-Agent request header field. | |
| 301 "{}", // JSON encoded experimental options. | |
| 302 "", // Data reduction proxy key. | |
| 303 "", // Data reduction proxy. | |
| 304 "", // Fallback data reduction proxy. | |
| 305 "", // Data reduction proxy secure proxy check URL. | |
| 306 std::move(mock_cert_verifier_), // MockCertVerifier to use for testing | |
| 307 // purposes. | |
| 308 false, // Enable network quality estimator. | |
| 309 true, // Enable bypassing of public key pinning for local trust anchors | |
| 310 "")); // Certificate verifier cache data. | |
| 334 | 311 |
| 335 params.host_resolver = main_context_->host_resolver(); | 312 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 | 313 |
| 314 context_builder.set_accept_language(accept_language_); | |
| 315 | |
| 316 config->ConfigureURLRequestContextBuilder(&context_builder, net_log_.get(), | |
| 317 file_thread_.get()->task_runner()); | |
| 318 | |
| 319 std::unique_ptr<net::MappedHostResolver> mapped_host_resolver( | |
| 320 new net::MappedHostResolver( | |
| 321 net::HostResolver::CreateDefaultResolver(nullptr))); | |
| 322 | |
| 323 mapped_host_resolver->SetRulesFromString(host_resolver_rules_); | |
| 324 context_builder.set_host_resolver(std::move(mapped_host_resolver)); | |
| 325 | |
| 326 std::unordered_set<std::string> quic_host_whitelist; | |
| 327 std::unique_ptr<net::HttpServerProperties> http_server_properties( | |
| 328 new net::HttpServerPropertiesImpl()); | |
| 350 for (const auto& quic_hint : quic_hints_) { | 329 for (const auto& quic_hint : quic_hints_) { |
| 351 net::AlternativeService alternative_service(net::AlternateProtocol::QUIC, | 330 net::AlternativeService alternative_service(net::AlternateProtocol::QUIC, |
| 352 "", quic_hint.port()); | 331 "", quic_hint.port()); |
| 353 url::SchemeHostPort quic_hint_server("https", quic_hint.host(), | 332 url::SchemeHostPort quic_hint_server("https", quic_hint.host(), |
| 354 quic_hint.port()); | 333 quic_hint.port()); |
| 355 main_context_->http_server_properties()->SetAlternativeService( | 334 http_server_properties->SetAlternativeService( |
| 356 quic_hint_server, alternative_service, base::Time::Max()); | 335 quic_hint_server, alternative_service, base::Time::Max()); |
| 357 params.quic_host_whitelist.insert(quic_hint.host()); | 336 quic_host_whitelist.insert(quic_hint.host()); |
| 358 } | 337 } |
| 359 | 338 |
| 360 if (!params.channel_id_service) { | 339 context_builder.SetHttpServerProperties(std::move(http_server_properties)); |
| 361 // The main context may not have a ChannelIDService, since it is lazily | 340 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. | |
|
mmenke
2016/11/23 18:41:33
Keep this TODO?
lilyhoughton
2016/11/28 16:42:21
Where would the best place to put it be?
| |
| 365 params.channel_id_service = | |
| 366 new net::ChannelIDService(new net::DefaultChannelIDStore(NULL), | |
| 367 base::WorkerPool::GetTaskRunner(true)); | |
| 368 } | |
| 369 | 341 |
| 370 // TODO(mmenke): These really shouldn't be leaked. | 342 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 } | 343 } |
| 384 | 344 |
| 385 std::string CronetEnvironment::user_agent() { | 345 std::string CronetEnvironment::user_agent() { |
| 386 const net::HttpUserAgentSettings* user_agent_settings = | 346 const net::HttpUserAgentSettings* user_agent_settings = |
| 387 main_context_->http_user_agent_settings(); | 347 main_context_->http_user_agent_settings(); |
| 388 if (!user_agent_settings) { | 348 if (!user_agent_settings) { |
| 389 return nullptr; | 349 return nullptr; |
| 390 } | 350 } |
| 391 | 351 |
| 392 return user_agent_settings->GetUserAgent(); | 352 return user_agent_settings->GetUserAgent(); |
| 393 } | 353 } |
| 394 | 354 |
| 395 std::vector<uint8_t> CronetEnvironment::GetHistogramDeltas() { | 355 std::vector<uint8_t> CronetEnvironment::GetHistogramDeltas() { |
| 396 base::StatisticsRecorder::Initialize(); | 356 base::StatisticsRecorder::Initialize(); |
| 397 std::vector<uint8_t> data; | 357 std::vector<uint8_t> data; |
| 398 if (!HistogramManager::GetInstance()->GetDeltas(&data)) | 358 if (!HistogramManager::GetInstance()->GetDeltas(&data)) |
| 399 return std::vector<uint8_t>(); | 359 return std::vector<uint8_t>(); |
| 400 return data; | 360 return data; |
| 401 } | 361 } |
| 402 | 362 |
| 403 } // namespace cronet | 363 } // namespace cronet |
| OLD | NEW |