| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/hung_plugin_tab_helper.h" | 5 #include "chrome/browser/ui/hung_plugin_tab_helper.h" |
| 6 | 6 |
| 7 #include <memory> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/process/process.h" | 12 #include "base/process/process.h" |
| 12 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/infobars/infobar_service.h" | 16 #include "chrome/browser/infobars/infobar_service.h" |
| 16 #include "chrome/common/channel_info.h" | 17 #include "chrome/common/channel_info.h" |
| 17 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
| 18 #include "chrome/grit/locale_settings.h" | 19 #include "chrome/grit/locale_settings.h" |
| 19 #include "components/infobars/core/confirm_infobar_delegate.h" | 20 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 20 #include "components/infobars/core/infobar.h" | 21 #include "components/infobars/core/infobar.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 base::string16 button_text_; | 162 base::string16 button_text_; |
| 162 }; | 163 }; |
| 163 | 164 |
| 164 // static | 165 // static |
| 165 infobars::InfoBar* HungPluginInfoBarDelegate::Create( | 166 infobars::InfoBar* HungPluginInfoBarDelegate::Create( |
| 166 InfoBarService* infobar_service, | 167 InfoBarService* infobar_service, |
| 167 HungPluginTabHelper* helper, | 168 HungPluginTabHelper* helper, |
| 168 int plugin_child_id, | 169 int plugin_child_id, |
| 169 const base::string16& plugin_name) { | 170 const base::string16& plugin_name) { |
| 170 return infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( | 171 return infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( |
| 171 scoped_ptr<ConfirmInfoBarDelegate>(new HungPluginInfoBarDelegate( | 172 std::unique_ptr<ConfirmInfoBarDelegate>(new HungPluginInfoBarDelegate( |
| 172 helper, plugin_child_id, plugin_name)))); | 173 helper, plugin_child_id, plugin_name)))); |
| 173 } | 174 } |
| 174 | 175 |
| 175 HungPluginInfoBarDelegate::HungPluginInfoBarDelegate( | 176 HungPluginInfoBarDelegate::HungPluginInfoBarDelegate( |
| 176 HungPluginTabHelper* helper, | 177 HungPluginTabHelper* helper, |
| 177 int plugin_child_id, | 178 int plugin_child_id, |
| 178 const base::string16& plugin_name) | 179 const base::string16& plugin_name) |
| 179 : ConfirmInfoBarDelegate(), | 180 : ConfirmInfoBarDelegate(), |
| 180 helper_(helper), | 181 helper_(helper), |
| 181 plugin_child_id_(plugin_child_id), | 182 plugin_child_id_(plugin_child_id), |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 } | 359 } |
| 359 | 360 |
| 360 void HungPluginTabHelper::KillPlugin(int child_id) { | 361 void HungPluginTabHelper::KillPlugin(int child_id) { |
| 361 #if defined(OS_WIN) | 362 #if defined(OS_WIN) |
| 362 // Dump renderers that are sending or receiving pepper messages, in order to | 363 // Dump renderers that are sending or receiving pepper messages, in order to |
| 363 // diagnose inter-process deadlocks. | 364 // diagnose inter-process deadlocks. |
| 364 // Only do that on the Canary channel, for 20% of pepper plugin hangs. | 365 // Only do that on the Canary channel, for 20% of pepper plugin hangs. |
| 365 if (base::RandInt(0, 100) < 20) { | 366 if (base::RandInt(0, 100) < 20) { |
| 366 version_info::Channel channel = chrome::GetChannel(); | 367 version_info::Channel channel = chrome::GetChannel(); |
| 367 if (channel == version_info::Channel::CANARY) { | 368 if (channel == version_info::Channel::CANARY) { |
| 368 scoped_ptr<OwnedHandleVector> renderer_handles(new OwnedHandleVector); | 369 std::unique_ptr<OwnedHandleVector> renderer_handles( |
| 370 new OwnedHandleVector); |
| 369 HANDLE current_process = ::GetCurrentProcess(); | 371 HANDLE current_process = ::GetCurrentProcess(); |
| 370 content::RenderProcessHost::iterator renderer_iter = | 372 content::RenderProcessHost::iterator renderer_iter = |
| 371 content::RenderProcessHost::AllHostsIterator(); | 373 content::RenderProcessHost::AllHostsIterator(); |
| 372 for (; !renderer_iter.IsAtEnd(); renderer_iter.Advance()) { | 374 for (; !renderer_iter.IsAtEnd(); renderer_iter.Advance()) { |
| 373 content::RenderProcessHost* host = renderer_iter.GetCurrentValue(); | 375 content::RenderProcessHost* host = renderer_iter.GetCurrentValue(); |
| 374 HANDLE handle = NULL; | 376 HANDLE handle = NULL; |
| 375 ::DuplicateHandle(current_process, host->GetHandle(), current_process, | 377 ::DuplicateHandle(current_process, host->GetHandle(), current_process, |
| 376 &handle, 0, FALSE, DUPLICATE_SAME_ACCESS); | 378 &handle, 0, FALSE, DUPLICATE_SAME_ACCESS); |
| 377 renderer_handles->data()->push_back(handle); | 379 renderer_handles->data()->push_back(handle); |
| 378 } | 380 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 } | 426 } |
| 425 | 427 |
| 426 void HungPluginTabHelper::CloseBar(PluginState* state) { | 428 void HungPluginTabHelper::CloseBar(PluginState* state) { |
| 427 InfoBarService* infobar_service = | 429 InfoBarService* infobar_service = |
| 428 InfoBarService::FromWebContents(web_contents()); | 430 InfoBarService::FromWebContents(web_contents()); |
| 429 if (infobar_service && state->infobar) { | 431 if (infobar_service && state->infobar) { |
| 430 infobar_service->RemoveInfoBar(state->infobar); | 432 infobar_service->RemoveInfoBar(state->infobar); |
| 431 state->infobar = NULL; | 433 state->infobar = NULL; |
| 432 } | 434 } |
| 433 } | 435 } |
| OLD | NEW |