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

Unified Diff: trunk/src/chrome/browser/infobars/infobar_service.cc

Issue 102163002: Revert 238283 "Infobar system refactor." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years 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: trunk/src/chrome/browser/infobars/infobar_service.cc
===================================================================
--- trunk/src/chrome/browser/infobars/infobar_service.cc (revision 238401)
+++ trunk/src/chrome/browser/infobars/infobar_service.cc (working copy)
@@ -16,22 +16,24 @@
DEFINE_WEB_CONTENTS_USER_DATA_KEY(InfoBarService);
-InfoBar* InfoBarService::AddInfoBar(scoped_ptr<InfoBar> infobar) {
+InfoBarDelegate* InfoBarService::AddInfoBar(
+ scoped_ptr<InfoBarDelegate> infobar) {
DCHECK(infobar);
if (!infobars_enabled_)
return NULL;
for (InfoBars::const_iterator i(infobars_.begin()); i != infobars_.end();
++i) {
- if ((*i)->delegate()->EqualsDelegate(infobar->delegate())) {
- DCHECK_NE((*i)->delegate(), infobar->delegate());
+ if ((*i)->EqualsDelegate(infobar.get())) {
+ DCHECK_NE(*i, infobar.get());
return NULL;
}
}
- InfoBar* infobar_ptr = infobar.release();
+ InfoBarDelegate* infobar_ptr = infobar.release();
infobars_.push_back(infobar_ptr);
- infobar_ptr->SetOwner(this);
+ // TODO(pkasting): Remove InfoBarService arg from delegate constructors and
+ // instead use a setter from here.
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
@@ -40,36 +42,35 @@
return infobar_ptr;
}
-void InfoBarService::RemoveInfoBar(InfoBar* infobar) {
+void InfoBarService::RemoveInfoBar(InfoBarDelegate* infobar) {
RemoveInfoBarInternal(infobar, true);
}
-InfoBar* InfoBarService::ReplaceInfoBar(InfoBar* old_infobar,
- scoped_ptr<InfoBar> new_infobar) {
+InfoBarDelegate* InfoBarService::ReplaceInfoBar(
+ InfoBarDelegate* old_infobar,
+ scoped_ptr<InfoBarDelegate> new_infobar) {
DCHECK(old_infobar);
if (!infobars_enabled_)
- return AddInfoBar(new_infobar.Pass()); // Deletes the infobar.
+ return AddInfoBar(new_infobar.Pass()); // Deletes the delegate.
DCHECK(new_infobar);
InfoBars::iterator i(std::find(infobars_.begin(), infobars_.end(),
old_infobar));
DCHECK(i != infobars_.end());
- InfoBar* new_infobar_ptr = new_infobar.release();
+ InfoBarDelegate* new_infobar_ptr = new_infobar.release();
i = infobars_.insert(i, new_infobar_ptr);
- new_infobar_ptr->SetOwner(this);
InfoBar::ReplacedDetails replaced_details(old_infobar, new_infobar_ptr);
- // Remove the old infobar before notifying, so that if any observers call back
- // to AddInfoBar() or similar, we don't dupe-check against this infobar.
+ // Remove the old infobar before notifying, so that if any observers call
+ // back to AddInfoBar() or similar, we don't dupe-check against this infobar.
infobars_.erase(++i);
+ old_infobar->clear_owner();
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED,
content::Source<InfoBarService>(this),
content::Details<InfoBar::ReplacedDetails>(&replaced_details));
-
- old_infobar->CloseSoon();
return new_infobar_ptr;
}
@@ -82,6 +83,10 @@
InfoBarService::~InfoBarService() {
// Destroy all remaining InfoBars. It's important to not animate here so that
// we guarantee that we'll delete all delegates before we do anything else.
+ //
+ // TODO(pkasting): If there is no InfoBarContainer, this leaks all the
+ // InfoBarDelegates. This will be fixed once we call CloseSoon() directly on
+ // Infobars.
RemoveAllInfoBars(false);
}
@@ -95,8 +100,8 @@
// use iterators, as the RemoveInfoBar() call synchronously modifies our
// delegate list.
for (size_t i = infobars_.size(); i > 0; --i) {
- InfoBar* infobar = infobars_[i - 1];
- if (infobar->delegate()->ShouldExpire(load_details))
+ InfoBarDelegate* infobar = infobars_[i - 1];
+ if (infobar->ShouldExpire(load_details))
RemoveInfoBar(infobar);
}
}
@@ -122,7 +127,8 @@
return handled;
}
-void InfoBarService::RemoveInfoBarInternal(InfoBar* infobar, bool animate) {
+void InfoBarService::RemoveInfoBarInternal(InfoBarDelegate* infobar,
+ bool animate) {
DCHECK(infobar);
if (!infobars_enabled_) {
DCHECK(infobars_.empty());
@@ -132,19 +138,16 @@
InfoBars::iterator i(std::find(infobars_.begin(), infobars_.end(), infobar));
DCHECK(i != infobars_.end());
+ infobar->clear_owner();
// Remove the infobar before notifying, so that if any observers call back to
// AddInfoBar() or similar, we don't dupe-check against this infobar.
infobars_.erase(i);
- // This notification must happen before the call to CloseSoon() below, since
- // observers may want to access |infobar| and that call can delete it.
InfoBar::RemovedDetails removed_details(infobar, animate);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
content::Source<InfoBarService>(this),
content::Details<InfoBar::RemovedDetails>(&removed_details));
-
- infobar->CloseSoon();
}
void InfoBarService::RemoveAllInfoBars(bool animate) {

Powered by Google App Engine
This is Rietveld 408576698