Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: content/utility/utility_main.cc

Issue 34123003: Utility process: initialize GTK when the sandbox is disabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix non-GTK compile. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/common/sandbox_seccomp_bpf_linux.cc ('k') | content/utility/utility_thread_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/threading/platform_thread.h" 7 #include "base/threading/platform_thread.h"
8 #include "base/timer/hi_res_timer_manager.h" 8 #include "base/timer/hi_res_timer_manager.h"
9 #include "content/child/child_process.h" 9 #include "content/child/child_process.h"
10 #include "content/common/sandbox_linux.h" 10 #include "content/common/sandbox_linux.h"
11 #include "content/public/common/content_switches.h" 11 #include "content/public/common/content_switches.h"
12 #include "content/public/common/main_function_params.h" 12 #include "content/public/common/main_function_params.h"
13 #include "content/public/common/sandbox_init.h" 13 #include "content/public/common/sandbox_init.h"
14 #include "content/utility/utility_thread_impl.h" 14 #include "content/utility/utility_thread_impl.h"
15 15
16 #if defined(OS_WIN) 16 #if defined(OS_WIN)
17 #include "sandbox/win/src/sandbox.h" 17 #include "sandbox/win/src/sandbox.h"
18 #endif 18 #endif
19 19
20 #if defined(TOOLKIT_GTK)
21 #include <gtk/gtk.h>
22
23 #include "ui/gfx/gtk_util.h"
24 #endif
25
20 namespace content { 26 namespace content {
21 27
22 // Mainline routine for running as the utility process. 28 // Mainline routine for running as the utility process.
23 int UtilityMain(const MainFunctionParams& parameters) { 29 int UtilityMain(const MainFunctionParams& parameters) {
24 // The main message loop of the utility process. 30 // The main message loop of the utility process.
25 base::MessageLoop main_message_loop; 31 base::MessageLoop main_message_loop;
26 base::PlatformThread::SetName("CrUtilityMain"); 32 base::PlatformThread::SetName("CrUtilityMain");
27 33
28 #if defined(OS_LINUX) 34 #if defined(OS_LINUX)
29 // Initialize the sandbox before any thread is created. 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.
30 LinuxSandbox::InitializeSandbox(); 38 LinuxSandbox::InitializeSandbox();
31 #endif 39 #endif
32 40
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.
47
48 #if defined(TOOLKIT_GTK)
49 bool is_sandboxed = false;
50
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
55
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);
62 }
63 #endif
64 gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess());
65 }
66 #endif
67 #endif
68
33 ChildProcess utility_process; 69 ChildProcess utility_process;
34 utility_process.set_main_thread(new UtilityThreadImpl()); 70 utility_process.set_main_thread(new UtilityThreadImpl());
35 71
36 base::HighResolutionTimerManager hi_res_timer_manager; 72 base::HighResolutionTimerManager hi_res_timer_manager;
37 73
38 #if defined(OS_WIN) 74 #if defined(OS_WIN)
39 bool no_sandbox = parameters.command_line.HasSwitch(switches::kNoSandbox); 75 bool no_sandbox = parameters.command_line.HasSwitch(switches::kNoSandbox);
40 if (!no_sandbox) { 76 if (!no_sandbox) {
41 sandbox::TargetServices* target_services = 77 sandbox::TargetServices* target_services =
42 parameters.sandbox_info->target_services; 78 parameters.sandbox_info->target_services;
43 if (!target_services) 79 if (!target_services)
44 return false; 80 return false;
45 target_services->LowerToken(); 81 target_services->LowerToken();
46 } 82 }
47 #endif 83 #endif
48 84
49 base::MessageLoop::current()->Run(); 85 base::MessageLoop::current()->Run();
50 86
51 return 0; 87 return 0;
52 } 88 }
53 89
54 } // namespace content 90 } // namespace content
OLDNEW
« no previous file with comments | « content/common/sandbox_seccomp_bpf_linux.cc ('k') | content/utility/utility_thread_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698