[Telemetry]: Add HTML5 Capabilities and Canvas tests to Peacekeeper benchmark suite.
[chromium-blink-merge.git] / content / utility / utility_main.cc
blob29fd01b2938c8670f721f01e6899963f25a3dcd5
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"
16 #if defined(OS_WIN)
17 #include "sandbox/win/src/sandbox.h"
18 #endif
20 #if defined(TOOLKIT_GTK)
21 #include <gtk/gtk.h>
23 #include "ui/gfx/gtk_util.h"
24 #endif
26 namespace content {
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");
34 #if defined(OS_LINUX)
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();
39 #endif
41 #if defined(OS_POSIX)
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
44 // GLib/GTK.
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;
51 #if defined(OS_LINUX)
52 // On Linux, we only initialize GLib/GTK if we're not sandboxed.
53 is_sandboxed = !parameters.command_line.HasSwitch(switches::kNoSandbox);
54 #endif
56 if (!is_sandboxed) {
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()) {
61 g_thread_init(NULL);
63 #endif
64 gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess());
66 #endif
67 #endif
69 ChildProcess utility_process;
70 utility_process.set_main_thread(new UtilityThreadImpl());
72 base::HighResolutionTimerManager hi_res_timer_manager;
74 #if defined(OS_WIN)
75 bool no_sandbox = parameters.command_line.HasSwitch(switches::kNoSandbox);
76 if (!no_sandbox) {
77 sandbox::TargetServices* target_services =
78 parameters.sandbox_info->target_services;
79 if (!target_services)
80 return false;
81 target_services->LowerToken();
83 #endif
85 base::MessageLoop::current()->Run();
87 return 0;
90 } // namespace content