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

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: lint fixes 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 65581)
+++ chrome/browser/chromeos/notifications/balloon_collection_impl.cc (working copy)
@@ -7,11 +7,11 @@
#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"
#include "chrome/browser/notifications/balloon.h"
+#include "chrome/browser/notifications/balloon_collection_util.h"
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/window_sizer.h"
#include "chrome/common/notification_service.h"
@@ -24,17 +24,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 +41,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 +54,13 @@
const Notification& notification,
const std::string& message,
MessageCallback* callback) {
- Balloons::iterator iter = FindBalloon(notification);
- if (iter == balloons_.end()) {
+ Balloon* balloon = base_.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 +69,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 +84,9 @@
bool BalloonCollectionImpl::UpdateNotification(
const Notification& notification) {
- Balloons::iterator iter = FindBalloon(notification);
- if (iter == balloons_.end())
+ Balloon* balloon = base_.FindBalloon(notification);
+ if (!balloon)
return false;
- Balloon* balloon = *iter;
balloon->Update(notification);
notification_ui_->Update(balloon);
return true;
@@ -105,8 +94,8 @@
bool BalloonCollectionImpl::UpdateAndShowNotification(
const Notification& notification) {
- Balloons::iterator iter = FindBalloon(notification);
- if (iter == balloons_.end())
+ Balloon* balloon = base_.FindBalloon(notification);
+ if (!balloon)
return false;
Balloon* balloon = *iter;
balloon->Update(notification);
@@ -116,17 +105,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_.RemoveById(id);
}
+bool BalloonCollectionImpl::RemoveBySourceOrigin(const GURL& origin) {
+ return base_.RemoveAllBySourceOrigin(origin);
+}
+
bool BalloonCollectionImpl::HasSpace() const {
return true;
}
@@ -137,15 +123,9 @@
}
void BalloonCollectionImpl::OnBalloonClosed(Balloon* source) {
- // We want to free the balloon when finished.
- scoped_ptr<Balloon> closed(source);
-
+ base_.Remove(source);
Andrew T Wilson (Slow) 2010/11/11 01:07:44 Previously this routine was freeing |source| - who
John Gregg 2010/11/11 18:13:51 It is freed by base_.Remove(), so I reordered them
notification_ui_->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 +150,6 @@
// themselves from the parent.
DVLOG(1) << "Shutting down notification UI";
notification_ui_.reset();
- STLDeleteElements(&balloons_);
}
Balloon* BalloonCollectionImpl::MakeBalloon(const Notification& notification,
@@ -180,13 +159,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

Powered by Google App Engine
This is Rietveld 408576698