| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/url_request/url_request_context_builder.h" | 5 #include "net/url_request/url_request_context_builder.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate); | 131 DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate); |
| 132 }; | 132 }; |
| 133 | 133 |
| 134 // Define a context class that can self-manage the ownership of its components | 134 // Define a context class that can self-manage the ownership of its components |
| 135 // via a UrlRequestContextStorage object. | 135 // via a UrlRequestContextStorage object. |
| 136 class ContainerURLRequestContext : public URLRequestContext { | 136 class ContainerURLRequestContext : public URLRequestContext { |
| 137 public: | 137 public: |
| 138 explicit ContainerURLRequestContext( | 138 explicit ContainerURLRequestContext( |
| 139 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) | 139 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) |
| 140 : file_task_runner_(file_task_runner), storage_(this) {} | 140 : file_task_runner_(file_task_runner), storage_(this) {} |
| 141 ~ContainerURLRequestContext() override { AssertNoURLRequests(); } | 141 |
| 142 ~ContainerURLRequestContext() override { |
| 143 // Shut down the ProxyService, as it may have pending URLRequests using this |
| 144 // context. |
| 145 proxy_service()->OnShutdown(); |
| 146 |
| 147 AssertNoURLRequests(); |
| 148 } |
| 142 | 149 |
| 143 URLRequestContextStorage* storage() { | 150 URLRequestContextStorage* storage() { |
| 144 return &storage_; | 151 return &storage_; |
| 145 } | 152 } |
| 146 | 153 |
| 147 scoped_refptr<base::SingleThreadTaskRunner>& GetFileTaskRunner() { | 154 scoped_refptr<base::SingleThreadTaskRunner>& GetFileTaskRunner() { |
| 148 // Create a new thread to run file tasks, if needed. | 155 // Create a new thread to run file tasks, if needed. |
| 149 if (!file_task_runner_) { | 156 if (!file_task_runner_) { |
| 150 DCHECK(!file_thread_); | 157 DCHECK(!file_thread_); |
| 151 file_thread_.reset(new base::Thread("Network File Thread")); | 158 file_thread_.reset(new base::Thread("Network File Thread")); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 context->set_net_log(net_log_); | 329 context->set_net_log(net_log_); |
| 323 } else { | 330 } else { |
| 324 storage->set_net_log(base::WrapUnique(new NetLog)); | 331 storage->set_net_log(base::WrapUnique(new NetLog)); |
| 325 } | 332 } |
| 326 | 333 |
| 327 if (!host_resolver_) { | 334 if (!host_resolver_) { |
| 328 host_resolver_ = HostResolver::CreateDefaultResolver(context->net_log()); | 335 host_resolver_ = HostResolver::CreateDefaultResolver(context->net_log()); |
| 329 } | 336 } |
| 330 storage->set_host_resolver(std::move(host_resolver_)); | 337 storage->set_host_resolver(std::move(host_resolver_)); |
| 331 | 338 |
| 332 if (!proxy_service_) { | |
| 333 // TODO(willchan): Switch to using this code when | |
| 334 // ProxyService::CreateSystemProxyConfigService()'s signature doesn't suck. | |
| 335 #if !defined(OS_LINUX) && !defined(OS_ANDROID) | |
| 336 if (!proxy_config_service_) { | |
| 337 proxy_config_service_ = ProxyService::CreateSystemProxyConfigService( | |
| 338 base::ThreadTaskRunnerHandle::Get().get(), | |
| 339 context->GetFileTaskRunner()); | |
| 340 } | |
| 341 #endif // !defined(OS_LINUX) && !defined(OS_ANDROID) | |
| 342 proxy_service_ = ProxyService::CreateUsingSystemProxyResolver( | |
| 343 std::move(proxy_config_service_), | |
| 344 context->net_log()); | |
| 345 } | |
| 346 storage->set_proxy_service(std::move(proxy_service_)); | |
| 347 | |
| 348 storage->set_ssl_config_service(new SSLConfigServiceDefaults); | 339 storage->set_ssl_config_service(new SSLConfigServiceDefaults); |
| 349 | 340 |
| 350 if (!http_auth_handler_factory_) { | 341 if (!http_auth_handler_factory_) { |
| 351 http_auth_handler_factory_ = | 342 http_auth_handler_factory_ = |
| 352 HttpAuthHandlerRegistryFactory::CreateDefault(context->host_resolver()); | 343 HttpAuthHandlerRegistryFactory::CreateDefault(context->host_resolver()); |
| 353 } | 344 } |
| 354 | 345 |
| 355 storage->set_http_auth_handler_factory(std::move(http_auth_handler_factory_)); | 346 storage->set_http_auth_handler_factory(std::move(http_auth_handler_factory_)); |
| 356 | 347 |
| 357 if (cookie_store_set_by_client_) { | 348 if (cookie_store_set_by_client_) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 ct_verifier->AddLogs(ct::CreateLogVerifiersForKnownLogs()); | 395 ct_verifier->AddLogs(ct::CreateLogVerifiersForKnownLogs()); |
| 405 storage->set_cert_transparency_verifier(std::move(ct_verifier)); | 396 storage->set_cert_transparency_verifier(std::move(ct_verifier)); |
| 406 } | 397 } |
| 407 storage->set_ct_policy_enforcer(base::MakeUnique<CTPolicyEnforcer>()); | 398 storage->set_ct_policy_enforcer(base::MakeUnique<CTPolicyEnforcer>()); |
| 408 | 399 |
| 409 if (throttling_enabled_) { | 400 if (throttling_enabled_) { |
| 410 storage->set_throttler_manager( | 401 storage->set_throttler_manager( |
| 411 base::MakeUnique<URLRequestThrottlerManager>()); | 402 base::MakeUnique<URLRequestThrottlerManager>()); |
| 412 } | 403 } |
| 413 | 404 |
| 405 if (!proxy_service_) { |
| 406 #if !defined(OS_LINUX) && !defined(OS_ANDROID) |
| 407 // TODO(willchan): Switch to using this code when |
| 408 // ProxyService::CreateSystemProxyConfigService()'s signature doesn't suck. |
| 409 if (!proxy_config_service_) { |
| 410 proxy_config_service_ = ProxyService::CreateSystemProxyConfigService( |
| 411 base::ThreadTaskRunnerHandle::Get().get(), |
| 412 context->GetFileTaskRunner()); |
| 413 } |
| 414 #endif // !defined(OS_LINUX) && !defined(OS_ANDROID) |
| 415 proxy_service_ = |
| 416 CreateProxyService(std::move(proxy_config_service_), context.get(), |
| 417 context->host_resolver(), |
| 418 context->network_delegate(), context->net_log()); |
| 419 } |
| 420 storage->set_proxy_service(std::move(proxy_service_)); |
| 421 |
| 414 HttpNetworkSession::Params network_session_params; | 422 HttpNetworkSession::Params network_session_params; |
| 415 SetHttpNetworkSessionComponents(context.get(), &network_session_params); | 423 SetHttpNetworkSessionComponents(context.get(), &network_session_params); |
| 416 | 424 |
| 417 network_session_params.ignore_certificate_errors = | 425 network_session_params.ignore_certificate_errors = |
| 418 http_network_session_params_.ignore_certificate_errors; | 426 http_network_session_params_.ignore_certificate_errors; |
| 419 network_session_params.host_mapping_rules = | 427 network_session_params.host_mapping_rules = |
| 420 http_network_session_params_.host_mapping_rules; | 428 http_network_session_params_.host_mapping_rules; |
| 421 network_session_params.testing_fixed_http_port = | 429 network_session_params.testing_fixed_http_port = |
| 422 http_network_session_params_.testing_fixed_http_port; | 430 http_network_session_params_.testing_fixed_http_port; |
| 423 network_session_params.testing_fixed_https_port = | 431 network_session_params.testing_fixed_https_port = |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 std::move(top_job_factory), std::move(*i))); | 525 std::move(top_job_factory), std::move(*i))); |
| 518 } | 526 } |
| 519 url_request_interceptors_.clear(); | 527 url_request_interceptors_.clear(); |
| 520 } | 528 } |
| 521 storage->set_job_factory(std::move(top_job_factory)); | 529 storage->set_job_factory(std::move(top_job_factory)); |
| 522 // TODO(willchan): Support sdch. | 530 // TODO(willchan): Support sdch. |
| 523 | 531 |
| 524 return std::move(context); | 532 return std::move(context); |
| 525 } | 533 } |
| 526 | 534 |
| 535 std::unique_ptr<ProxyService> URLRequestContextBuilder::CreateProxyService( |
| 536 std::unique_ptr<ProxyConfigService> proxy_config_service, |
| 537 URLRequestContext* url_request_context, |
| 538 HostResolver* host_resolver, |
| 539 NetworkDelegate* network_delegate, |
| 540 NetLog* net_log) { |
| 541 return ProxyService::CreateUsingSystemProxyResolver( |
| 542 std::move(proxy_config_service), net_log); |
| 543 } |
| 544 |
| 527 } // namespace net | 545 } // namespace net |
| OLD | NEW |