Upstream version 8.36.156.0
[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
11 #include "base/message_loop/message_pump_glib.h"
12 #endif
13
14 #include "base/debug/stack_trace.h"
15 #include "base/logging.h"
16 #include "base/message_loop/message_loop.h"
17 #include "base/run_loop.h"
18 #include "base/threading/platform_thread.h"
19 #include "xwalk/extensions/extension_process/xwalk_extension_process.h"
20
21 int XWalkExtensionProcessMain(const content::MainFunctionParams& parameters) {
22   base::PlatformThread::SetName("XWalkExtensionProcess_Main");
23
24   VLOG(1) << "Extension process running!";
25
26 #if defined(OS_LINUX)
27   // FIXME(jeez): This fixes the zombie-process-on-^C issue that we are facing
28   // on Linux. However, we must find a cleaner way of doing this, perhaps using
29   // something from Chromium and ensuring this process dies when its parent die.
30   prctl(PR_SET_PDEATHSIG, SIGTERM);
31
32   // On Linux-based platforms, we want the Glib message pump running so we force
33   // it by declaring it explicitly. For other platforms we will stick with
34   // TYPE_DEFAULT for now.
35   base::MessageLoop main_message_loop(
36       make_scoped_ptr<base::MessagePump>(new base::MessagePumpGlib()));
37 #else
38   base::MessageLoop main_message_loop(base::MessageLoop::TYPE_DEFAULT);
39 #endif
40
41   xwalk::extensions::XWalkExtensionProcess extension_process;
42
43 #ifndef NDEBUG
44   // In debug mode, enable to stack dumping in a similar fashion than Renderer
45   // Process. This is helpful to understand crashes in Extension Process.
46   base::debug::EnableInProcessStackDumping();
47 #endif
48
49   base::RunLoop run_loop;
50   run_loop.Run();
51
52   return 0;
53 }