[email protected] | 623c0bd | 2011-03-12 01:00:41 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 5 | #include <stdlib.h> |
6 | |||||
[email protected] | cafd0b6 | 2011-01-19 01:22:05 | [diff] [blame] | 7 | #if defined(OS_WIN) |
8 | #include <windows.h> | ||||
9 | #endif | ||||
10 | |||||
[email protected] | fd85ad6 | 2010-12-31 20:39:02 | [diff] [blame] | 11 | #include "app/win/scoped_com_initializer.h" |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 12 | #include "base/environment.h" |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 13 | #include "base/message_loop.h" |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 14 | #include "base/stringprintf.h" |
[email protected] | ce072a7 | 2010-12-31 20:02:16 | [diff] [blame] | 15 | #include "base/threading/platform_thread.h" |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 16 | #include "build/build_config.h" |
[email protected] | 6b7a5e3 | 2011-03-11 18:34:10 | [diff] [blame] | 17 | #include "content/common/content_switches.h" |
[email protected] | f24a1e2b | 2011-04-08 01:48:48 | [diff] [blame^] | 18 | #include "content/common/gpu/gpu_config.h" |
[email protected] | 415c2cd | 2011-03-11 21:56:11 | [diff] [blame] | 19 | #include "content/common/main_function_params.h" |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 20 | #include "content/gpu/gpu_child_thread.h" |
[email protected] | 623c0bd | 2011-03-12 01:00:41 | [diff] [blame] | 21 | #include "content/gpu/gpu_process.h" |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 22 | |
[email protected] | 802a13a0 | 2010-12-02 01:48:37 | [diff] [blame] | 23 | #if defined(OS_MACOSX) |
[email protected] | 415c2cd | 2011-03-11 21:56:11 | [diff] [blame] | 24 | #include "content/common/chrome_application_mac.h" |
[email protected] | 802a13a0 | 2010-12-02 01:48:37 | [diff] [blame] | 25 | #endif |
26 | |||||
[email protected] | 02ec37a | 2010-09-20 22:32:16 | [diff] [blame] | 27 | #if defined(USE_X11) |
[email protected] | 57b5d7dc | 2011-03-09 14:11:34 | [diff] [blame] | 28 | #include "ui/base/x/x11_util.h" |
[email protected] | 02ec37a | 2010-09-20 22:32:16 | [diff] [blame] | 29 | #endif |
30 | |||||
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 31 | // Main function for starting the Gpu process. |
32 | int GpuMain(const MainFunctionParams& parameters) { | ||||
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 33 | base::Time start_time = base::Time::Now(); |
34 | |||||
[email protected] | 6b889fb | 2010-03-23 20:09:49 | [diff] [blame] | 35 | const CommandLine& command_line = parameters.command_line_; |
36 | if (command_line.HasSwitch(switches::kGpuStartupDialog)) { | ||||
[email protected] | 75fcc27 | 2011-03-08 20:50:48 | [diff] [blame] | 37 | ChildProcess::WaitForDebugger("Gpu"); |
[email protected] | 6b889fb | 2010-03-23 20:09:49 | [diff] [blame] | 38 | } |
39 | |||||
[email protected] | de9e0b5 | 2010-12-23 22:01:17 | [diff] [blame] | 40 | #if defined(OS_MACOSX) |
41 | chrome_application_mac::RegisterCrApp(); | ||||
42 | #endif | ||||
43 | |||||
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 44 | MessageLoop main_message_loop(MessageLoop::TYPE_UI); |
[email protected] | ce072a7 | 2010-12-31 20:02:16 | [diff] [blame] | 45 | base::PlatformThread::SetName("CrGpuMain"); |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 46 | |
[email protected] | 57b5d7dc | 2011-03-09 14:11:34 | [diff] [blame] | 47 | if (!command_line.HasSwitch(switches::kSingleProcess)) { |
[email protected] | cafd0b6 | 2011-01-19 01:22:05 | [diff] [blame] | 48 | #if defined(OS_WIN) |
[email protected] | 57b5d7dc | 2011-03-09 14:11:34 | [diff] [blame] | 49 | // Prevent Windows from displaying a modal dialog on failures like not being |
50 | // able to load a DLL. | ||||
51 | SetErrorMode( | ||||
52 | SEM_FAILCRITICALERRORS | | ||||
53 | SEM_NOGPFAULTERRORBOX | | ||||
54 | SEM_NOOPENFILEERRORBOX); | ||||
55 | #elif defined(USE_X11) | ||||
56 | ui::SetDefaultX11ErrorHandlers(); | ||||
[email protected] | cafd0b6 | 2011-01-19 01:22:05 | [diff] [blame] | 57 | #endif |
[email protected] | 57b5d7dc | 2011-03-09 14:11:34 | [diff] [blame] | 58 | } |
[email protected] | cafd0b6 | 2011-01-19 01:22:05 | [diff] [blame] | 59 | |
[email protected] | fd85ad6 | 2010-12-31 20:39:02 | [diff] [blame] | 60 | app::win::ScopedCOMInitializer com_initializer; |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 61 | |
[email protected] | 7709e71 | 2011-01-07 17:57:31 | [diff] [blame] | 62 | // We can not tolerate early returns from this code, because the |
63 | // detection of early return of a child process is implemented using | ||||
64 | // an IPC channel error. If the IPC channel is not fully set up | ||||
65 | // between the browser and GPU process, and the GPU process crashes | ||||
66 | // or exits early, the browser process will never detect it. For | ||||
67 | // this reason we defer all work related to the GPU until receiving | ||||
68 | // the GpuMsg_Initialize message from the browser. | ||||
[email protected] | 983c33d | 2010-11-16 22:38:44 | [diff] [blame] | 69 | GpuProcess gpu_process; |
[email protected] | 8fe0ec52 | 2011-03-03 00:31:33 | [diff] [blame] | 70 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 71 | GpuChildThread* child_thread = |
[email protected] | 8fe0ec52 | 2011-03-03 00:31:33 | [diff] [blame] | 72 | #if defined(OS_WIN) |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 73 | new GpuChildThread(parameters.sandbox_info_.TargetServices()); |
[email protected] | 8fe0ec52 | 2011-03-03 00:31:33 | [diff] [blame] | 74 | #else |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 75 | new GpuChildThread; |
[email protected] | 8fe0ec52 | 2011-03-03 00:31:33 | [diff] [blame] | 76 | #endif |
77 | |||||
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 78 | child_thread->Init(start_time); |
[email protected] | 995a7f1 | 2011-02-11 23:07:17 | [diff] [blame] | 79 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 80 | gpu_process.set_main_thread(child_thread); |
[email protected] | 983c33d | 2010-11-16 22:38:44 | [diff] [blame] | 81 | |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 82 | main_message_loop.Run(); |
83 | |||||
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 84 | child_thread->StopWatchdog(); |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 85 | |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 86 | return 0; |
87 | } |