io_thread.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #ifndef ATOM_BROWSER_IO_THREAD_H_
  5. #define ATOM_BROWSER_IO_THREAD_H_
  6. #include <memory>
  7. #include <set>
  8. #include "atom/browser/net/system_network_context_manager.h"
  9. #include "base/macros.h"
  10. #include "base/synchronization/lock.h"
  11. #include "content/public/browser/browser_thread_delegate.h"
  12. #include "services/network/public/mojom/network_service.mojom.h"
  13. namespace atom {
  14. class URLRequestContextGetter;
  15. }
  16. namespace net {
  17. class URLRequestContext;
  18. }
  19. namespace net_log {
  20. class ChromeNetLog;
  21. }
  22. class IOThread : public content::BrowserThreadDelegate {
  23. public:
  24. explicit IOThread(
  25. net_log::ChromeNetLog* net_log,
  26. SystemNetworkContextManager* system_network_context_manager);
  27. ~IOThread() override;
  28. void RegisterURLRequestContextGetter(atom::URLRequestContextGetter* getter);
  29. void DeregisterURLRequestContextGetter(atom::URLRequestContextGetter* getter);
  30. protected:
  31. // BrowserThreadDelegate Implementation, runs on the IO thread.
  32. void Init() override;
  33. void CleanUp() override;
  34. private:
  35. // The NetLog is owned by the browser process, to allow logging from other
  36. // threads during shutdown, but is used most frequently on the IOThread.
  37. net_log::ChromeNetLog* net_log_;
  38. // When the network service is disabled, this holds on to a
  39. // content::NetworkContext class that owns |system_request_context_|.
  40. std::unique_ptr<network::mojom::NetworkContext> system_network_context_;
  41. net::URLRequestContext* system_request_context_;
  42. // These are set on the UI thread, and then consumed during initialization on
  43. // the IO thread.
  44. network::mojom::NetworkContextRequest network_context_request_;
  45. network::mojom::NetworkContextParamsPtr network_context_params_;
  46. // Initial HTTP auth configuration used when setting up the NetworkService on
  47. // the IO Thread. Future updates are sent using the NetworkService mojo
  48. // interface, but initial state needs to be set non-racily.
  49. network::mojom::HttpAuthStaticParamsPtr http_auth_static_params_;
  50. network::mojom::HttpAuthDynamicParamsPtr http_auth_dynamic_params_;
  51. // |lock_| protects access to |request_context_getters_|.
  52. base::Lock lock_;
  53. // List of all request contexts that needs to be notified when
  54. // IO thread is shutting down.
  55. std::set<atom::URLRequestContextGetter*> request_context_getters_;
  56. DISALLOW_COPY_AND_ASSIGN(IOThread);
  57. };
  58. #endif // ATOM_BROWSER_IO_THREAD_H_