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.
5 #ifndef ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_
6 #define ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_
11 #include "base/callback.h"
12 #include "base/timer/timer.h"
13 #include "brightray/browser/browser_main_parts.h"
14 #include "content/public/browser/browser_context.h"
22 class JavascriptEnvironment;
25 class NodeEnvironment;
26 class BridgeTaskRunner;
28 class AtomBrowserMainParts : public brightray::BrowserMainParts {
30 AtomBrowserMainParts();
31 virtual ~AtomBrowserMainParts();
33 static AtomBrowserMainParts* Get();
35 // Sets the exit code, will fail if the message loop is not ready.
36 bool SetExitCode(int code);
41 // Register a callback that should be destroyed before JavaScript environment
43 // Returns a closure that can be used to remove |callback| from the list.
44 base::Closure RegisterDestructionCallback(const base::Closure& callback);
46 static void SetNodeEnvironment();
48 Browser* browser() { return browser_.get(); }
49 static Browser* GetStaticBrowser();
52 // content::BrowserMainParts:
53 void PreEarlyInitialization() override;
54 void PostEarlyInitialization() override;
55 void PreMainMessageLoopRun() override;
56 bool MainMessageLoopRun(int* result_code) override;
57 void PostMainMessageLoopStart() override;
58 void PostMainMessageLoopRun() override;
59 #if defined(OS_MACOSX)
60 void PreMainMessageLoopStart() override;
65 // Set signal handlers.
67 void HandleShutdownSignals();
70 #if defined(OS_MACOSX)
71 void FreeAppDelegate();
74 // A fake BrowserProcess object that used to feed the source code from chrome.
75 std::unique_ptr<BrowserProcess> fake_browser_process_;
77 // The gin::PerIsolateData requires a task runner to create, so we feed it
78 // with a task runner that will post all work to main loop.
79 scoped_refptr<BridgeTaskRunner> bridge_task_runner_;
81 // Pointer to exit code.
84 std::unique_ptr<Browser> browser_;
85 std::unique_ptr<JavascriptEnvironment> js_env_;
86 std::unique_ptr<NodeBindings> node_bindings_;
87 std::unique_ptr<AtomBindings> atom_bindings_;
88 std::unique_ptr<NodeEnvironment> node_env_;
89 std::unique_ptr<NodeDebugger> node_debugger_;
91 base::Timer gc_timer_;
93 // List of callbacks should be executed before destroying JS env.
94 std::list<base::Closure> destructors_;
96 static AtomBrowserMainParts* self_;
98 DISALLOW_COPY_AND_ASSIGN(AtomBrowserMainParts);
103 #endif // ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_