Initial Implementation of Node prelaunch
[platform/framework/web/crosswalk-tizen.git] / atom / browser / atom_browser_main_parts.h
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
5 #ifndef ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_
6 #define ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_
7
8 #include <list>
9 #include <string>
10
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"
15
16 class BrowserProcess;
17
18 namespace atom {
19
20 class AtomBindings;
21 class Browser;
22 class JavascriptEnvironment;
23 class NodeBindings;
24 class NodeDebugger;
25 class NodeEnvironment;
26 class BridgeTaskRunner;
27
28 class AtomBrowserMainParts : public brightray::BrowserMainParts {
29  public:
30   AtomBrowserMainParts();
31   virtual ~AtomBrowserMainParts();
32
33   static AtomBrowserMainParts* Get();
34
35   // Sets the exit code, will fail if the message loop is not ready.
36   bool SetExitCode(int code);
37
38   // Gets the exit code
39   int GetExitCode();
40
41   // Register a callback that should be destroyed before JavaScript environment
42   // gets destroyed.
43   // Returns a closure that can be used to remove |callback| from the list.
44   base::Closure RegisterDestructionCallback(const base::Closure& callback);
45
46   static void SetNodeEnvironment();
47
48   Browser* browser() { return browser_.get(); }
49   static Browser* GetStaticBrowser();
50
51  protected:
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;
61 #endif
62
63  private:
64 #if defined(OS_POSIX)
65   // Set signal handlers.
66   void HandleSIGCHLD();
67   void HandleShutdownSignals();
68 #endif
69
70 #if defined(OS_MACOSX)
71   void FreeAppDelegate();
72 #endif
73
74   // A fake BrowserProcess object that used to feed the source code from chrome.
75   std::unique_ptr<BrowserProcess> fake_browser_process_;
76
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_;
80
81   // Pointer to exit code.
82   int* exit_code_;
83
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_;
90
91   base::Timer gc_timer_;
92
93   // List of callbacks should be executed before destroying JS env.
94   std::list<base::Closure> destructors_;
95
96   static AtomBrowserMainParts* self_;
97
98   DISALLOW_COPY_AND_ASSIGN(AtomBrowserMainParts);
99 };
100
101 }  // namespace atom
102
103 #endif  // ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_