atom_browser_main_parts.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // Copyright (c) 2013 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_ATOM_BROWSER_MAIN_PARTS_H_
  5. #define ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_
  6. #include <list>
  7. #include <memory>
  8. #include <string>
  9. #include "base/callback.h"
  10. #include "base/timer/timer.h"
  11. #include "brightray/browser/browser_main_parts.h"
  12. #include "content/public/browser/browser_context.h"
  13. #include "content/public/common/main_function_params.h"
  14. #include "services/device/public/mojom/geolocation_control.mojom.h"
  15. class BrowserProcess;
  16. class IconManager;
  17. #if defined(TOOLKIT_VIEWS)
  18. namespace brightray {
  19. class ViewsDelegate;
  20. }
  21. #endif
  22. namespace net_log {
  23. class ChromeNetLog;
  24. }
  25. namespace atom {
  26. class AtomBindings;
  27. class Browser;
  28. class IOThread;
  29. class JavascriptEnvironment;
  30. class NodeBindings;
  31. class NodeDebugger;
  32. class NodeEnvironment;
  33. class BridgeTaskRunner;
  34. #if defined(OS_MACOSX)
  35. class ViewsDelegateMac;
  36. #endif
  37. class AtomBrowserMainParts : public brightray::BrowserMainParts {
  38. public:
  39. explicit AtomBrowserMainParts(const content::MainFunctionParams& params);
  40. ~AtomBrowserMainParts() override;
  41. static AtomBrowserMainParts* Get();
  42. // Sets the exit code, will fail if the message loop is not ready.
  43. bool SetExitCode(int code);
  44. // Gets the exit code
  45. int GetExitCode();
  46. // Register a callback that should be destroyed before JavaScript environment
  47. // gets destroyed.
  48. // Returns a closure that can be used to remove |callback| from the list.
  49. void RegisterDestructionCallback(base::OnceClosure callback);
  50. // Returns the connection to GeolocationControl which can be
  51. // used to enable the location services once per client.
  52. device::mojom::GeolocationControl* GetGeolocationControl();
  53. // Returns handle to the class responsible for extracting file icons.
  54. IconManager* GetIconManager();
  55. Browser* browser() { return browser_.get(); }
  56. IOThread* io_thread() const { return io_thread_.get(); }
  57. net_log::ChromeNetLog* net_log() { return net_log_.get(); }
  58. protected:
  59. // content::BrowserMainParts:
  60. int PreEarlyInitialization() override;
  61. void PostEarlyInitialization() override;
  62. int PreCreateThreads() override;
  63. void ToolkitInitialized() override;
  64. void PreMainMessageLoopRun() override;
  65. bool MainMessageLoopRun(int* result_code) override;
  66. void PreDefaultMainMessageLoopRun(base::OnceClosure quit_closure) override;
  67. void PostMainMessageLoopStart() override;
  68. void PostMainMessageLoopRun() override;
  69. #if defined(OS_MACOSX)
  70. void PreMainMessageLoopStart() override;
  71. #endif
  72. void PostDestroyThreads() override;
  73. private:
  74. #if defined(OS_POSIX)
  75. // Set signal handlers.
  76. void HandleSIGCHLD();
  77. void HandleShutdownSignals();
  78. #endif
  79. #if defined(OS_MACOSX)
  80. void FreeAppDelegate();
  81. #endif
  82. #if defined(OS_MACOSX)
  83. std::unique_ptr<ViewsDelegateMac> views_delegate_;
  84. #else
  85. std::unique_ptr<brightray::ViewsDelegate> views_delegate_;
  86. #endif
  87. // A fake BrowserProcess object that used to feed the source code from chrome.
  88. std::unique_ptr<BrowserProcess> fake_browser_process_;
  89. // Pointer to exit code.
  90. int* exit_code_ = nullptr;
  91. std::unique_ptr<Browser> browser_;
  92. std::unique_ptr<JavascriptEnvironment> js_env_;
  93. std::unique_ptr<NodeBindings> node_bindings_;
  94. std::unique_ptr<AtomBindings> atom_bindings_;
  95. std::unique_ptr<NodeEnvironment> node_env_;
  96. std::unique_ptr<NodeDebugger> node_debugger_;
  97. std::unique_ptr<IOThread> io_thread_;
  98. std::unique_ptr<net_log::ChromeNetLog> net_log_;
  99. std::unique_ptr<IconManager> icon_manager_;
  100. base::RepeatingTimer gc_timer_;
  101. // List of callbacks should be executed before destroying JS env.
  102. std::list<base::OnceClosure> destructors_;
  103. device::mojom::GeolocationControlPtr geolocation_control_;
  104. const content::MainFunctionParams main_function_params_;
  105. static AtomBrowserMainParts* self_;
  106. DISALLOW_COPY_AND_ASSIGN(AtomBrowserMainParts);
  107. };
  108. } // namespace atom
  109. #endif // ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_