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

Unified Diff: chrome/browser/ui/hung_plugin_tab_helper.h

Issue 10014013: Add a hang monitor for Pepper plugins (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix leak Created 8 years, 8 months 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
Index: chrome/browser/ui/hung_plugin_tab_helper.h
diff --git a/chrome/browser/ui/hung_plugin_tab_helper.h b/chrome/browser/ui/hung_plugin_tab_helper.h
new file mode 100644
index 0000000000000000000000000000000000000000..38f3878d6fb949ce229db51929a06e1aef1a3499
--- /dev/null
+++ b/chrome/browser/ui/hung_plugin_tab_helper.h
@@ -0,0 +1,113 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_HUNG_PLUGIN_TAB_HELPER_H_
+#define CHROME_BROWSER_UI_HUNG_PLUGIN_TAB_HELPER_H_
+
+#include <map>
+
+#include "base/file_path.h"
+#include "base/memory/linked_ptr.h"
+#include "base/string16.h"
+#include "base/time.h"
+#include "base/timer.h"
+
+class FilePath;
+
+namespace content {
+class WebContents;
+}
+
+// Manages per-tab state with regard to hung plugins. This only handles
+// Pepper plugins which we know are windowless. Hung NPAPI plugins (which
+// may have native windows) can not be handled with infobars and have a
+// separate OS-specific hang monitoring.
+//
+// Our job is:
+// - Pop up an infobar when a plugin is hung.
+// - Terminate the plugin process if the user so chooses.
+// - Periodically re-show the hung plugin infobar if the user closes it without
+// terminating the plugin.
+// - Hide the infobar if the plugin starts responding again.
+// - Keep track of all of this for any number of plugins.
+class HungPluginTabHelper {
+ public:
+ HungPluginTabHelper(content::WebContents* contents);
yzshen1 2012/04/11 18:30:46 explicit, please.
+ ~HungPluginTabHelper();
+
+ void PluginCrashed(const FilePath& plugin_path);
+
+ void PluginHungStatusChanged(int plugin_child_id,
+ const FilePath& plugin_path,
+ bool is_hung);
+
+ private:
+ class InfoBarDelegate;
+ friend class InfoBarDelegate;
+
+ // Per-plugin state (since there could be more than one plugin hung). The
+ // integer key is the child process ID of the plugin process. This maintains
+ // the state for all plugins on this page that are currently hung, whether or
+ // not we're currently showing the infobar.
+ struct PluginState {
+ // Initializes the plugin state to be a hung plugin.
+ PluginState(const FilePath& p, const string16& n);
+ ~PluginState();
+
+ // True when the plugin is currently hung.
+ bool is_hung;
yzshen1 2012/04/11 18:30:46 This member is not used.
+
+ // Time when the infobar for this plugin was last closed. This will be
+ // is_null() if the bar for this plugin has not been closed since it became
+ // hung.
+ base::TimeTicks bar_closed_time;
yzshen1 2012/04/11 18:30:46 This member is not useful, either.
+
+ FilePath path;
+ string16 name;
+
+ // Possibly-null if we're not showing an infobar right now.
+ InfoBarDelegate* info_bar;
+
+ // Time to delay before re-showing the infobar for a hung plugin. This is
+ // increased each time the user cancels it.
+ base::TimeDelta next_reshow_delay;
+
+ // Handles calling the helper when the infobar should be re-shown.
+ base::Timer timer;
+
+ private:
+ // Since the scope of the timer manages our callback, this struct should
+ // not be copied.
+ DISALLOW_COPY_AND_ASSIGN(PluginState);
+ };
+ typedef std::map<int, linked_ptr<PluginState> > PluginStateMap;
+
+ // Called by an infobar when the user selects to kill the plugin.
+ void KillPlugin(int child_id);
+
+ // Called by an infobar when the user presses the close button to dismiss the
+ // bar without doing anything.
+ void BarClosed(int child_id);
+
+ // Called on a timer for a hung plugin if the bar is closed to re-show the
yzshen1 2012/04/11 18:30:46 nit: please consider removing the "if the bar is c
+ // bar.
+ void OnReshowTimer(int child_id);
+
+ // Shows the bar for the plugin identified by the given state, updating the
+ // state accordingly. The plugin must not have an infobar already.
+ void ShowBar(int child_id, PluginState* state);
+
+ // Closes the infobar associated with the given state. Note that this can
+ // be called even if the bar is not opened, in which case it will do nothing.
+ void CloseBar(PluginState* state);
+
+ content::WebContents* contents_;
+
+ // All currently hung plugins.
+ PluginStateMap hung_plugins_;
+
+ DISALLOW_COPY_AND_ASSIGN(HungPluginTabHelper);
+};
+
+#endif // CHROME_BROWSER_UI_HUNG_PLUGIN_TAB_HELPER_H_

Powered by Google App Engine
This is Rietveld 408576698