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

Unified Diff: trunk/src/chrome/browser/infobars/infobar.h

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.h
===================================================================
--- trunk/src/chrome/browser/infobars/infobar.h (revision 238401)
+++ trunk/src/chrome/browser/infobars/infobar.h (working copy)
@@ -7,7 +7,9 @@
#include <utility>
-#include "base/memory/scoped_ptr.h"
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "build/build_config.h"
#include "chrome/browser/infobars/infobar_delegate.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/animation/animation_delegate.h"
@@ -17,27 +19,12 @@
class InfoBarContainer;
class InfoBarService;
-// InfoBar is a cross-platform base class for an infobar "view" (in the MVC
-// sense), which owns a corresponding InfoBarDelegate "model". Typically,
-// a caller will call XYZInfoBarDelegate::Create() and pass in the
-// InfoBarService for the relevant tab. This will create an XYZInfoBarDelegate,
-// create a platform-specific subclass of InfoBar to own it, and then call
-// InfoBarService::AddInfoBar() to give it ownership of the infobar.
-// During its life, the InfoBar may be shown and hidden as the owning tab is
-// switched between the foreground and background. Eventually, InfoBarService
-// will instruct the InfoBar to close itself. At this point, the InfoBar will
-// optionally animate closed; once it's no longer visible, it deletes itself,
-// destroying the InfoBarDelegate in the process.
-//
-// Thus, InfoBarDelegate and InfoBar implementations can assume they share
-// lifetimes, and not NULL-check each other; but if one needs to reach back into
-// the owning InfoBarService, it must check whether that's still possible.
class InfoBar : public gfx::AnimationDelegate {
public:
// These are the types passed as Details for infobar-related notifications.
- typedef InfoBar AddedDetails;
- typedef std::pair<InfoBar*, bool> RemovedDetails;
- typedef std::pair<InfoBar*, InfoBar*> ReplacedDetails;
+ typedef InfoBarDelegate AddedDetails;
+ typedef std::pair<InfoBarDelegate*, bool> RemovedDetails;
+ typedef std::pair<InfoBarDelegate*, InfoBarDelegate*> ReplacedDetails;
// Platforms must define these.
static const int kDefaultBarTargetHeight;
@@ -49,44 +36,32 @@
static const int kDefaultArrowTargetHalfWidth;
static const int kMaximumArrowTargetHalfWidth;
- explicit InfoBar(scoped_ptr<InfoBarDelegate> delegate);
+ InfoBar(InfoBarService* owner, InfoBarDelegate* delegate);
virtual ~InfoBar();
static SkColor GetTopColor(InfoBarDelegate::Type infobar_type);
static SkColor GetBottomColor(InfoBarDelegate::Type infobar_type);
- InfoBarService* owner() { return owner_; }
- InfoBarDelegate* delegate() { return delegate_.get(); }
- const InfoBarDelegate* delegate() const { return delegate_.get(); }
+ InfoBarDelegate* delegate() { return delegate_; }
void set_container(InfoBarContainer* container) { container_ = container; }
- // Sets |owner_|. This also calls StoreActiveEntryUniqueID() on |delegate_|.
- // This must only be called once as there's no way to extract an infobar from
- // its owner without deleting it, for reparenting in another tab.
- void SetOwner(InfoBarService* owner);
-
// Makes the infobar visible. If |animate| is true, the infobar is then
// animated to full size.
void Show(bool animate);
- // Makes the infobar hidden. If |animate| is false, the infobar is
- // immediately removed from the container, and, if now unowned, deleted. If
- // |animate| is true, the infobar is animated to zero size, ultimately
- // triggering a call to AnimationEnded().
+ // Makes the infobar hidden. If |animate| is true, the infobar is first
+ // animated to zero size. Once the infobar is hidden, it is removed from its
+ // container (triggering its deletion), and its delegate is closed.
void Hide(bool animate);
// Changes the target height of the arrow portion of the infobar. This has no
// effect once the infobar is animating closed.
void SetArrowTargetHeight(int height);
- // Notifies the infobar that it is no longer owned and should delete itself
- // once it is invisible.
+ // Notifies the infobar that it is no longer owned and should close its
+ // delegate once it is invisible.
void CloseSoon();
- // Forwards a close request to our owner. This is a no-op if we're already
- // unowned.
- void RemoveSelf();
-
// Changes the target height of the main ("bar") portion of the infobar.
void SetBarTargetHeight(int height);
@@ -100,11 +75,16 @@
// gfx::AnimationDelegate:
virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
+ // Forwards a close request to our owner.
+ // NOTE: Subclasses should not call this if we're already unowned.
+ void RemoveSelf();
+
// Given a control with size |prefsize|, returns the centered y position
// within us, taking into account animation so the control "slides in" (or
// out) as we animate open and closed.
int OffsetY(const gfx::Size& prefsize) const;
+ InfoBarService* owner() const { return owner_; }
const InfoBarContainer* container() const { return container_; }
InfoBarContainer* container() { return container_; }
gfx::SlideAnimation* animation() { return &animation_; }
@@ -113,7 +93,6 @@
// Platforms may optionally override these if they need to do work during
// processing of the given calls.
- virtual void PlatformSpecificSetOwner() {}
virtual void PlatformSpecificShow(bool animate) {}
virtual void PlatformSpecificHide(bool animate) {}
virtual void PlatformSpecificOnCloseSoon() {}
@@ -129,13 +108,13 @@
// |force_notify| is set.
void RecalculateHeights(bool force_notify);
- // Checks whether the infobar is unowned and done with all animations. If so,
- // notifies the container that it should remove this infobar, and deletes
- // itself.
+ // Checks whether we're closed. If so, notifies the container that it should
+ // remove us (which will cause the platform-specific code to asynchronously
+ // delete us) and closes the delegate.
void MaybeDelete();
InfoBarService* owner_;
- scoped_ptr<InfoBarDelegate> delegate_;
+ InfoBarDelegate* delegate_;
InfoBarContainer* container_;
gfx::SlideAnimation animation_;
« no previous file with comments | « trunk/src/chrome/browser/infobars/confirm_infobar_delegate.cc ('k') | trunk/src/chrome/browser/infobars/infobar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698