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

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

Issue 22694006: Infobar system refactor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
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
« no previous file with comments | « chrome/browser/infobars/infobar.h ('k') | chrome/browser/infobars/infobar_container.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/infobars/infobar.cc
===================================================================
--- chrome/browser/infobars/infobar.cc (revision 238220)
+++ chrome/browser/infobars/infobar.cc (working copy)
@@ -12,9 +12,9 @@
#include "chrome/browser/infobars/infobar_service.h"
#include "ui/gfx/animation/slide_animation.h"
-InfoBar::InfoBar(InfoBarService* owner, InfoBarDelegate* delegate)
- : owner_(owner),
- delegate_(delegate),
+InfoBar::InfoBar(scoped_ptr<InfoBarDelegate> delegate)
+ : owner_(NULL),
+ delegate_(delegate.Pass()),
container_(NULL),
animation_(this),
arrow_height_(0),
@@ -22,12 +22,13 @@
arrow_half_width_(0),
bar_height_(0),
bar_target_height_(kDefaultBarTargetHeight) {
- DCHECK(owner_ != NULL);
DCHECK(delegate_ != NULL);
animation_.SetTweenType(gfx::Tween::LINEAR);
+ delegate_->set_infobar(this);
}
InfoBar::~InfoBar() {
+ DCHECK(!owner_);
}
// static
@@ -50,6 +51,13 @@
kWarningBackgroundColorBottom : kPageActionBackgroundColorBottom;
}
+void InfoBar::SetOwner(InfoBarService* owner) {
+ DCHECK(!owner_);
+ owner_ = owner;
+ delegate_->StoreActiveEntryUniqueID();
+ PlatformSpecificSetOwner();
+}
+
void InfoBar::Show(bool animate) {
PlatformSpecificShow(animate);
if (animate) {
@@ -90,6 +98,11 @@
MaybeDelete();
}
+void InfoBar::RemoveSelf() {
+ if (owner_)
+ owner_->RemoveInfoBar(this);
+}
+
void InfoBar::SetBarTargetHeight(int height) {
if (bar_target_height_ != height) {
bar_target_height_ = height;
@@ -101,19 +114,6 @@
RecalculateHeights(false);
}
-void InfoBar::RemoveSelf() {
- // |owner_| should never be NULL here. If it is, then someone violated what
- // they were supposed to do -- e.g. a ConfirmInfoBarDelegate subclass returned
- // true from Accept() or Cancel() even though the infobar was already closing.
- // In the worst case, if we also switched tabs during that process, then
- // |this| has already been destroyed. But if that's the case, then we're
- // going to deref a garbage |this| pointer here whether we check |owner_| or
- // not, and in other cases (where we're still closing and |this| is valid),
- // checking |owner_| here will avoid a NULL deref.
- if (owner_)
- owner_->RemoveInfoBar(delegate_);
-}
-
int InfoBar::OffsetY(const gfx::Size& prefsize) const {
return arrow_height_ +
std::max((bar_target_height_ - prefsize.height()) / 2, 0) -
@@ -173,10 +173,9 @@
}
void InfoBar::MaybeDelete() {
- if (!owner_ && delegate_ && (animation_.GetCurrentValue() == 0.0)) {
+ if (!owner_ && (animation_.GetCurrentValue() == 0.0)) {
if (container_)
container_->RemoveInfoBar(this);
- delete delegate_;
- delegate_ = NULL;
+ delete this;
}
}
« no previous file with comments | « chrome/browser/infobars/infobar.h ('k') | chrome/browser/infobars/infobar_container.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698