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

Side by Side 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: Review comments 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_UI_HUNG_PLUGIN_TAB_HELPER_H_
6 #define CHROME_BROWSER_UI_HUNG_PLUGIN_TAB_HELPER_H_
7
8 #include <map>
9
10 #include "base/file_path.h"
11 #include "base/memory/linked_ptr.h"
12 #include "base/string16.h"
13 #include "base/time.h"
14 #include "base/timer.h"
15
16 class FilePath;
17
18 namespace content {
19 class WebContents;
20 }
21
22 // Manages per-tab state with regard to hung plugins. This only handles
23 // Pepper plugins which we know are windowless. Hung NPAPI plugins (which
24 // may have native windows) can not be handled with infobars and have a
25 // separate OS-specific hang monitoring.
26 //
27 // Our job is:
28 // - Pop up an infobar when a plugin is hung.
29 // - Terminate the plugin process if the user so chooses.
30 // - Periodically re-show the hung plugin infobar if the user closes it without
31 // terminating the plugin.
32 // - Hide the infobar if the plugin starts responding again.
33 // - Keep track of all of this for any number of plugins.
34 class HungPluginTabHelper {
35 public:
36 explicit HungPluginTabHelper(content::WebContents* contents);
37 ~HungPluginTabHelper();
38
39 void PluginCrashed(const FilePath& plugin_path);
40
41 void PluginHungStatusChanged(int plugin_child_id,
42 const FilePath& plugin_path,
43 bool is_hung);
44
45 private:
46 class InfoBarDelegate;
47 friend class InfoBarDelegate;
48
49 // Per-plugin state (since there could be more than one plugin hung). The
50 // integer key is the child process ID of the plugin process. This maintains
51 // the state for all plugins on this page that are currently hung, whether or
52 // not we're currently showing the infobar.
53 struct PluginState {
54 // Initializes the plugin state to be a hung plugin.
55 PluginState(const FilePath& p, const string16& n);
56 ~PluginState();
57
58 FilePath path;
59 string16 name;
60
61 // Possibly-null if we're not showing an infobar right now.
62 InfoBarDelegate* info_bar;
63
64 // Time to delay before re-showing the infobar for a hung plugin. This is
65 // increased each time the user cancels it.
66 base::TimeDelta next_reshow_delay;
67
68 // Handles calling the helper when the infobar should be re-shown.
69 base::Timer timer;
70
71 private:
72 // Since the scope of the timer manages our callback, this struct should
73 // not be copied.
74 DISALLOW_COPY_AND_ASSIGN(PluginState);
75 };
76 typedef std::map<int, linked_ptr<PluginState> > PluginStateMap;
77
78 // Called by an infobar when the user selects to kill the plugin.
79 void KillPlugin(int child_id);
80
81 // Called by an infobar when the user presses the close button to dismiss the
82 // bar without doing anything.
83 void BarClosed(int child_id);
84
85 // Called on a timer for a hung plugin to re-show the bar.
86 void OnReshowTimer(int child_id);
87
88 // Shows the bar for the plugin identified by the given state, updating the
89 // state accordingly. The plugin must not have an infobar already.
90 void ShowBar(int child_id, PluginState* state);
91
92 // Closes the infobar associated with the given state. Note that this can
93 // be called even if the bar is not opened, in which case it will do nothing.
94 void CloseBar(PluginState* state);
95
96 // Possibly returns null.
97 InfoBarTabHelper* GetInfoBarHelper();
98
99 content::WebContents* contents_;
100
101 // All currently hung plugins.
102 PluginStateMap hung_plugins_;
103
104 DISALLOW_COPY_AND_ASSIGN(HungPluginTabHelper);
105 };
106
107 #endif // CHROME_BROWSER_UI_HUNG_PLUGIN_TAB_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698