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

Unified Diff: chrome/browser/infobars/infobar_container.cc

Issue 22694006: Infobar system refactor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 2 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/infobars/infobar_container.cc
===================================================================
--- chrome/browser/infobars/infobar_container.cc (revision 226624)
+++ chrome/browser/infobars/infobar_container.cc (working copy)
@@ -47,9 +47,7 @@
for (size_t i = 0; i < infobar_service_->infobar_count(); ++i) {
// As when we removed the infobars above, we prevent callbacks to
// OnInfoBarAnimated() for each infobar.
- AddInfoBar(
- infobar_service_->infobar_at(i)->CreateInfoBar(infobar_service_),
- i, false, NO_CALLBACK);
+ AddInfoBar(infobar_service_->infobar_at(i), i, false, NO_CALLBACK);
}
}
@@ -114,23 +112,30 @@
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED:
- AddInfoBar(
- content::Details<InfoBarAddedDetails>(details)->CreateInfoBar(
- infobar_service_),
- infobars_.size(), true, WANT_CALLBACK);
+ AddInfoBar(content::Details<InfoBar::AddedDetails>(details).ptr(),
+ infobars_.size(), true, WANT_CALLBACK);
break;
case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED: {
- InfoBarRemovedDetails* removed_details =
- content::Details<InfoBarRemovedDetails>(details).ptr();
- HideInfoBar(FindInfoBar(removed_details->first), removed_details->second);
+ InfoBar::RemovedDetails* removed_details =
+ content::Details<InfoBar::RemovedDetails>(details).ptr();
+ removed_details->first->Hide(removed_details->second);
+ UpdateInfoBarArrowTargetHeights();
break;
}
case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED: {
- InfoBarReplacedDetails* replaced_details =
- content::Details<InfoBarReplacedDetails>(details).ptr();
- ReplaceInfoBar(replaced_details->first, replaced_details->second);
+ 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;
}
@@ -140,44 +145,6 @@
}
}
-void InfoBarContainer::ReplaceInfoBar(InfoBarDelegate* old_delegate,
- InfoBarDelegate* new_delegate) {
- InfoBar* new_infobar = new_delegate->CreateInfoBar(infobar_service_);
- InfoBar* old_infobar = FindInfoBar(old_delegate);
-#if defined(OS_ANDROID)
- PlatformSpecificReplaceInfoBar(old_infobar, new_infobar);
-#endif
- AddInfoBar(
- new_infobar, HideInfoBar(old_infobar, false), false, WANT_CALLBACK);
-}
-
-InfoBar* InfoBarContainer::FindInfoBar(InfoBarDelegate* delegate) {
- // Search for the infobar associated with |delegate|. We cannot search for
- // |delegate| in |tab_helper_|, because an InfoBar remains alive until its
- // close animation completes, while the delegate is removed from the tab
- // immediately.
- for (InfoBars::iterator i(infobars_.begin()); i != infobars_.end(); ++i) {
- InfoBar* infobar = *i;
- if (infobar->delegate() == delegate)
- return infobar;
- }
- NOTREACHED();
- return NULL;
-}
-
-size_t InfoBarContainer::HideInfoBar(InfoBar* infobar, bool use_animation) {
- InfoBars::iterator it =
- std::find(infobars_.begin(), infobars_.end(), infobar);
- DCHECK(it != infobars_.end());
- size_t position = it - infobars_.begin();
- // We merely need hide the infobar; it will call back to RemoveInfoBar()
- // itself once it's hidden.
- infobar->Hide(use_animation);
- infobar->CloseSoon();
- UpdateInfoBarArrowTargetHeights();
- return position;
-}
-
void InfoBarContainer::HideAllInfoBars() {
registrar_.RemoveAll();
@@ -184,7 +151,8 @@
while (!infobars_.empty()) {
InfoBar* infobar = infobars_.front();
// Inform the infobar that it's hidden. If it was already closing, this
- // closes its delegate.
+ // deletes it. Otherwise, this ensures the infobar will be deleted if it's
+ // closed while it's not in an InfoBarContainer.
infobar->Hide(false);
}
}

Powered by Google App Engine
This is Rietveld 408576698