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
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "base/message_loop/message_loop.h"
7 #include "base/threading/platform_thread.h"
8 #include "base/timer/hi_res_timer_manager.h"
9 #include "content/child/child_process.h"
10 #include "content/common/sandbox_linux.h"
11 #include "content/public/common/content_switches.h"
12 #include "content/public/common/main_function_params.h"
13 #include "content/public/common/sandbox_init.h"
14 #include "content/utility/utility_thread_impl.h"
17 #include "sandbox/win/src/sandbox.h"
20 #if defined(TOOLKIT_GTK)
23 #include "ui/gfx/gtk_util.h"
28 // Mainline routine for running as the utility process.
29 int UtilityMain(const MainFunctionParams
& parameters
) {
30 // The main message loop of the utility process.
31 base::MessageLoop main_message_loop
;
32 base::PlatformThread::SetName("CrUtilityMain");
35 // Initializes the sandbox before any threads are created.
36 // TODO(jorgelo): move this after GTK initialization when we enable a strict
37 // Seccomp-BPF policy.
38 LinuxSandbox::InitializeSandbox();
42 // The utility process is used to load plugins (see OnLoadPlugins() in
43 // utility_thread_impl.cc). Some plugins expect the browser to have loaded
45 // Due to bugs in GLib we need to initialize GLib/GTK before we start threads,
46 // see crbug.com/309093.
48 #if defined(TOOLKIT_GTK)
49 bool is_sandboxed
= false;
52 // On Linux, we only initialize GLib/GTK if we're not sandboxed.
53 is_sandboxed
= !parameters
.command_line
.HasSwitch(switches::kNoSandbox
);
57 // g_thread_init() is deprecated since glib 2.31.0, please see release note:
58 // http://mail.gnome.org/archives/gnome-announce-list/2011-October/msg00041.html
59 #if !(GLIB_CHECK_VERSION(2, 31, 0))
60 if (!g_thread_get_initialized()) {
64 gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess());
69 ChildProcess utility_process
;
70 utility_process
.set_main_thread(new UtilityThreadImpl());
72 base::HighResolutionTimerManager hi_res_timer_manager
;
75 bool no_sandbox
= parameters
.command_line
.HasSwitch(switches::kNoSandbox
);
77 sandbox::TargetServices
* target_services
=
78 parameters
.sandbox_info
->target_services
;
81 target_services
->LowerToken();
85 base::MessageLoop::current()->Run();
90 } // namespace content