io_thread.cc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #if defined(USE_NSS_CERTS)
  10. #include "net/cert_net/nss_ocsp.h"
  11. #endif
  12. using content::BrowserThread;
  13. namespace brightray {
  14. IOThread::IOThread() {
  15. BrowserThread::SetIOThreadDelegate(this);
  16. }
  17. IOThread::~IOThread() {
  18. BrowserThread::SetIOThreadDelegate(nullptr);
  19. }
  20. void IOThread::Init() {
  21. net::URLRequestContextBuilder builder;
  22. builder.set_proxy_service(net::ProxyService::CreateDirect());
  23. builder.DisableHttpCache();
  24. url_request_context_ = builder.Build();
  25. #if defined(USE_NSS_CERTS)
  26. net::SetMessageLoopForNSSHttpIO();
  27. net::SetURLRequestContextForNSSHttpIO(url_request_context_.get());
  28. #endif
  29. }
  30. void IOThread::CleanUp() {
  31. #if defined(USE_NSS_CERTS)
  32. net::ShutdownNSSHttpIO();
  33. net::SetURLRequestContextForNSSHttpIO(nullptr);
  34. #endif
  35. url_request_context_.reset();
  36. }
  37. } // namespace brightray