atom_browser_main_parts.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 "content/public/browser/browser_context.h"
  12. #include "content/public/browser/browser_main_parts.h"
  13. #include "content/public/common/main_function_params.h"
  14. #include "services/device/public/mojom/geolocation_control.mojom.h"
  15. #include "ui/views/layout/layout_provider.h"
  16. class BrowserProcess;
  17. class IconManager;
  18. #if defined(USE_AURA)
  19. namespace wm {
  20. class WMState;
  21. }
  22. #endif
  23. namespace atom {
  24. class AtomBindings;
  25. class Browser;
  26. class JavascriptEnvironment;
  27. class NodeBindings;
  28. class NodeDebugger;
  29. class NodeEnvironment;
  30. class BridgeTaskRunner;
  31. #if defined(TOOLKIT_VIEWS)
  32. class ViewsDelegate;
  33. #endif
  34. #if defined(OS_MACOSX)
  35. class ViewsDelegateMac;
  36. #endif
  37. class AtomBrowserMainParts : public content::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. protected:
  57. // content::BrowserMainParts:
  58. int PreEarlyInitialization() override;
  59. void PostEarlyInitialization() override;
  60. int PreCreateThreads() override;
  61. void ToolkitInitialized() override;
  62. void PreMainMessageLoopRun() override;
  63. bool MainMessageLoopRun(int* result_code) override;
  64. void PreDefaultMainMessageLoopRun(base::OnceClosure quit_closure) override;
  65. void PostMainMessageLoopStart() override;
  66. void PostMainMessageLoopRun() override;
  67. void PreMainMessageLoopStart() override;
  68. void PostDestroyThreads() override;
  69. private:
  70. void InitializeFeatureList();
  71. void OverrideAppLogsPath();
  72. void PreMainMessageLoopStartCommon();
  73. #if defined(OS_POSIX)
  74. // Set signal handlers.
  75. void HandleSIGCHLD();
  76. void HandleShutdownSignals();
  77. #endif
  78. #if defined(OS_MACOSX)
  79. void FreeAppDelegate();
  80. void InitializeMainNib();
  81. #endif
  82. #if defined(OS_MACOSX)
  83. std::unique_ptr<ViewsDelegateMac> views_delegate_;
  84. #else
  85. std::unique_ptr<ViewsDelegate> views_delegate_;
  86. #endif
  87. #if defined(USE_AURA)
  88. std::unique_ptr<wm::WMState> wm_state_;
  89. #endif
  90. std::unique_ptr<views::LayoutProvider> layout_provider_;
  91. // A fake BrowserProcess object that used to feed the source code from chrome.
  92. std::unique_ptr<BrowserProcessImpl> fake_browser_process_;
  93. // Pointer to exit code.
  94. int* exit_code_ = nullptr;
  95. std::unique_ptr<Browser> browser_;
  96. std::unique_ptr<JavascriptEnvironment> js_env_;
  97. std::unique_ptr<NodeBindings> node_bindings_;
  98. std::unique_ptr<AtomBindings> atom_bindings_;
  99. std::unique_ptr<NodeEnvironment> node_env_;
  100. std::unique_ptr<NodeDebugger> node_debugger_;
  101. std::unique_ptr<IconManager> icon_manager_;
  102. base::RepeatingTimer gc_timer_;
  103. // List of callbacks should be executed before destroying JS env.
  104. std::list<base::OnceClosure> destructors_;
  105. device::mojom::GeolocationControlPtr geolocation_control_;
  106. const content::MainFunctionParams main_function_params_;
  107. static AtomBrowserMainParts* self_;
  108. DISALLOW_COPY_AND_ASSIGN(AtomBrowserMainParts);
  109. };
  110. } // namespace atom
  111. #endif // ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_