summaryrefslogtreecommitdiffstats
path: root/chrome/browser/notifications/balloon_collection.cc
diff options
context:
space:
mode:
authorjohnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-12 03:28:01 +0000
committerjohnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-12 03:28:01 +0000
commitaaba38dc4f74a9e00232417e56bc4a8126aa3093 (patch)
treed8ca67d1dc1a6aedac4df8efff08f32c62ccb864 /chrome/browser/notifications/balloon_collection.cc
parenta358fd8076527132d37e0262823abe3807da16b8 (diff)
downloadchromium_src-aaba38dc4f74a9e00232417e56bc4a8126aa3093.zip
chromium_src-aaba38dc4f74a9e00232417e56bc4a8126aa3093.tar.gz
chromium_src-aaba38dc4f74a9e00232417e56bc4a8126aa3093.tar.bz2
Revert 65879 - When an extension is uninstalled, close all desktop notifications from that extension.
This change also refactors the balloon collection code to remove duplication between chrome and chromeos. Removes some gross removal code which was using fake notifications just to get the right ID. BUG=58266 TEST=open notifications from extension, uninstall extensions Review URL: http://codereview.chromium.org/4635007 TBR=johnnyg@chromium.org Review URL: http://codereview.chromium.org/4855002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65896 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/notifications/balloon_collection.cc')
-rw-r--r--chrome/browser/notifications/balloon_collection.cc59
1 files changed, 31 insertions, 28 deletions
diff --git a/chrome/browser/notifications/balloon_collection.cc b/chrome/browser/notifications/balloon_collection.cc
index 7d926ed..a125837 100644
--- a/chrome/browser/notifications/balloon_collection.cc
+++ b/chrome/browser/notifications/balloon_collection.cc
@@ -45,6 +45,7 @@ BalloonCollectionImpl::BalloonCollectionImpl()
}
BalloonCollectionImpl::~BalloonCollectionImpl() {
+ STLDeleteElements(&balloons_);
}
void BalloonCollectionImpl::Add(const Notification& notification,
@@ -58,11 +59,10 @@ void BalloonCollectionImpl::Add(const Notification& notification,
new_balloon->SetPosition(layout_.OffScreenLocation(), false);
new_balloon->Show();
#if USE_OFFSETS
- int count = base_.count();
- if (count > 0)
- new_balloon->set_offset(base_.balloons()[count - 1]->offset());
+ if (balloons_.size() > 0)
+ new_balloon->set_offset(balloons_[balloons_.size() - 1]->offset());
#endif
- base_.Add(new_balloon);
+ balloons_.push_back(new_balloon);
PositionBalloons(false);
// There may be no listener in a unit test.
@@ -74,24 +74,28 @@ void BalloonCollectionImpl::Add(const Notification& notification,
on_collection_changed_callback_->Run();
}
-bool BalloonCollectionImpl::RemoveById(const std::string& id) {
- return base_.CloseById(id);
-}
-
-bool BalloonCollectionImpl::RemoveBySourceOrigin(const GURL& origin) {
- return base_.CloseAllBySourceOrigin(origin);
+bool BalloonCollectionImpl::Remove(const Notification& notification) {
+ Balloons::iterator iter;
+ for (iter = balloons_.begin(); iter != balloons_.end(); ++iter) {
+ if (notification.IsSame((*iter)->notification())) {
+ // Balloon.CloseByScript() will cause OnBalloonClosed() to be called on
+ // this object, which will remove it from the collection and free it.
+ (*iter)->CloseByScript();
+ return true;
+ }
+ }
+ return false;
}
bool BalloonCollectionImpl::HasSpace() const {
- int count = base_.count();
- if (count < kMinAllowedBalloonCount)
+ if (count() < kMinAllowedBalloonCount)
return true;
int max_balloon_size = 0;
int total_size = 0;
layout_.GetMaxLinearSize(&max_balloon_size, &total_size);
- int current_max_size = max_balloon_size * count;
+ int current_max_size = max_balloon_size * count();
int max_allowed_size = static_cast<int>(total_size *
kPercentBalloonFillFactor);
return current_max_size < max_allowed_size - max_balloon_size;
@@ -110,16 +114,16 @@ void BalloonCollectionImpl::DisplayChanged() {
void BalloonCollectionImpl::OnBalloonClosed(Balloon* source) {
// We want to free the balloon when finished.
- const Balloons& balloons = base_.balloons();
- Balloons::const_iterator it = balloons.begin();
+ scoped_ptr<Balloon> closed(source);
+ Balloons::iterator it = balloons_.begin();
#if USE_OFFSETS
gfx::Point offset;
bool apply_offset = false;
- while (it != balloons.end()) {
+ while (it != balloons_.end()) {
if (*it == source) {
- ++it;
- if (it != balloons.end()) {
+ it = balloons_.erase(it);
+ if (it != balloons_.end()) {
apply_offset = true;
offset.set_y((source)->offset().y() - (*it)->offset().y() +
(*it)->content_size().height() - source->content_size().height());
@@ -134,9 +138,15 @@ void BalloonCollectionImpl::OnBalloonClosed(Balloon* source) {
// leaves the balloon area.
if (apply_offset)
AddMessageLoopObserver();
+#else
+ for (; it != balloons_.end(); ++it) {
+ if (*it == source) {
+ balloons_.erase(it);
+ break;
+ }
+ }
#endif
- base_.Remove(source);
PositionBalloons(true);
// There may be no listener in a unit test.
@@ -149,13 +159,9 @@ void BalloonCollectionImpl::OnBalloonClosed(Balloon* source) {
}
void BalloonCollectionImpl::PositionBalloonsInternal(bool reposition) {
- const Balloons& balloons = base_.balloons();
-
layout_.RefreshSystemMetrics();
gfx::Point origin = layout_.GetLayoutOrigin();
- for (Balloons::const_iterator it = balloons.begin();
- it != balloons.end();
- ++it) {
+ for (Balloons::iterator it = balloons_.begin(); it != balloons_.end(); ++it) {
gfx::Point upper_left = layout_.NextPosition((*it)->GetViewSize(), &origin);
(*it)->SetPosition(upper_left, reposition);
}
@@ -182,10 +188,7 @@ void BalloonCollectionImpl::CancelOffsets() {
// Unhook from listening to all UI events.
RemoveMessageLoopObserver();
- const Balloons& balloons = base_.balloons();
- for (Balloons::const_iterator it = balloons.begin();
- it != balloons.end();
- ++it)
+ for (Balloons::iterator it = balloons_.begin(); it != balloons_.end(); ++it)
(*it)->set_offset(gfx::Point(0, 0));
PositionBalloons(true);