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

Side by Side Diff: chrome/gpu/gpu_main.cc

Issue 5491001: Mac: Sandbox GPU process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make tests work for now Created 10 years 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <stdlib.h> 5 #include <stdlib.h>
6 6
7 #include "app/app_switches.h" 7 #include "app/app_switches.h"
8 #include "app/gfx/gl/gl_context.h" 8 #include "app/gfx/gl/gl_context.h"
9 #include "app/gfx/gl/gl_implementation.h" 9 #include "app/gfx/gl/gl_implementation.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/metrics/field_trial.h" 12 #include "base/metrics/field_trial.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "chrome/common/chrome_constants.h" 15 #include "chrome/common/chrome_constants.h"
16 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/env_vars.h" 17 #include "chrome/common/env_vars.h"
18 #include "chrome/common/main_function_params.h" 18 #include "chrome/common/main_function_params.h"
19 #include "chrome/gpu/gpu_config.h" 19 #include "chrome/gpu/gpu_config.h"
20 #include "chrome/gpu/gpu_process.h" 20 #include "chrome/gpu/gpu_process.h"
21 #include "chrome/gpu/gpu_thread.h" 21 #include "chrome/gpu/gpu_thread.h"
22 #include "chrome/gpu/gpu_watchdog_thread.h" 22 #include "chrome/gpu/gpu_watchdog_thread.h"
23 23
24 #if defined(USE_LINUX_BREAKPAD) 24 #if defined(USE_LINUX_BREAKPAD)
25 #include "chrome/app/breakpad_linux.h" 25 #include "chrome/app/breakpad_linux.h"
26 #endif 26 #endif
27 27
28 #if defined(OS_MACOSX)
29 #include "chrome/common/sandbox_mac.h"
30 #endif
31
28 #if defined(OS_WIN) 32 #if defined(OS_WIN)
29 #include "app/win_util.h" 33 #include "app/win_util.h"
30 #endif 34 #endif
31 35
32 #if defined(USE_X11) 36 #if defined(USE_X11)
33 #include "gfx/gtk_util.h" 37 #include "gfx/gtk_util.h"
34 #endif 38 #endif
35 39
36 namespace {
37
38 // 1% per watchdog trial group. 40 // 1% per watchdog trial group.
39 const int kFieldTrialSize = 1; 41 const int kFieldTrialSize = 1;
40 42
41 // 5 - 20 seconds timeout. 43 // 5 - 20 seconds timeout.
42 const int kMinGpuTimeout = 5; 44 const int kMinGpuTimeout = 5;
43 const int kMaxGpuTimeout = 20; 45 const int kMaxGpuTimeout = 20;
44 46
47 namespace {
48
49 bool InitializeGpuSandbox() {
50 #if defined(OS_MACOSX)
51 CommandLine* parsed_command_line = CommandLine::ForCurrentProcess();
52 SandboxInitWrapper sandbox_wrapper;
53 return sandbox_wrapper.InitializeSandbox(*parsed_command_line,
jeremy 2010/12/02 08:33:56 Does this call Warmup first?
54 switches::kGpuProcess);
55 #else
56 // TODO(port): Create GPU sandbox for linux and windows.
57 return true;
58 #endif
59 }
60
45 } // namespace 61 } // namespace
46 62
47 // Main function for starting the Gpu process. 63 // Main function for starting the Gpu process.
48 int GpuMain(const MainFunctionParams& parameters) { 64 int GpuMain(const MainFunctionParams& parameters) {
49 base::Time start_time = base::Time::Now(); 65 base::Time start_time = base::Time::Now();
50 66
51 #if defined(USE_LINUX_BREAKPAD) 67 #if defined(USE_LINUX_BREAKPAD)
52 // Needs to be called after we have chrome::DIR_USER_DATA. 68 // Needs to be called after we have chrome::DIR_USER_DATA.
53 InitCrashReporter(); 69 InitCrashReporter();
54 #endif 70 #endif
(...skipping 20 matching lines...) Expand all
75 #if defined(USE_X11) 91 #if defined(USE_X11)
76 // The X11 port of the command buffer code assumes it can access the X 92 // The X11 port of the command buffer code assumes it can access the X
77 // display via the macro GDK_DISPLAY(), which implies that Gtk has been 93 // display via the macro GDK_DISPLAY(), which implies that Gtk has been
78 // initialized. This code was taken from PluginThread. TODO(kbr): 94 // initialized. This code was taken from PluginThread. TODO(kbr):
79 // rethink whether initializing Gtk is really necessary or whether we 95 // rethink whether initializing Gtk is really necessary or whether we
80 // should just send a raw display connection down to the GPUProcessor. 96 // should just send a raw display connection down to the GPUProcessor.
81 g_thread_init(NULL); 97 g_thread_init(NULL);
82 gfx::GtkInitFromCommandLine(command_line); 98 gfx::GtkInitFromCommandLine(command_line);
83 #endif 99 #endif
84 100
101 // Note that kNoSandbox will also disable the GPU sandbox.
102 bool no_gpu_sandbox = command_line.HasSwitch(switches::kNoGpuSandbox);
103 if (!no_gpu_sandbox) {
104 if (!InitializeGpuSandbox()) {
105 LOG(ERROR) << "Failed to initialize the GPU sandbox";
106 return EXIT_FAILURE;
107 }
108 } else {
109 LOG(ERROR) << "Running without GPU sandbox";
110 }
111
85 // Load the GL implementation and locate the bindings before starting the GPU 112 // Load the GL implementation and locate the bindings before starting the GPU
86 // watchdog because this can take a lot of time and the GPU watchdog might 113 // watchdog because this can take a lot of time and the GPU watchdog might
87 // terminate the GPU process. 114 // terminate the GPU process.
88 if (!gfx::GLContext::InitializeOneOff()) 115 if (!gfx::GLContext::InitializeOneOff())
89 return EXIT_FAILURE; 116 return EXIT_FAILURE;
90 117
91 // Do this soon before running the message loop so accurate 118 // Do this soon before running the message loop so accurate
92 // initialization time is recorded in the GPU info. Don't do it before 119 // initialization time is recorded in the GPU info. Don't do it before
93 // starting the watchdog thread since it can take a significant amount of 120 // starting the watchdog thread since it can take a significant amount of
94 // time to collect GPU information in GpuThread::Init. 121 // time to collect GPU information in GpuThread::Init.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 watchdog_thread->Start(); 162 watchdog_thread->Start();
136 } 163 }
137 164
138 main_message_loop.Run(); 165 main_message_loop.Run();
139 166
140 if (enable_watchdog) 167 if (enable_watchdog)
141 watchdog_thread->Stop(); 168 watchdog_thread->Stop();
142 169
143 return 0; 170 return 0;
144 } 171 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698