Chromium Code Reviews| Index: chrome/browser/ui/hung_plugin_tab_helper.cc |
| diff --git a/chrome/browser/ui/hung_plugin_tab_helper.cc b/chrome/browser/ui/hung_plugin_tab_helper.cc |
| index 374932018845c63b1e30d2a4e0e28338e40730ba..d3836d5921bc369fbff2262a63e5c945d94712b2 100644 |
| --- a/chrome/browser/ui/hung_plugin_tab_helper.cc |
| +++ b/chrome/browser/ui/hung_plugin_tab_helper.cc |
| @@ -10,7 +10,6 @@ |
| #include "base/process/process.h" |
| #include "base/rand_util.h" |
| #include "build/build_config.h" |
| -#include "chrome/browser/chrome_notification_types.h" |
| #include "chrome/browser/infobars/infobar_service.h" |
| #include "chrome/common/chrome_version_info.h" |
| #include "components/infobars/core/confirm_infobar_delegate.h" |
| @@ -18,8 +17,6 @@ |
| #include "content/public/browser/browser_child_process_host_iterator.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/child_process_data.h" |
| -#include "content/public/browser/notification_details.h" |
| -#include "content/public/browser/notification_service.h" |
| #include "content/public/browser/plugin_service.h" |
| #include "content/public/browser/render_process_host.h" |
| #include "content/public/common/process_type.h" |
| @@ -261,9 +258,8 @@ HungPluginTabHelper::PluginState::~PluginState() { |
| DEFINE_WEB_CONTENTS_USER_DATA_KEY(HungPluginTabHelper); |
| HungPluginTabHelper::HungPluginTabHelper(content::WebContents* contents) |
| - : content::WebContentsObserver(contents) { |
| - registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
| - content::NotificationService::AllSources()); |
| + : content::WebContentsObserver(contents), |
| + observer_installed_(false) { |
| } |
| HungPluginTabHelper::~HungPluginTabHelper() { |
| @@ -279,6 +275,11 @@ void HungPluginTabHelper::PluginCrashed(const base::FilePath& plugin_path, |
| if (!infobar_service) |
| return; |
| + if (!observer_installed_) { |
| + observer_installed_ = true; |
| + infobar_service->AddObserver(this); |
|
Peter Kasting
2014/05/30 18:05:48
Why do we want to add an observer here? We don't
|
| + } |
| + |
| // For now, just do a brute-force search to see if we have this plugin. Since |
| // we'll normally have 0 or 1, this is fast. |
| for (PluginStateMap::iterator i = hung_plugins_.begin(); |
| @@ -301,6 +302,11 @@ void HungPluginTabHelper::PluginHungStatusChanged( |
| if (!infobar_service) |
| return; |
| + if (!observer_installed_) { |
| + observer_installed_ = true; |
| + infobar_service->AddObserver(this); |
|
Peter Kasting
2014/05/30 18:05:48
Wouldn't we want this in ShowBar() instead of here
|
| + } |
| + |
| PluginStateMap::iterator found = hung_plugins_.find(plugin_child_id); |
| if (found != hung_plugins_.end()) { |
| if (!is_hung) { |
| @@ -321,33 +327,6 @@ void HungPluginTabHelper::PluginHungStatusChanged( |
| ShowBar(plugin_child_id, state.get()); |
| } |
| -void HungPluginTabHelper::Observe( |
| - int type, |
| - const content::NotificationSource& source, |
| - const content::NotificationDetails& details) { |
| - DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); |
| - infobars::InfoBar* infobar = |
| - content::Details<infobars::InfoBar::RemovedDetails>(details)->first; |
| - for (PluginStateMap::iterator i = hung_plugins_.begin(); |
| - i != hung_plugins_.end(); ++i) { |
| - PluginState* state = i->second.get(); |
| - if (state->infobar == infobar) { |
| - state->infobar = NULL; |
| - |
| - // Schedule the timer to re-show the infobar if the plugin continues to be |
| - // hung. |
| - state->timer.Start(FROM_HERE, state->next_reshow_delay, |
| - base::Bind(&HungPluginTabHelper::OnReshowTimer, |
| - base::Unretained(this), |
| - i->first)); |
| - |
| - // Next time we do this, delay it twice as long to avoid being annoying. |
| - state->next_reshow_delay *= 2; |
| - return; |
| - } |
| - } |
| -} |
| - |
| void HungPluginTabHelper::KillPlugin(int child_id) { |
| #if defined(OS_WIN) |
| // Dump renderers that are sending or receiving pepper messages, in order to |
| @@ -422,3 +401,37 @@ void HungPluginTabHelper::CloseBar(PluginState* state) { |
| state->infobar = NULL; |
| } |
| } |
| + |
| +void HungPluginTabHelper::OnInfoBarRemoved(infobars::InfoBar* infobar, |
| + bool animate) { |
| + for (PluginStateMap::iterator i = hung_plugins_.begin(); |
| + i != hung_plugins_.end(); ++i) { |
| + PluginState* state = i->second.get(); |
| + if (state->infobar == infobar) { |
| + state->infobar = NULL; |
| + |
| + // Schedule the timer to re-show the infobar if the plugin continues to be |
| + // hung. |
| + state->timer.Start(FROM_HERE, |
| + state->next_reshow_delay, |
| + base::Bind(&HungPluginTabHelper::OnReshowTimer, |
| + base::Unretained(this), |
| + i->first)); |
| + |
| + // Next time we do this, delay it twice as long to avoid being annoying. |
| + state->next_reshow_delay *= 2; |
| + return; |
| + } |
| + } |
| +} |
| + |
| +void HungPluginTabHelper::OnManagerShuttingDown( |
| + infobars::InfoBarManager* manager) { |
| + InfoBarService* infobar_service = |
| + InfoBarService::FromWebContents(web_contents()); |
| + if (!infobar_service) |
| + return; |
| + |
| + if (observer_installed_) |
| + infobar_service->RemoveObserver(this); |
| +} |