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 #ifndef CHROME_BROWSER_UI_HUNG_PLUGIN_TAB_HELPER_H_ | 5 #ifndef CHROME_BROWSER_UI_HUNG_PLUGIN_TAB_HELPER_H_ |
6 #define CHROME_BROWSER_UI_HUNG_PLUGIN_TAB_HELPER_H_ | 6 #define CHROME_BROWSER_UI_HUNG_PLUGIN_TAB_HELPER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/files/file_path.h" | |
11 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
12 #include "base/string16.h" | 11 #include "base/string16.h" |
13 #include "base/time.h" | 12 #include "base/time.h" |
14 #include "base/timer.h" | 13 #include "base/timer.h" |
15 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
16 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
17 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
18 #include "content/public/browser/web_contents_user_data.h" | 17 #include "content/public/browser/web_contents_user_data.h" |
19 | 18 |
20 class InfoBarDelegate; | 19 class InfoBarDelegate; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 const content::NotificationSource& source, | 53 const content::NotificationSource& source, |
55 const content::NotificationDetails& details) OVERRIDE; | 54 const content::NotificationDetails& details) OVERRIDE; |
56 | 55 |
57 // Called by an infobar when the user selects to kill the plugin. | 56 // Called by an infobar when the user selects to kill the plugin. |
58 void KillPlugin(int child_id); | 57 void KillPlugin(int child_id); |
59 | 58 |
60 private: | 59 private: |
61 explicit HungPluginTabHelper(content::WebContents* contents); | 60 explicit HungPluginTabHelper(content::WebContents* contents); |
62 friend class content::WebContentsUserData<HungPluginTabHelper>; | 61 friend class content::WebContentsUserData<HungPluginTabHelper>; |
63 | 62 |
64 // Per-plugin state (since there could be more than one plugin hung). The | 63 struct PluginState; |
65 // integer key is the child process ID of the plugin process. This maintains | |
66 // the state for all plugins on this page that are currently hung, whether or | |
67 // not we're currently showing the infobar. | |
68 struct PluginState { | |
69 // Initializes the plugin state to be a hung plugin. | |
70 PluginState(const base::FilePath& p, const string16& n); | |
71 ~PluginState(); | |
72 | |
73 base::FilePath path; | |
74 string16 name; | |
75 | |
76 // Possibly-null if we're not showing an infobar right now. | |
77 InfoBarDelegate* info_bar; | |
78 | |
79 // Time to delay before re-showing the infobar for a hung plugin. This is | |
80 // increased each time the user cancels it. | |
81 base::TimeDelta next_reshow_delay; | |
82 | |
83 // Handles calling the helper when the infobar should be re-shown. | |
84 base::Timer timer; | |
85 | |
86 private: | |
87 // Since the scope of the timer manages our callback, this struct should | |
88 // not be copied. | |
89 DISALLOW_COPY_AND_ASSIGN(PluginState); | |
90 }; | |
91 typedef std::map<int, linked_ptr<PluginState> > PluginStateMap; | 64 typedef std::map<int, linked_ptr<PluginState> > PluginStateMap; |
92 | 65 |
93 // Called on a timer for a hung plugin to re-show the bar. | 66 // Called on a timer for a hung plugin to re-show the bar. |
94 void OnReshowTimer(int child_id); | 67 void OnReshowTimer(int child_id); |
95 | 68 |
96 // Shows the bar for the plugin identified by the given state, updating the | 69 // Shows the bar for the plugin identified by the given state, updating the |
97 // state accordingly. The plugin must not have an infobar already. | 70 // state accordingly. The plugin must not have an infobar already. |
98 void ShowBar(int child_id, PluginState* state); | 71 void ShowBar(int child_id, PluginState* state); |
99 | 72 |
100 // Closes the infobar associated with the given state. Note that this can | 73 // Closes the infobar associated with the given state. Note that this can |
101 // be called even if the bar is not opened, in which case it will do nothing. | 74 // be called even if the bar is not opened, in which case it will do nothing. |
102 void CloseBar(PluginState* state); | 75 void CloseBar(PluginState* state); |
103 | 76 |
104 content::NotificationRegistrar registrar_; | 77 content::NotificationRegistrar registrar_; |
105 | 78 |
106 // All currently hung plugins. | 79 // All currently hung plugins. |
107 PluginStateMap hung_plugins_; | 80 PluginStateMap hung_plugins_; |
108 | 81 |
109 DISALLOW_COPY_AND_ASSIGN(HungPluginTabHelper); | 82 DISALLOW_COPY_AND_ASSIGN(HungPluginTabHelper); |
110 }; | 83 }; |
111 | 84 |
112 #endif // CHROME_BROWSER_UI_HUNG_PLUGIN_TAB_HELPER_H_ | 85 #endif // CHROME_BROWSER_UI_HUNG_PLUGIN_TAB_HELPER_H_ |
OLD | NEW |