OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/debug/leak_annotations.h" | 6 #include "base/debug/leak_annotations.h" |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/threading/platform_thread.h" | 8 #include "base/threading/platform_thread.h" |
9 #include "base/timer/hi_res_timer_manager.h" | 9 #include "base/timer/hi_res_timer_manager.h" |
10 #include "content/child/child_process.h" | 10 #include "content/child/child_process.h" |
11 #include "content/common/sandbox_linux/sandbox_linux.h" | 11 #include "content/common/sandbox_linux/sandbox_linux.h" |
12 #include "content/public/common/content_switches.h" | 12 #include "content/public/common/content_switches.h" |
13 #include "content/public/common/main_function_params.h" | 13 #include "content/public/common/main_function_params.h" |
14 #include "content/public/common/sandbox_init.h" | 14 #include "content/public/common/sandbox_init.h" |
15 #include "content/utility/utility_thread_impl.h" | 15 #include "content/utility/utility_thread_impl.h" |
16 | 16 |
17 #if defined(OS_WIN) | 17 #if defined(OS_WIN) |
18 #include "sandbox/win/src/sandbox.h" | 18 #include "sandbox/win/src/sandbox.h" |
19 #endif | 19 #endif |
20 | 20 |
21 #if defined(TOOLKIT_GTK) | |
22 #include <gtk/gtk.h> | |
23 | |
24 #include "ui/gfx/gtk_util.h" | |
25 #endif | |
26 | |
27 namespace content { | 21 namespace content { |
28 | 22 |
29 // Mainline routine for running as the utility process. | 23 // Mainline routine for running as the utility process. |
30 int UtilityMain(const MainFunctionParams& parameters) { | 24 int UtilityMain(const MainFunctionParams& parameters) { |
31 // The main message loop of the utility process. | 25 // The main message loop of the utility process. |
32 base::MessageLoop main_message_loop; | 26 base::MessageLoop main_message_loop; |
33 base::PlatformThread::SetName("CrUtilityMain"); | 27 base::PlatformThread::SetName("CrUtilityMain"); |
34 | 28 |
35 #if defined(OS_LINUX) | 29 #if defined(OS_LINUX) |
36 // Initializes the sandbox before any threads are created. | 30 // Initializes the sandbox before any threads are created. |
37 // TODO(jorgelo): move this after GTK initialization when we enable a strict | 31 // TODO(jorgelo): move this after GTK initialization when we enable a strict |
38 // Seccomp-BPF policy. | 32 // Seccomp-BPF policy. |
39 LinuxSandbox::InitializeSandbox(); | 33 LinuxSandbox::InitializeSandbox(); |
40 #endif | 34 #endif |
41 | 35 |
42 #if defined(OS_POSIX) | |
43 // The utility process is used to load plugins (see OnLoadPlugins() in | |
44 // utility_thread_impl.cc). Some plugins expect the browser to have loaded | |
45 // GLib/GTK. | |
46 // Due to bugs in GLib we need to initialize GLib/GTK before we start threads, | |
47 // see crbug.com/309093. | |
48 | |
49 #if defined(TOOLKIT_GTK) | |
50 bool is_sandboxed = false; | |
51 | |
52 #if defined(OS_LINUX) | |
53 // On Linux, we only initialize GLib/GTK if we're not sandboxed. | |
54 is_sandboxed = !parameters.command_line.HasSwitch(switches::kNoSandbox); | |
55 #endif | |
56 | |
57 if (!is_sandboxed) { | |
58 // g_thread_init() is deprecated since glib 2.31.0, please see release note: | |
59 // http://mail.gnome.org/archives/gnome-announce-list/2011-October/msg00041.
html | |
60 #if !(GLIB_CHECK_VERSION(2, 31, 0)) | |
61 if (!g_thread_get_initialized()) { | |
62 g_thread_init(NULL); | |
63 } | |
64 #endif | |
65 gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); | |
66 } | |
67 #endif | |
68 #endif | |
69 | |
70 ChildProcess utility_process; | 36 ChildProcess utility_process; |
71 utility_process.set_main_thread(new UtilityThreadImpl()); | 37 utility_process.set_main_thread(new UtilityThreadImpl()); |
72 | 38 |
73 base::HighResolutionTimerManager hi_res_timer_manager; | 39 base::HighResolutionTimerManager hi_res_timer_manager; |
74 | 40 |
75 #if defined(OS_WIN) | 41 #if defined(OS_WIN) |
76 bool no_sandbox = parameters.command_line.HasSwitch(switches::kNoSandbox); | 42 bool no_sandbox = parameters.command_line.HasSwitch(switches::kNoSandbox); |
77 if (!no_sandbox) { | 43 if (!no_sandbox) { |
78 sandbox::TargetServices* target_services = | 44 sandbox::TargetServices* target_services = |
79 parameters.sandbox_info->target_services; | 45 parameters.sandbox_info->target_services; |
80 if (!target_services) | 46 if (!target_services) |
81 return false; | 47 return false; |
82 target_services->LowerToken(); | 48 target_services->LowerToken(); |
83 } | 49 } |
84 #endif | 50 #endif |
85 | 51 |
86 base::MessageLoop::current()->Run(); | 52 base::MessageLoop::current()->Run(); |
87 | 53 |
88 #if defined(LEAK_SANITIZER) | 54 #if defined(LEAK_SANITIZER) |
89 // Invoke LeakSanitizer before shutting down the utility thread, to avoid | 55 // Invoke LeakSanitizer before shutting down the utility thread, to avoid |
90 // reporting shutdown-only leaks. | 56 // reporting shutdown-only leaks. |
91 __lsan_do_leak_check(); | 57 __lsan_do_leak_check(); |
92 #endif | 58 #endif |
93 | 59 |
94 return 0; | 60 return 0; |
95 } | 61 } |
96 | 62 |
97 } // namespace content | 63 } // namespace content |
OLD | NEW |