2ba7d341f430a56d03e34176747c4f540ee6b080
[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   Browser* browser() { return browser_.get(); }
47
48  protected:
49   // content::BrowserMainParts:
50   void PreEarlyInitialization() override;
51   void PostEarlyInitialization() override;
52   void PreMainMessageLoopRun() override;
53   bool MainMessageLoopRun(int* result_code) override;
54   void PostMainMessageLoopStart() override;
55   void PostMainMessageLoopRun() override;
56 #if defined(OS_MACOSX)
57   void PreMainMessageLoopStart() override;
58 #endif
59
60  private:
61 #if defined(OS_POSIX)
62   // Set signal handlers.
63   void HandleSIGCHLD();
64   void HandleShutdownSignals();
65 #endif
66
67 #if defined(OS_MACOSX)
68   void FreeAppDelegate();
69 #endif
70
71   // A fake BrowserProcess object that used to feed the source code from chrome.
72   std::unique_ptr<BrowserProcess> fake_browser_process_;
73
74   // The gin::PerIsolateData requires a task runner to create, so we feed it
75   // with a task runner that will post all work to main loop.
76   scoped_refptr<BridgeTaskRunner> bridge_task_runner_;
77
78   // Pointer to exit code.
79   int* exit_code_;
80
81   std::unique_ptr<Browser> browser_;
82   std::unique_ptr<JavascriptEnvironment> js_env_;
83   std::unique_ptr<NodeBindings> node_bindings_;
84   std::unique_ptr<AtomBindings> atom_bindings_;
85   std::unique_ptr<NodeEnvironment> node_env_;
86   std::unique_ptr<NodeDebugger> node_debugger_;
87
88   base::Timer gc_timer_;
89
90   // List of callbacks should be executed before destroying JS env.
91   std::list<base::Closure> destructors_;
92
93   static AtomBrowserMainParts* self_;
94
95   DISALLOW_COPY_AND_ASSIGN(AtomBrowserMainParts);
96 };
97
98 }  // namespace atom
99
100 #endif  // ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_