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" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/feature_list.h" | 12 #include "base/feature_list.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 15 #include "base/files/scoped_file.h" | 15 #include "base/files/scoped_file.h" |
| 16 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
| 17 #include "base/mac/bind_objc_block.h" | 17 #include "base/mac/bind_objc_block.h" |
| 18 #include "base/mac/foundation_util.h" | 18 #include "base/mac/foundation_util.h" |
| 19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/memory/ptr_util.h" | 20 #include "base/memory/ptr_util.h" |
| 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/net/cookies/cookie_store_ios.h" | |
| 30 #include "ios/web/public/user_agent.h" | 31 #include "ios/web/public/user_agent.h" |
| 31 #include "net/base/net_errors.h" | 32 #include "net/base/net_errors.h" |
| 32 #include "net/base/network_change_notifier.h" | 33 #include "net/base/network_change_notifier.h" |
| 33 #include "net/cert/cert_verifier.h" | 34 #include "net/cert/cert_verifier.h" |
| 34 #include "net/cert/ct_known_logs.h" | 35 #include "net/cert/ct_known_logs.h" |
| 35 #include "net/cert/ct_log_verifier.h" | 36 #include "net/cert/ct_log_verifier.h" |
| 36 #include "net/cert/ct_policy_enforcer.h" | 37 #include "net/cert/ct_policy_enforcer.h" |
| 37 #include "net/cert/ct_verifier.h" | 38 #include "net/cert/ct_verifier.h" |
| 38 #include "net/cert/multi_log_ct_verifier.h" | 39 #include "net/cert/multi_log_ct_verifier.h" |
| 40 #include "net/cookies/cookie_store.h" | |
| 39 #include "net/dns/host_resolver.h" | 41 #include "net/dns/host_resolver.h" |
| 40 #include "net/dns/mapped_host_resolver.h" | 42 #include "net/dns/mapped_host_resolver.h" |
| 41 #include "net/http/http_auth_handler_factory.h" | 43 #include "net/http/http_auth_handler_factory.h" |
| 42 #include "net/http/http_cache.h" | 44 #include "net/http/http_cache.h" |
| 43 #include "net/http/http_response_headers.h" | 45 #include "net/http/http_response_headers.h" |
| 44 #include "net/http/http_server_properties_impl.h" | 46 #include "net/http/http_server_properties_impl.h" |
| 45 #include "net/http/http_stream_factory.h" | 47 #include "net/http/http_stream_factory.h" |
| 46 #include "net/http/http_util.h" | 48 #include "net/http/http_util.h" |
| 47 #include "net/log/net_log.h" | 49 #include "net/log/net_log.h" |
| 48 #include "net/log/net_log_capture_mode.h" | 50 #include "net/log/net_log_capture_mode.h" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 network_io_thread_->task_runner(), nullptr); | 258 network_io_thread_->task_runner(), nullptr); |
| 257 main_context_getter_ = new CronetURLRequestContextGetter( | 259 main_context_getter_ = new CronetURLRequestContextGetter( |
| 258 this, network_io_thread_->task_runner()); | 260 this, network_io_thread_->task_runner()); |
| 259 base::subtle::MemoryBarrier(); | 261 base::subtle::MemoryBarrier(); |
| 260 PostToNetworkThread(FROM_HERE, | 262 PostToNetworkThread(FROM_HERE, |
| 261 base::Bind(&CronetEnvironment::InitializeOnNetworkThread, | 263 base::Bind(&CronetEnvironment::InitializeOnNetworkThread, |
| 262 base::Unretained(this))); | 264 base::Unretained(this))); |
| 263 } | 265 } |
| 264 | 266 |
| 265 CronetEnvironment::~CronetEnvironment() { | 267 CronetEnvironment::~CronetEnvironment() { |
| 266 // net::HTTPProtocolHandlerDelegate::SetInstance(nullptr); | 268 // net::HTTPProtocolHandlerDelegate::SetInstance(nullptr); |
|
kapishnikov
2016/11/18 20:58:03
Why do we need it here?
mef
2016/11/18 22:29:36
git cl format is different for .mm and .cc.
| |
| 267 } | 269 } |
| 268 | 270 |
| 269 void CronetEnvironment::InitializeOnNetworkThread() { | 271 void CronetEnvironment::InitializeOnNetworkThread() { |
| 270 DCHECK(network_io_thread_->task_runner()->BelongsToCurrentThread()); | 272 DCHECK(network_io_thread_->task_runner()->BelongsToCurrentThread()); |
| 271 base::FeatureList::InitializeInstance(std::string(), std::string()); | 273 base::FeatureList::InitializeInstance(std::string(), std::string()); |
| 272 // TODO(mef): Use net:UrlRequestContextBuilder instead of manual build. | 274 // TODO(mef): Use net:UrlRequestContextBuilder instead of manual build. |
| 273 main_context_.reset(new net::URLRequestContext); | 275 main_context_.reset(new net::URLRequestContext); |
| 274 main_context_->set_net_log(net_log_.get()); | 276 main_context_->set_net_log(net_log_.get()); |
| 275 | 277 |
| 276 if (user_agent_partial_) | 278 if (user_agent_partial_) |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 params.transport_security_state = main_context_->transport_security_state(); | 338 params.transport_security_state = main_context_->transport_security_state(); |
| 337 params.proxy_service = main_context_->proxy_service(); | 339 params.proxy_service = main_context_->proxy_service(); |
| 338 params.ssl_config_service = main_context_->ssl_config_service(); | 340 params.ssl_config_service = main_context_->ssl_config_service(); |
| 339 params.http_auth_handler_factory = main_context_->http_auth_handler_factory(); | 341 params.http_auth_handler_factory = main_context_->http_auth_handler_factory(); |
| 340 params.http_server_properties = main_context_->http_server_properties(); | 342 params.http_server_properties = main_context_->http_server_properties(); |
| 341 params.net_log = main_context_->net_log(); | 343 params.net_log = main_context_->net_log(); |
| 342 params.enable_http2 = http2_enabled(); | 344 params.enable_http2 = http2_enabled(); |
| 343 params.enable_quic = quic_enabled(); | 345 params.enable_quic = quic_enabled(); |
| 344 | 346 |
| 345 for (const auto& quic_hint : quic_hints_) { | 347 for (const auto& quic_hint : quic_hints_) { |
| 346 net::AlternativeService alternative_service(net::AlternateProtocol::QUIC, | 348 net::AlternativeService alternative_service(net::kProtoQUIC, "", |
|
kapishnikov
2016/11/18 20:58:03
Why are we changing net::AlternateProtocol::QUIC t
mef
2016/11/18 22:29:36
Synced to head.
| |
| 347 "", quic_hint.port()); | 349 quic_hint.port()); |
| 348 url::SchemeHostPort quic_hint_server("https", quic_hint.host(), | 350 url::SchemeHostPort quic_hint_server("https", quic_hint.host(), |
| 349 quic_hint.port()); | 351 quic_hint.port()); |
| 350 main_context_->http_server_properties()->SetAlternativeService( | 352 main_context_->http_server_properties()->SetAlternativeService( |
| 351 quic_hint_server, alternative_service, base::Time::Max()); | 353 quic_hint_server, alternative_service, base::Time::Max()); |
| 352 params.quic_host_whitelist.insert(quic_hint.host()); | 354 params.quic_host_whitelist.insert(quic_hint.host()); |
| 353 } | 355 } |
| 354 | 356 |
| 355 if (!params.channel_id_service) { | 357 if (!params.channel_id_service) { |
| 356 // The main context may not have a ChannelIDService, since it is lazily | 358 // The main context may not have a ChannelIDService, since it is lazily |
| 357 // constructed. If not, build an ephemeral ChannelIDService with no backing | 359 // constructed. If not, build an ephemeral ChannelIDService with no backing |
| 358 // disk store. | 360 // disk store. |
| 359 // TODO(ellyjones): support persisting ChannelID. | 361 // TODO(ellyjones): support persisting ChannelID. |
| 360 params.channel_id_service = | 362 params.channel_id_service = |
| 361 new net::ChannelIDService(new net::DefaultChannelIDStore(NULL), | 363 new net::ChannelIDService(new net::DefaultChannelIDStore(NULL), |
| 362 base::WorkerPool::GetTaskRunner(true)); | 364 base::WorkerPool::GetTaskRunner(true)); |
| 363 } | 365 } |
| 364 | 366 |
| 365 // TODO(mmenke): These really shouldn't be leaked. | 367 // TODO(mmenke): These really shouldn't be leaked. |
| 366 // See https://crbug.com/523858. | 368 // See https://crbug.com/523858. |
| 367 net::HttpNetworkSession* http_network_session = | 369 net::HttpNetworkSession* http_network_session = |
| 368 new net::HttpNetworkSession(params); | 370 new net::HttpNetworkSession(params); |
| 369 net::HttpCache* main_cache = | 371 net::HttpCache* main_cache = |
| 370 new net::HttpCache(http_network_session, std::move(main_backend), | 372 new net::HttpCache(http_network_session, std::move(main_backend), |
| 371 true /* set_up_quic_server_info */); | 373 true /* set_up_quic_server_info */); |
| 372 main_context_->set_http_transaction_factory(main_cache); | 374 main_context_->set_http_transaction_factory(main_cache); |
| 375 // Cookies | |
| 376 cookie_store_ = net::CookieStoreIOS::CreateCookieStore( | |
| 377 [NSHTTPCookieStorage sharedHTTPCookieStorage]); | |
| 378 main_context_->set_cookie_store(cookie_store_.get()); | |
| 373 | 379 |
| 374 net::URLRequestJobFactoryImpl* job_factory = | 380 net::URLRequestJobFactoryImpl* job_factory = |
| 375 new net::URLRequestJobFactoryImpl; | 381 new net::URLRequestJobFactoryImpl; |
| 376 main_context_->set_job_factory(job_factory); | 382 main_context_->set_job_factory(job_factory); |
| 377 main_context_->set_net_log(net_log_.get()); | 383 main_context_->set_net_log(net_log_.get()); |
| 378 } | 384 } |
| 379 | 385 |
| 380 std::string CronetEnvironment::user_agent() { | 386 std::string CronetEnvironment::user_agent() { |
| 381 const net::HttpUserAgentSettings* user_agent_settings = | 387 const net::HttpUserAgentSettings* user_agent_settings = |
| 382 main_context_->http_user_agent_settings(); | 388 main_context_->http_user_agent_settings(); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 407 | 413 |
| 408 void CronetEnvironment::SetHostResolverRulesOnNetworkThread( | 414 void CronetEnvironment::SetHostResolverRulesOnNetworkThread( |
| 409 const std::string& rules, | 415 const std::string& rules, |
| 410 base::WaitableEvent* event) { | 416 base::WaitableEvent* event) { |
| 411 static_cast<net::MappedHostResolver*>(main_context_->host_resolver()) | 417 static_cast<net::MappedHostResolver*>(main_context_->host_resolver()) |
| 412 ->SetRulesFromString(rules); | 418 ->SetRulesFromString(rules); |
| 413 event->Signal(); | 419 event->Signal(); |
| 414 } | 420 } |
| 415 | 421 |
| 416 } // namespace cronet | 422 } // namespace cronet |
| OLD | NEW |