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

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: Created 7 years, 2 months 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 | « no previous file | 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
34 #if defined(OS_POSIX)
35 // The utility process is used to load plugins (see OnLoadPlugins() in
36 // utility_thread_impl.cc). Some plugins expect the browser to have loaded
37 // GLib/GTK.
38 // Due to bugs in GLib we need to initialize GLib/GTK before we start threads,
39 // see crbug.com/309093.
40
41 bool do_init_gtk = false;
42
28 #if defined(OS_LINUX) 43 #if defined(OS_LINUX)
29 // Initialize the sandbox before any thread is created. 44 // On Linux, we only initialize GLib/GTK if we're not sandboxed.
jln (very slow on Chromium) 2013/10/22 01:23:55 This is super weird-looking. The utility process r
Jorge Lucangeli Obes 2013/10/22 16:14:54 Well, we do know our cmdline flags, and we use --n
jln (very slow on Chromium) 2013/10/22 16:42:40 It's error prone though. You could have a DCHECK t
Jorge Lucangeli Obes 2013/10/22 17:56:14 Done.
30 LinuxSandbox::InitializeSandbox(); 45 LinuxSandbox::GetInstance()->PreinitializeSandbox();
46 const int sandbox_status = LinuxSandbox::GetInstance()->GetStatus();
47 do_init_gtk = !(sandbox_status & kSandboxLinuxSUID);
48 #endif
49
50 #if defined(TOOLKIT_GTK)
51 if (do_init_gtk) {
52 // g_thread_init() is deprecated since glib 2.31.0, please see release note:
53 // http://mail.gnome.org/archives/gnome-announce-list/2011-October/msg00041. html
54 #if !(GLIB_CHECK_VERSION(2, 31, 0))
55 if (!g_thread_get_initialized()) {
56 g_thread_init(NULL);
57 }
58 #endif
59 gfx::GtkInitFromCommandLine(*CommandLine::ForCurrentProcess());
60 }
61 #endif
62 #endif
63
64 #if defined(OS_LINUX)
65 // If we didn't initialize GLib/GTK, initialize the sandbox.
66 if (!do_init_gtk) {
67 LinuxSandbox::InitializeSandbox();
jln (very slow on Chromium) 2013/10/22 01:23:55 This is ugly. You should create a "const bool is_s
Jorge Lucangeli Obes 2013/10/22 16:14:54 GTK starts threads, so we actually do need to know
jln (very slow on Chromium) 2013/10/22 16:42:40 I realize, but again, there should be some "logic"
Jorge Lucangeli Obes 2013/10/22 16:58:43 I'm worried that we'll change the BPF policy and t
68 }
31 #endif 69 #endif
32 70
33 ChildProcess utility_process; 71 ChildProcess utility_process;
34 utility_process.set_main_thread(new UtilityThreadImpl()); 72 utility_process.set_main_thread(new UtilityThreadImpl());
35 73
36 base::HighResolutionTimerManager hi_res_timer_manager; 74 base::HighResolutionTimerManager hi_res_timer_manager;
37 75
38 #if defined(OS_WIN) 76 #if defined(OS_WIN)
39 bool no_sandbox = parameters.command_line.HasSwitch(switches::kNoSandbox); 77 bool no_sandbox = parameters.command_line.HasSwitch(switches::kNoSandbox);
40 if (!no_sandbox) { 78 if (!no_sandbox) {
41 sandbox::TargetServices* target_services = 79 sandbox::TargetServices* target_services =
42 parameters.sandbox_info->target_services; 80 parameters.sandbox_info->target_services;
43 if (!target_services) 81 if (!target_services)
44 return false; 82 return false;
45 target_services->LowerToken(); 83 target_services->LowerToken();
46 } 84 }
47 #endif 85 #endif
48 86
49 base::MessageLoop::current()->Run(); 87 base::MessageLoop::current()->Run();
50 88
51 return 0; 89 return 0;
52 } 90 }
53 91
54 } // namespace content 92 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/utility/utility_thread_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698