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

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

Issue 297293002: Change HungPluginTabHelper to listen for infobar changes through Observer style. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 6 years, 7 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.cc
diff --git a/chrome/browser/ui/hung_plugin_tab_helper.cc b/chrome/browser/ui/hung_plugin_tab_helper.cc
index 374932018845c63b1e30d2a4e0e28338e40730ba..93529d161fff4e8ca9d82d8bd640575727b09964 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,12 +258,12 @@ 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),
+ number_of_infobars_(0) {
}
HungPluginTabHelper::~HungPluginTabHelper() {
tfarina 2014/06/07 05:26:21 Peter, I got the backtrace for this. It is this (
+ DCHECK_EQ(0, number_of_infobars_);
Peter Kasting 2014/06/03 18:41:45 Are you sure we're guaranteed that the InfoBarMana
}
void HungPluginTabHelper::PluginCrashed(const base::FilePath& plugin_path,
@@ -321,13 +318,13 @@ 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;
+void HungPluginTabHelper::OnInfoBarRemoved(infobars::InfoBar* infobar,
+ bool animate) {
+ --number_of_infobars_;
Peter Kasting 2014/06/03 18:41:45 This is not safe. You get called on every kind of
tfarina 2014/06/07 05:26:21 Done.
+
Peter Kasting 2014/06/03 18:41:45 Nit: I'd avoid this newline (2 places)
tfarina 2014/06/07 05:26:21 Done.
+ if (number_of_infobars_ == 0)
+ InfoBarService::FromWebContents(web_contents())->RemoveObserver(this);
+
for (PluginStateMap::iterator i = hung_plugins_.begin();
i != hung_plugins_.end(); ++i) {
PluginState* state = i->second.get();
@@ -412,6 +409,13 @@ void HungPluginTabHelper::ShowBar(int child_id, PluginState* state) {
DCHECK(!state->infobar);
state->infobar = HungPluginInfoBarDelegate::Create(infobar_service, this,
child_id, state->name);
+
+ if (state->infobar) {
+ ++number_of_infobars_;
+
+ if (number_of_infobars_ == 1)
+ infobar_service->AddObserver(this);
+ }
}
void HungPluginTabHelper::CloseBar(PluginState* state) {
« chrome/browser/ui/hung_plugin_tab_helper.h ('K') | « chrome/browser/ui/hung_plugin_tab_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698