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

Unified Diff: chrome/browser/ui/webui/hung_renderer_dialog.cc

Issue 8462015: Tests for WebUI Hung Renderer Dialog (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: missing virtual keyword on destructor (caught on mac try) Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/webui/hung_renderer_dialog.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/hung_renderer_dialog.cc
diff --git a/chrome/browser/ui/webui/hung_renderer_dialog.cc b/chrome/browser/ui/webui/hung_renderer_dialog.cc
index de0233451310e5c191aab408e2d75da609af653e..9017dab9e16a34880c56957e3f5b12fec956b42f 100644
--- a/chrome/browser/ui/webui/hung_renderer_dialog.cc
+++ b/chrome/browser/ui/webui/hung_renderer_dialog.cc
@@ -35,7 +35,7 @@ namespace browser {
void ShowHungRendererDialog(TabContents* contents) {
#if defined(OS_CHROMEOS) || defined(USE_AURA)
- HungRendererDialog::ShowHungRendererDialog(contents);
+ HungRendererDialog::ShowHungRendererDialog(contents, true);
wyck 2011/11/15 01:56:44 Aw Snap! This shouldn't be here. This caused the
#else
// TODO(rbyers): Remove IsMoreWebUI check once we decide for sure which
// platforms will use the WebUI version of this dialog.
@@ -63,12 +63,7 @@ void HideHungRendererDialog(TabContents* contents) {
// HungRendererDialog public static methods
void HungRendererDialog::ShowHungRendererDialog(TabContents* contents) {
- if (!logging::DialogsAreSuppressed()) {
- if (g_instance)
- return;
- g_instance = new HungRendererDialog();
- g_instance->ShowDialog(contents);
- }
+ ShowHungRendererDialogInternal(contents, true);
}
void HungRendererDialog::HideHungRendererDialog(TabContents* contents) {
@@ -76,16 +71,49 @@ void HungRendererDialog::HideHungRendererDialog(TabContents* contents) {
g_instance->HideDialog(contents);
}
+////////////////////////////////////////////////////////////////////////////////
+// HungRendererDialog::TabContentsObserverImpl
+
+HungRendererDialog::TabContentsObserverImpl::TabContentsObserverImpl(
+ HungRendererDialog* dialog,
+ TabContents* contents)
+ : TabContentsObserver(contents),
+ contents_(contents),
+ dialog_(dialog) {
+}
+
+void HungRendererDialog::TabContentsObserverImpl::RenderViewGone() {
+ dialog_->HideDialog(contents_);
+}
+
+void HungRendererDialog::TabContentsObserverImpl::TabContentsDestroyed(
+ TabContents* tab) {
+ dialog_->HideDialog(contents_);
+}
////////////////////////////////////////////////////////////////////////////////
// HungRendererDialog private methods
-HungRendererDialog::HungRendererDialog()
+HungRendererDialog::HungRendererDialog(bool is_enabled)
: contents_(NULL),
handler_(NULL),
+ is_enabled_(is_enabled),
window_(NULL) {
}
+HungRendererDialog::~HungRendererDialog() {
+}
+
+void HungRendererDialog::ShowHungRendererDialogInternal(TabContents* contents,
+ bool is_enabled) {
+ if (!logging::DialogsAreSuppressed()) {
+ if (g_instance)
+ return;
+ g_instance = new HungRendererDialog(is_enabled);
+ g_instance->ShowDialog(contents);
+ }
+}
+
void HungRendererDialog::ShowDialog(TabContents* contents) {
DCHECK(contents);
contents_ = contents;
@@ -93,6 +121,7 @@ void HungRendererDialog::ShowDialog(TabContents* contents) {
DCHECK(browser);
handler_ = new HungRendererDialogHandler(contents_);
window_ = browser->BrowserShowHtmlDialog(this, NULL);
+ contents_observer_.reset(new TabContentsObserverImpl(this, contents_));
}
void HungRendererDialog::HideDialog(TabContents* contents) {
@@ -104,6 +133,7 @@ void HungRendererDialog::HideDialog(TabContents* contents) {
// Settings |contents_| to NULL prevents the hang monitor from restarting.
// We do this because the close dialog handler runs whether it is trigged by
// the user closing the box, or by being closed externally with widget->Close.
+ contents_observer_.reset();
contents_ = NULL;
DCHECK(handler_);
handler_->CloseDialog();
@@ -135,25 +165,27 @@ std::string HungRendererDialog::GetDialogArgs() const {
}
void HungRendererDialog::OnDialogClosed(const std::string& json_retval) {
- // Figure out what the response was.
- scoped_ptr<Value> root(base::JSONReader::Read(json_retval, false));
- bool response = false;
- ListValue* list = NULL;
- // If the dialog closes because of a button click then the json is a list
- // containing a single bool. If the dialog closes some other way, then we
- // assume it means no permission was given to kill tabs.
- if (root.get() && root->GetAsList(&list) && list &&
- list->GetBoolean(0, &response) && response) {
- // The user indicated that it is OK to kill the renderer process.
- if (contents_ && contents_->GetRenderProcessHost()) {
- base::KillProcess(contents_->GetRenderProcessHost()->GetHandle(),
- content::RESULT_CODE_HUNG, false);
+ if (is_enabled_) {
+ // Figure out what the response was.
+ scoped_ptr<Value> root(base::JSONReader::Read(json_retval, false));
+ bool response = false;
+ ListValue* list = NULL;
+ // If the dialog closes because of a button click then the json is a list
+ // containing a single bool. If the dialog closes some other way, then we
+ // assume it means no permission was given to kill tabs.
+ if (root.get() && root->GetAsList(&list) && list &&
+ list->GetBoolean(0, &response) && response) {
+ // The user indicated that it is OK to kill the renderer process.
+ if (contents_ && contents_->GetRenderProcessHost()) {
+ base::KillProcess(contents_->GetRenderProcessHost()->GetHandle(),
+ content::RESULT_CODE_HUNG, false);
+ }
+ } else {
+ // No indication from the user that it is ok to kill anything. Just wait.
+ // Start waiting again for responsiveness.
+ if (contents_ && contents_->render_view_host())
+ contents_->render_view_host()->RestartHangMonitorTimeout();
}
- } else {
- // No indication from the user that it is ok to kill anything. Just wait.
- // Start waiting again for responsiveness.
- if (contents_ && contents_->render_view_host())
- contents_->render_view_host()->RestartHangMonitorTimeout();
}
g_instance = NULL;
delete this;
« no previous file with comments | « chrome/browser/ui/webui/hung_renderer_dialog.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698