Index: chrome/browser/infobars/infobar_container.cc |
diff --git a/chrome/browser/infobars/infobar_container.cc b/chrome/browser/infobars/infobar_container.cc |
index 8ef5b7ee9501f9c4bb6ee0e0f368246bd733fb31..df1976c1169ee87f7562615361628f6e6c3bc7ba 100644 |
--- a/chrome/browser/infobars/infobar_container.cc |
+++ b/chrome/browser/infobars/infobar_container.cc |
@@ -9,12 +9,9 @@ |
#include <algorithm> |
#include "base/logging.h" |
-#include "chrome/browser/chrome_notification_types.h" |
#include "chrome/browser/infobars/infobar.h" |
#include "chrome/browser/infobars/infobar_delegate.h" |
-#include "chrome/browser/infobars/infobar_service.h" |
-#include "content/public/browser/notification_details.h" |
-#include "content/public/browser/notification_source.h" |
+#include "chrome/browser/infobars/infobar_manager.h" |
#include "ui/gfx/animation/slide_animation.h" |
InfoBarContainer::Delegate::~Delegate() { |
@@ -22,32 +19,29 @@ InfoBarContainer::Delegate::~Delegate() { |
InfoBarContainer::InfoBarContainer(Delegate* delegate) |
: delegate_(delegate), |
- infobar_service_(NULL), |
- top_arrow_target_height_(InfoBar::kDefaultArrowTargetHeight) { |
-} |
+ infobar_manager_(NULL), |
+ top_arrow_target_height_(InfoBar::kDefaultArrowTargetHeight) {} |
InfoBarContainer::~InfoBarContainer() { |
+ if (infobar_manager_) |
+ infobar_manager_->RemoveObserver(this); |
// RemoveAllInfoBarsForDestruction() should have already cleared our infobars. |
DCHECK(infobars_.empty()); |
} |
-void InfoBarContainer::ChangeInfoBarService(InfoBarService* infobar_service) { |
+void InfoBarContainer::ChangeInfoBarManager(InfoBarManager* infobar_manager) { |
HideAllInfoBars(); |
- infobar_service_ = infobar_service; |
- if (infobar_service_) { |
- content::Source<InfoBarService> source(infobar_service_); |
- registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
- source); |
- registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
- source); |
- registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED, |
- source); |
- |
- for (size_t i = 0; i < infobar_service_->infobar_count(); ++i) { |
+ if (infobar_manager_) |
+ infobar_manager_->RemoveObserver(this); |
+ |
+ infobar_manager_ = infobar_manager; |
+ if (infobar_manager_) { |
+ infobar_manager_->AddObserver(this); |
+ for (size_t i = 0; i < infobar_manager_->infobar_count(); ++i) { |
// As when we removed the infobars above, we prevent callbacks to |
// OnInfoBarStateChanged() for each infobar. |
- AddInfoBar(infobar_service_->infobar_at(i), i, false, NO_CALLBACK); |
+ AddInfoBar(infobar_manager_->infobar_at(i), i, false, NO_CALLBACK); |
} |
} |
@@ -104,50 +98,30 @@ void InfoBarContainer::RemoveAllInfoBarsForDestruction() { |
// this point |delegate_| may be shutting down, and it's at best unimportant |
// and at worst disastrous to call that. |
delegate_ = NULL; |
- ChangeInfoBarService(NULL); |
+ ChangeInfoBarManager(NULL); |
} |
-void InfoBarContainer::Observe(int type, |
- const content::NotificationSource& source, |
- const content::NotificationDetails& details) { |
- switch (type) { |
- case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED: |
- AddInfoBar(content::Details<InfoBar::AddedDetails>(details).ptr(), |
- infobars_.size(), true, WANT_CALLBACK); |
- break; |
- |
- case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED: { |
- InfoBar::RemovedDetails* removed_details = |
- content::Details<InfoBar::RemovedDetails>(details).ptr(); |
- removed_details->first->Hide(removed_details->second); |
- UpdateInfoBarArrowTargetHeights(); |
- break; |
- } |
+void InfoBarContainer::OnInfoBarAdded(InfoBar* infobar) { |
+ AddInfoBar(infobar, infobars_.size(), true, WANT_CALLBACK); |
+} |
- case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED: { |
- InfoBar::ReplacedDetails* replaced_details = |
- content::Details<InfoBar::ReplacedDetails>(details).ptr(); |
- InfoBar* old_infobar = replaced_details->first; |
- InfoBar* new_infobar = replaced_details->second; |
- PlatformSpecificReplaceInfoBar(old_infobar, new_infobar); |
- InfoBars::const_iterator i(std::find(infobars_.begin(), infobars_.end(), |
- old_infobar)); |
- DCHECK(i != infobars_.end()); |
- size_t position = i - infobars_.begin(); |
- old_infobar->Hide(false); |
- AddInfoBar(new_infobar, position, false, WANT_CALLBACK); |
- break; |
- } |
+void InfoBarContainer::OnInfoBarReplaced(InfoBar* old_infobar, |
+ InfoBar* new_infobar) { |
+ PlatformSpecificReplaceInfoBar(old_infobar, new_infobar); |
+ InfoBars::const_iterator i( |
+ std::find(infobars_.begin(), infobars_.end(), old_infobar)); |
+ DCHECK(i != infobars_.end()); |
+ size_t position = i - infobars_.begin(); |
+ old_infobar->Hide(false); |
+ AddInfoBar(new_infobar, position, false, WANT_CALLBACK); |
+} |
- default: |
- NOTREACHED(); |
- break; |
- } |
+void InfoBarContainer::OnInfoBarRemoved(InfoBar* infobar, bool animate) { |
+ infobar->Hide(animate); |
+ UpdateInfoBarArrowTargetHeights(); |
} |
void InfoBarContainer::HideAllInfoBars() { |
- registrar_.RemoveAll(); |
- |
while (!infobars_.empty()) { |
InfoBar* infobar = infobars_.front(); |
// Inform the infobar that it's hidden. If it was already closing, this |