io_thread.cc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright (c) 2017 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "atom/browser/io_thread.h"
  5. #include <utility>
  6. #include "components/net_log/chrome_net_log.h"
  7. #include "content/public/browser/browser_thread.h"
  8. #include "content/public/browser/network_service_instance.h"
  9. #include "net/cert/caching_cert_verifier.h"
  10. #include "net/cert/cert_verifier.h"
  11. #include "net/cert/cert_verify_proc.h"
  12. #include "net/cert/multi_threaded_cert_verifier.h"
  13. #include "net/proxy_resolution/proxy_resolution_service.h"
  14. #include "net/url_request/url_request_context.h"
  15. #include "services/network/network_service.h"
  16. #include "services/network/url_request_context_builder_mojo.h"
  17. using content::BrowserThread;
  18. IOThread::IOThread(net_log::ChromeNetLog* net_log,
  19. SystemNetworkContextManager* system_network_context_manager)
  20. : net_log_(net_log) {
  21. BrowserThread::SetIOThreadDelegate(this);
  22. system_network_context_manager->SetUp(
  23. &network_context_request_, &network_context_params_,
  24. &http_auth_static_params_, &http_auth_dynamic_params_);
  25. }
  26. IOThread::~IOThread() {
  27. BrowserThread::SetIOThreadDelegate(nullptr);
  28. }
  29. void IOThread::Init() {
  30. std::unique_ptr<network::URLRequestContextBuilderMojo> builder =
  31. std::make_unique<network::URLRequestContextBuilderMojo>();
  32. auto cert_verifier = std::make_unique<net::CachingCertVerifier>(
  33. std::make_unique<net::MultiThreadedCertVerifier>(
  34. net::CertVerifyProc::CreateDefault()));
  35. builder->SetCertVerifier(std::move(cert_verifier));
  36. // Create the network service, so that shared host resolver
  37. // gets created which is required to set the auth preferences below.
  38. network::NetworkService* network_service = content::GetNetworkServiceImpl();
  39. network_service->SetUpHttpAuth(std::move(http_auth_static_params_));
  40. network_service->ConfigureHttpAuthPrefs(std::move(http_auth_dynamic_params_));
  41. system_network_context_ =
  42. network_service
  43. ->CreateNetworkContextWithBuilder(std::move(network_context_request_),
  44. std::move(network_context_params_),
  45. std::move(builder),
  46. &system_request_context_)
  47. .release();
  48. }
  49. void IOThread::CleanUp() {
  50. system_request_context_->proxy_resolution_service()->OnShutdown();
  51. if (net_log_)
  52. net_log_->ShutDownBeforeTaskScheduler();
  53. }