OLD | NEW |
---|---|
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 "chrome/browser/gpu_process_host.h" | 5 #include "chrome/browser/gpu_process_host.h" |
6 | 6 |
7 #include "app/app_switches.h" | 7 #include "app/app_switches.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/thread.h" | 9 #include "base/thread.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/browser_thread.h" | 11 #include "chrome/browser/browser_thread.h" |
12 #include "chrome/browser/gpu_process_host_ui_shim.h" | 12 #include "chrome/browser/gpu_process_host_ui_shim.h" |
13 #include "chrome/browser/renderer_host/render_view_host.h" | 13 #include "chrome/browser/renderer_host/render_view_host.h" |
14 #include "chrome/browser/renderer_host/render_widget_host_view.h" | 14 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
15 #include "chrome/browser/renderer_host/resource_message_filter.h" | 15 #include "chrome/browser/renderer_host/resource_message_filter.h" |
16 #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" | |
16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/gpu_info.h" | 18 #include "chrome/common/gpu_info.h" |
18 #include "chrome/common/gpu_messages.h" | 19 #include "chrome/common/gpu_messages.h" |
19 #include "chrome/common/render_messages.h" | 20 #include "chrome/common/render_messages.h" |
20 #include "ipc/ipc_channel_handle.h" | 21 #include "ipc/ipc_channel_handle.h" |
21 #include "ipc/ipc_switches.h" | 22 #include "ipc/ipc_switches.h" |
22 #include "media/base/media_switches.h" | 23 #include "media/base/media_switches.h" |
23 | 24 |
24 #if defined(OS_LINUX) | 25 #if defined(OS_LINUX) |
25 #include "app/x11_util.h" | 26 #include "app/x11_util.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
41 IPC::Message msg_; | 42 IPC::Message msg_; |
42 }; | 43 }; |
43 | 44 |
44 // Global GpuProcessHost instance. | 45 // Global GpuProcessHost instance. |
45 // We can not use Singleton<GpuProcessHost> because that gets | 46 // We can not use Singleton<GpuProcessHost> because that gets |
46 // terminated on the wrong thread (main thread). We need the | 47 // terminated on the wrong thread (main thread). We need the |
47 // GpuProcessHost to be terminated on the same thread on which it is | 48 // GpuProcessHost to be terminated on the same thread on which it is |
48 // initialized, the IO thread. | 49 // initialized, the IO thread. |
49 static GpuProcessHost* sole_instance_ = NULL; | 50 static GpuProcessHost* sole_instance_ = NULL; |
50 | 51 |
52 // Number of times the gpu process has crashed in the current browser session. | |
53 static int g_gpu_crash_count = 0; | |
54 // Maximaum number of times the gpu process is allowed to crash in a session. | |
apatrick_chromium
2010/11/29 20:59:31
typo: Maximum
| |
55 // Once this limit is reached, any request to launch the gpu process will fail. | |
56 static const int kGpuMaxCrashCount = 3; | |
57 | |
51 void RouteOnUIThread(const IPC::Message& message) { | 58 void RouteOnUIThread(const IPC::Message& message) { |
52 BrowserThread::PostTask(BrowserThread::UI, | 59 BrowserThread::PostTask(BrowserThread::UI, |
53 FROM_HERE, | 60 FROM_HERE, |
54 new RouteOnUIThreadTask(message)); | 61 new RouteOnUIThreadTask(message)); |
55 } | 62 } |
56 } // anonymous namespace | 63 } // anonymous namespace |
57 | 64 |
58 GpuProcessHost::GpuProcessHost() | 65 GpuProcessHost::GpuProcessHost() |
59 : BrowserChildProcessHost(GPU_PROCESS, NULL), | 66 : BrowserChildProcessHost(GPU_PROCESS, NULL), |
60 initialized_(false), | 67 initialized_(false), |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 uint32 request_id, | 344 uint32 request_id, |
338 const ViewHostMsg_Resource_Request& request_data) { | 345 const ViewHostMsg_Resource_Request& request_data) { |
339 return NULL; | 346 return NULL; |
340 } | 347 } |
341 | 348 |
342 bool GpuProcessHost::CanShutdown() { | 349 bool GpuProcessHost::CanShutdown() { |
343 return true; | 350 return true; |
344 } | 351 } |
345 | 352 |
346 void GpuProcessHost::OnProcessCrashed() { | 353 void GpuProcessHost::OnProcessCrashed() { |
347 // TODO(alokp): Update gpu process crash rate. | 354 if (++g_gpu_crash_count >= kGpuMaxCrashCount) { |
355 // The gpu process is too unstable to use. Disable it for current session. | |
356 RenderViewHostDelegateHelper::set_gpu_enabled(false); | |
357 } | |
348 BrowserChildProcessHost::OnProcessCrashed(); | 358 BrowserChildProcessHost::OnProcessCrashed(); |
349 } | 359 } |
350 | 360 |
351 bool GpuProcessHost::CanLaunchGpuProcess() const { | 361 bool GpuProcessHost::CanLaunchGpuProcess() const { |
352 // TODO(alokp): Answer based on crash rate. | 362 return RenderViewHostDelegateHelper::gpu_enabled(); |
353 return true; | |
354 } | 363 } |
355 | 364 |
356 bool GpuProcessHost::LaunchGpuProcess() { | 365 bool GpuProcessHost::LaunchGpuProcess() { |
apatrick
2010/11/29 17:45:38
Does making this function return false when g_gpu_
alokp
2010/11/29 18:34:38
yes it works and I do that too via CanLaunchGpuPro
| |
357 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 366 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
358 CommandLine::StringType gpu_launcher = | 367 CommandLine::StringType gpu_launcher = |
359 browser_command_line.GetSwitchValueNative(switches::kGpuLauncher); | 368 browser_command_line.GetSwitchValueNative(switches::kGpuLauncher); |
360 | 369 |
361 FilePath exe_path = ChildProcessHost::GetChildPath(gpu_launcher.empty()); | 370 FilePath exe_path = ChildProcessHost::GetChildPath(gpu_launcher.empty()); |
362 if (exe_path.empty()) | 371 if (exe_path.empty()) |
363 return false; | 372 return false; |
364 | 373 |
365 CommandLine* cmd_line = new CommandLine(exe_path); | 374 CommandLine* cmd_line = new CommandLine(exe_path); |
366 cmd_line->AppendSwitchASCII(switches::kProcessType, switches::kGpuProcess); | 375 cmd_line->AppendSwitchASCII(switches::kProcessType, switches::kGpuProcess); |
(...skipping 22 matching lines...) Expand all Loading... | |
389 FilePath(), | 398 FilePath(), |
390 #elif defined(OS_POSIX) | 399 #elif defined(OS_POSIX) |
391 false, // Never use the zygote (GPU plugin can't be sandboxed). | 400 false, // Never use the zygote (GPU plugin can't be sandboxed). |
392 base::environment_vector(), | 401 base::environment_vector(), |
393 #endif | 402 #endif |
394 cmd_line); | 403 cmd_line); |
395 | 404 |
396 return true; | 405 return true; |
397 } | 406 } |
398 | 407 |
OLD | NEW |