io_thread.cc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 "brightray/browser/io_thread.h"
  5. #include "content/public/browser/browser_thread.h"
  6. #include "net/proxy/proxy_service.h"
  7. #include "net/url_request/url_request_context.h"
  8. #include "net/url_request/url_request_context_builder.h"
  9. #include "net/url_request/url_request_context_getter.h"
  10. #if defined(USE_NSS_CERTS)
  11. #include "net/cert_net/nss_ocsp.h"
  12. #endif
  13. using content::BrowserThread;
  14. namespace brightray {
  15. IOThread::IOThread() {
  16. BrowserThread::SetIOThreadDelegate(this);
  17. }
  18. IOThread::~IOThread() {
  19. BrowserThread::SetIOThreadDelegate(nullptr);
  20. }
  21. void IOThread::Init() {
  22. net::URLRequestContextBuilder builder;
  23. builder.set_proxy_service(net::ProxyService::CreateDirect());
  24. url_request_context_ = builder.Build();
  25. url_request_context_getter_ = new net::TrivialURLRequestContextGetter(
  26. url_request_context_.get(), base::ThreadTaskRunnerHandle::Get());
  27. url_request_context_getter_->AddRef();
  28. #if defined(USE_NSS_CERTS)
  29. net::SetMessageLoopForNSSHttpIO();
  30. net::SetURLRequestContextForNSSHttpIO(url_request_context_.get());
  31. #endif
  32. }
  33. void IOThread::CleanUp() {
  34. #if defined(USE_NSS_CERTS)
  35. net::ShutdownNSSHttpIO();
  36. net::SetURLRequestContextForNSSHttpIO(nullptr);
  37. #endif
  38. // Explicitly release before the IO thread gets destroyed.
  39. url_request_context_getter_->Release();
  40. url_request_context_.reset();
  41. }
  42. } // namespace brightray