ee1f0f2b27493fc78610c2ff56917af5e56cd6a5
[platform/framework/web/crosswalk.git] / src / xwalk / extensions / extension_process / xwalk_extension_process_main.cc
1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "xwalk/extensions/extension_process/xwalk_extension_process_main.h"
6
7 #if defined(OS_LINUX)
8 #include <signal.h>
9 #include <sys/prctl.h>
10 #endif
11
12 #include "base/debug/stack_trace.h"
13 #include "base/logging.h"
14 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h"
16 #include "base/threading/platform_thread.h"
17 #include "xwalk/extensions/extension_process/xwalk_extension_process.h"
18
19 int XWalkExtensionProcessMain(const content::MainFunctionParams& parameters) {
20   base::PlatformThread::SetName("XWalkExtensionProcess_Main");
21
22   VLOG(1) << "Extension process running!";
23
24   // FIXME(jeez): This fixes the zombie-process-on-^C issue that we are facing
25   // on Linux. However, we must find a cleaner way of doing this, perhaps using
26   // something from Chromium and ensuring this process dies when its parent die.
27 #if defined(OS_LINUX)
28   prctl(PR_SET_PDEATHSIG, SIGTERM);
29 #endif
30
31   // On Linux-based platforms, we want the Glib message pump running so we need
32   // a TYPE_UI MessageLoop. For other platforms we will stick with TYPE_DEFAULT
33   // for now.
34   base::MessageLoop::Type message_loop_type;
35 #if defined(OS_POSIX)
36   message_loop_type = base::MessageLoop::TYPE_UI;
37 #else
38   message_loop_type = base::MessageLoop::TYPE_DEFAULT;
39 #endif
40
41   base::MessageLoop main_message_loop(message_loop_type);
42   xwalk::extensions::XWalkExtensionProcess extension_process;
43
44 #ifndef NDEBUG
45   // In debug mode, enable to stack dumping in a similar fashion than Renderer
46   // Process. This is helpful to understand crashes in Extension Process.
47   base::debug::EnableInProcessStackDumping();
48 #endif
49
50   base::RunLoop run_loop;
51   run_loop.Run();
52
53   return 0;
54 }