| 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 "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 queued_synchronization_replies_.pop(); | 90 queued_synchronization_replies_.pop(); |
| 91 } | 91 } |
| 92 DCHECK_EQ(sole_instance_, this); | 92 DCHECK_EQ(sole_instance_, this); |
| 93 sole_instance_ = NULL; | 93 sole_instance_ = NULL; |
| 94 } | 94 } |
| 95 | 95 |
| 96 bool GpuProcessHost::EnsureInitialized() { | 96 bool GpuProcessHost::EnsureInitialized() { |
| 97 if (!initialized_) { | 97 if (!initialized_) { |
| 98 initialized_ = true; | 98 initialized_ = true; |
| 99 initialized_successfully_ = Init(); | 99 initialized_successfully_ = Init(); |
| 100 if (initialized_successfully_) { |
| 101 Send(new GpuMsg_Initialize()); |
| 102 } |
| 100 } | 103 } |
| 101 return initialized_successfully_; | 104 return initialized_successfully_; |
| 102 } | 105 } |
| 103 | 106 |
| 104 bool GpuProcessHost::Init() { | 107 bool GpuProcessHost::Init() { |
| 105 if (!LoadGpuBlacklist()) | 108 if (!LoadGpuBlacklist()) |
| 106 return false; | 109 return false; |
| 107 | 110 |
| 108 if (!CreateChannel()) | 111 if (!CreateChannel()) |
| 109 return false; | 112 return false; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 if (gpu_feature_flags.flags() != 0) { | 224 if (gpu_feature_flags.flags() != 0) { |
| 222 Send(new GpuMsg_CloseChannel(channel_handle)); | 225 Send(new GpuMsg_CloseChannel(channel_handle)); |
| 223 SendEstablishChannelReply(IPC::ChannelHandle(), gpu_info, request.filter); | 226 SendEstablishChannelReply(IPC::ChannelHandle(), gpu_info, request.filter); |
| 224 } else { | 227 } else { |
| 225 SendEstablishChannelReply(channel_handle, gpu_info, request.filter); | 228 SendEstablishChannelReply(channel_handle, gpu_info, request.filter); |
| 226 } | 229 } |
| 227 sent_requests_.pop(); | 230 sent_requests_.pop(); |
| 228 } | 231 } |
| 229 | 232 |
| 230 void GpuProcessHost::OnSynchronizeReply() { | 233 void GpuProcessHost::OnSynchronizeReply() { |
| 231 const SynchronizationRequest& request = | 234 // Guard against race conditions in abrupt GPU process termination. |
| 232 queued_synchronization_replies_.front(); | 235 if (queued_synchronization_replies_.size() > 0) { |
| 233 SendSynchronizationReply(request.reply, request.filter); | 236 const SynchronizationRequest& request = |
| 234 queued_synchronization_replies_.pop(); | 237 queued_synchronization_replies_.front(); |
| 238 SendSynchronizationReply(request.reply, request.filter); |
| 239 queued_synchronization_replies_.pop(); |
| 240 } |
| 235 } | 241 } |
| 236 | 242 |
| 237 #if defined(OS_LINUX) | 243 #if defined(OS_LINUX) |
| 238 | 244 |
| 239 namespace { | 245 namespace { |
| 240 | 246 |
| 241 void SendDelayedReply(IPC::Message* reply_msg) { | 247 void SendDelayedReply(IPC::Message* reply_msg) { |
| 242 GpuProcessHost::Get()->Send(reply_msg); | 248 GpuProcessHost::Get()->Send(reply_msg); |
| 243 } | 249 } |
| 244 | 250 |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 filter->Send(message); | 479 filter->Send(message); |
| 474 } | 480 } |
| 475 | 481 |
| 476 // Sends the response for synchronization request to the renderer. | 482 // Sends the response for synchronization request to the renderer. |
| 477 void GpuProcessHost::SendSynchronizationReply( | 483 void GpuProcessHost::SendSynchronizationReply( |
| 478 IPC::Message* reply, | 484 IPC::Message* reply, |
| 479 RenderMessageFilter* filter) { | 485 RenderMessageFilter* filter) { |
| 480 filter->Send(reply); | 486 filter->Send(reply); |
| 481 } | 487 } |
| 482 | 488 |
| 489 void GpuProcessHost::SendOutstandingReplies() { |
| 490 // First send empty channel handles for all EstablishChannel requests. |
| 491 while (!sent_requests_.empty()) { |
| 492 const ChannelRequest& request = sent_requests_.front(); |
| 493 SendEstablishChannelReply(IPC::ChannelHandle(), GPUInfo(), request.filter); |
| 494 sent_requests_.pop(); |
| 495 } |
| 496 |
| 497 // Now unblock all renderers waiting for synchronization replies. |
| 498 while (!queued_synchronization_replies_.empty()) { |
| 499 OnSynchronizeReply(); |
| 500 } |
| 501 } |
| 502 |
| 483 bool GpuProcessHost::CanShutdown() { | 503 bool GpuProcessHost::CanShutdown() { |
| 484 return true; | 504 return true; |
| 485 } | 505 } |
| 486 | 506 |
| 487 void GpuProcessHost::OnChildDied() { | 507 void GpuProcessHost::OnChildDied() { |
| 508 SendOutstandingReplies(); |
| 488 // Located in OnChildDied because OnProcessCrashed suffers from a race | 509 // Located in OnChildDied because OnProcessCrashed suffers from a race |
| 489 // condition on Linux. The GPU process will only die if it crashes. | 510 // condition on Linux. The GPU process will only die if it crashes. |
| 490 UMA_HISTOGRAM_ENUMERATION("GPU.GPUProcessLifetimeEvents", | 511 UMA_HISTOGRAM_ENUMERATION("GPU.GPUProcessLifetimeEvents", |
| 491 kCrashed, kGPUProcessLifetimeEvent_Max); | 512 kCrashed, kGPUProcessLifetimeEvent_Max); |
| 492 BrowserChildProcessHost::OnChildDied(); | 513 BrowserChildProcessHost::OnChildDied(); |
| 493 } | 514 } |
| 494 | 515 |
| 495 void GpuProcessHost::OnProcessCrashed(int exit_code) { | 516 void GpuProcessHost::OnProcessCrashed(int exit_code) { |
| 517 SendOutstandingReplies(); |
| 496 if (++g_gpu_crash_count >= kGpuMaxCrashCount) { | 518 if (++g_gpu_crash_count >= kGpuMaxCrashCount) { |
| 497 // The gpu process is too unstable to use. Disable it for current session. | 519 // The gpu process is too unstable to use. Disable it for current session. |
| 498 RenderViewHostDelegateHelper::set_gpu_enabled(false); | 520 RenderViewHostDelegateHelper::set_gpu_enabled(false); |
| 499 } | 521 } |
| 500 BrowserChildProcessHost::OnProcessCrashed(exit_code); | 522 BrowserChildProcessHost::OnProcessCrashed(exit_code); |
| 501 } | 523 } |
| 502 | 524 |
| 503 bool GpuProcessHost::CanLaunchGpuProcess() const { | 525 bool GpuProcessHost::CanLaunchGpuProcess() const { |
| 504 return RenderViewHostDelegateHelper::gpu_enabled(); | 526 return RenderViewHostDelegateHelper::gpu_enabled(); |
| 505 } | 527 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 586 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
| 565 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) || | 587 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) || |
| 566 blacklist->LoadGpuBlacklist(gpu_blacklist_json.as_string(), true)) { | 588 blacklist->LoadGpuBlacklist(gpu_blacklist_json.as_string(), true)) { |
| 567 gpu_blacklist_.reset(blacklist); | 589 gpu_blacklist_.reset(blacklist); |
| 568 return true; | 590 return true; |
| 569 } | 591 } |
| 570 delete blacklist; | 592 delete blacklist; |
| 571 return false; | 593 return false; |
| 572 } | 594 } |
| 573 | 595 |
| OLD | NEW |