summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/notifications/balloon_collection_impl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/chromeos/notifications/balloon_collection_impl.cc')
-rw-r--r--chrome/browser/chromeos/notifications/balloon_collection_impl.cc64
1 files changed, 17 insertions, 47 deletions
diff --git a/chrome/browser/chromeos/notifications/balloon_collection_impl.cc b/chrome/browser/chromeos/notifications/balloon_collection_impl.cc
index 56a3d1c..14da2d6 100644
--- a/chrome/browser/chromeos/notifications/balloon_collection_impl.cc
+++ b/chrome/browser/chromeos/notifications/balloon_collection_impl.cc
@@ -7,7 +7,6 @@
#include <algorithm>
#include "base/logging.h"
-#include "base/stl_util-inl.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/chromeos/notifications/balloon_view.h"
#include "chrome/browser/chromeos/notifications/notification_panel.h"
@@ -24,17 +23,6 @@ namespace {
const int kVerticalEdgeMargin = 5;
const int kHorizontalEdgeMargin = 5;
-class NotificationMatcher {
- public:
- explicit NotificationMatcher(const Notification& notification)
- : notification_(notification) {}
- bool operator()(const Balloon* b) const {
- return notification_.IsSame(b->notification());
- }
- private:
- Notification notification_;
-};
-
} // namespace
namespace chromeos {
@@ -52,7 +40,7 @@ BalloonCollectionImpl::~BalloonCollectionImpl() {
void BalloonCollectionImpl::Add(const Notification& notification,
Profile* profile) {
Balloon* new_balloon = MakeBalloon(notification, profile);
- balloons_.push_back(new_balloon);
+ base_.Add(new_balloon);
new_balloon->Show();
notification_ui_->Add(new_balloon);
@@ -65,13 +53,13 @@ bool BalloonCollectionImpl::AddDOMUIMessageCallback(
const Notification& notification,
const std::string& message,
MessageCallback* callback) {
- Balloons::iterator iter = FindBalloon(notification);
- if (iter == balloons_.end()) {
+ Balloon* balloon = FindBalloon(notification);
+ if (!balloon) {
delete callback;
return false;
}
BalloonViewHost* host =
- static_cast<BalloonViewHost*>((*iter)->view()->GetHost());
+ static_cast<BalloonViewHost*>(balloon->view()->GetHost());
return host->AddDOMUIMessageCallback(message, callback);
}
@@ -80,10 +68,11 @@ void BalloonCollectionImpl::AddSystemNotification(
Profile* profile,
bool sticky,
bool control) {
+
Balloon* new_balloon = new Balloon(notification, profile, this);
new_balloon->set_view(
new chromeos::BalloonViewImpl(sticky, control, true));
- balloons_.push_back(new_balloon);
+ base_.Add(new_balloon);
new_balloon->Show();
notification_ui_->Add(new_balloon);
@@ -94,10 +83,9 @@ void BalloonCollectionImpl::AddSystemNotification(
bool BalloonCollectionImpl::UpdateNotification(
const Notification& notification) {
- Balloons::iterator iter = FindBalloon(notification);
- if (iter == balloons_.end())
+ Balloon* balloon = FindBalloon(notification);
+ if (!balloon)
return false;
- Balloon* balloon = *iter;
balloon->Update(notification);
notification_ui_->Update(balloon);
return true;
@@ -105,10 +93,9 @@ bool BalloonCollectionImpl::UpdateNotification(
bool BalloonCollectionImpl::UpdateAndShowNotification(
const Notification& notification) {
- Balloons::iterator iter = FindBalloon(notification);
- if (iter == balloons_.end())
+ Balloon* balloon = FindBalloon(notification);
+ if (!balloon)
return false;
- Balloon* balloon = *iter;
balloon->Update(notification);
bool updated = notification_ui_->Update(balloon);
DCHECK(updated);
@@ -116,15 +103,12 @@ bool BalloonCollectionImpl::UpdateAndShowNotification(
return true;
}
-bool BalloonCollectionImpl::Remove(const Notification& notification) {
- Balloons::iterator iter = FindBalloon(notification);
- if (iter != balloons_.end()) {
- // 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::RemoveById(const std::string& id) {
+ return base_.CloseById(id);
+}
+
+bool BalloonCollectionImpl::RemoveBySourceOrigin(const GURL& origin) {
+ return base_.CloseAllBySourceOrigin(origin);
}
bool BalloonCollectionImpl::HasSpace() const {
@@ -137,15 +121,9 @@ void BalloonCollectionImpl::ResizeBalloon(Balloon* balloon,
}
void BalloonCollectionImpl::OnBalloonClosed(Balloon* source) {
- // We want to free the balloon when finished.
- scoped_ptr<Balloon> closed(source);
-
notification_ui_->Remove(source);
+ base_.Remove(source);
- Balloons::iterator iter = FindBalloon(source->notification());
- if (iter != balloons_.end()) {
- balloons_.erase(iter);
- }
// There may be no listener in a unit test.
if (space_change_listener_)
space_change_listener_->OnBalloonSpaceChanged();
@@ -170,7 +148,6 @@ void BalloonCollectionImpl::Shutdown() {
// themselves from the parent.
DVLOG(1) << "Shutting down notification UI";
notification_ui_.reset();
- STLDeleteElements(&balloons_);
}
Balloon* BalloonCollectionImpl::MakeBalloon(const Notification& notification,
@@ -180,13 +157,6 @@ Balloon* BalloonCollectionImpl::MakeBalloon(const Notification& notification,
return new_balloon;
}
-std::deque<Balloon*>::iterator BalloonCollectionImpl::FindBalloon(
- const Notification& notification) {
- return std::find_if(balloons_.begin(),
- balloons_.end(),
- NotificationMatcher(notification));
-}
-
} // namespace chromeos
// static