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

Unified Diff: chrome/browser/chromeos/notifications/balloon_collection_impl.cc

Issue 4635007: When an extension is uninstalled, close all desktop notifications from that e... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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: chrome/browser/chromeos/notifications/balloon_collection_impl.cc
===================================================================
--- chrome/browser/chromeos/notifications/balloon_collection_impl.cc (revision 66634)
+++ chrome/browser/chromeos/notifications/balloon_collection_impl.cc (working copy)
@@ -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 @@
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 @@
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 @@
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 @@
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 @@
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::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,17 +103,14 @@
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 {
return true;
}
@@ -137,15 +121,9 @@
}
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 @@
// 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 @@
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
« no previous file with comments | « chrome/browser/chromeos/notifications/balloon_collection_impl.h ('k') | chrome/browser/chromeos/notifications/balloon_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698