OLD | NEW |
---|---|
(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 HungPluginTabHelper(content::WebContents* contents); | |
yzshen1
2012/04/11 18:30:46
explicit, please.
| |
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 // True when the plugin is currently hung. | |
59 bool is_hung; | |
yzshen1
2012/04/11 18:30:46
This member is not used.
| |
60 | |
61 // Time when the infobar for this plugin was last closed. This will be | |
62 // is_null() if the bar for this plugin has not been closed since it became | |
63 // hung. | |
64 base::TimeTicks bar_closed_time; | |
yzshen1
2012/04/11 18:30:46
This member is not useful, either.
| |
65 | |
66 FilePath path; | |
67 string16 name; | |
68 | |
69 // Possibly-null if we're not showing an infobar right now. | |
70 InfoBarDelegate* info_bar; | |
71 | |
72 // Time to delay before re-showing the infobar for a hung plugin. This is | |
73 // increased each time the user cancels it. | |
74 base::TimeDelta next_reshow_delay; | |
75 | |
76 // Handles calling the helper when the infobar should be re-shown. | |
77 base::Timer timer; | |
78 | |
79 private: | |
80 // Since the scope of the timer manages our callback, this struct should | |
81 // not be copied. | |
82 DISALLOW_COPY_AND_ASSIGN(PluginState); | |
83 }; | |
84 typedef std::map<int, linked_ptr<PluginState> > PluginStateMap; | |
85 | |
86 // Called by an infobar when the user selects to kill the plugin. | |
87 void KillPlugin(int child_id); | |
88 | |
89 // Called by an infobar when the user presses the close button to dismiss the | |
90 // bar without doing anything. | |
91 void BarClosed(int child_id); | |
92 | |
93 // 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
| |
94 // bar. | |
95 void OnReshowTimer(int child_id); | |
96 | |
97 // Shows the bar for the plugin identified by the given state, updating the | |
98 // state accordingly. The plugin must not have an infobar already. | |
99 void ShowBar(int child_id, PluginState* state); | |
100 | |
101 // Closes the infobar associated with the given state. Note that this can | |
102 // be called even if the bar is not opened, in which case it will do nothing. | |
103 void CloseBar(PluginState* state); | |
104 | |
105 content::WebContents* contents_; | |
106 | |
107 // All currently hung plugins. | |
108 PluginStateMap hung_plugins_; | |
109 | |
110 DISALLOW_COPY_AND_ASSIGN(HungPluginTabHelper); | |
111 }; | |
112 | |
113 #endif // CHROME_BROWSER_UI_HUNG_PLUGIN_TAB_HELPER_H_ | |
OLD | NEW |