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

Unified Diff: ui/message_center/notification_list.h

Issue 2314833002: Remove some uses of stl_util's STLDeleteContainerPointers. (Closed)
Patch Set: removed a few items Created 4 years, 3 months 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: ui/message_center/notification_list.h
diff --git a/ui/message_center/notification_list.h b/ui/message_center/notification_list.h
index f52217b0787b9dde14c367812112e7533f2851b6..ee7cac7a5f98e7b4f428b022e1f5619674423c08 100644
--- a/ui/message_center/notification_list.h
+++ b/ui/message_center/notification_list.h
@@ -37,12 +37,30 @@ class NotificationDelegate;
struct NotifierId;
// Comparers used to auto-sort the lists of Notifications.
-struct MESSAGE_CENTER_EXPORT ComparePriorityTimestampSerial {
- bool operator()(Notification* n1, Notification* n2);
+template <typename T>
+struct CompareTimestampSerial {
+ bool operator()(const T& n1, const T& n2) {
+ if (n1->timestamp() > n2->timestamp()) // Newer come first.
Nico 2016/09/15 16:07:16 I think making this a full template is confusing,
Avi (use Gerrit) 2016/09/15 19:53:45 That doesn't actually work. error: template argum
+ return true;
+ if (n1->timestamp() < n2->timestamp())
+ return false;
+ if (n1->serial_number() > n2->serial_number()) // Newer come first.
+ return true;
+ if (n1->serial_number() < n2->serial_number())
+ return false;
+ return false;
+ }
};
-struct MESSAGE_CENTER_EXPORT CompareTimestampSerial {
- bool operator()(Notification* n1, Notification* n2);
+template <typename T>
+struct ComparePriorityTimestampSerial {
+ bool operator()(const T& n1, const T& n2) {
+ if (n1->priority() > n2->priority()) // Higher pri go first.
+ return true;
+ if (n1->priority() < n2->priority())
+ return false;
+ return CompareTimestampSerial<T>()(n1, n2);
+ }
};
// A helper class to manage the list of notifications.
@@ -50,11 +68,16 @@ class MESSAGE_CENTER_EXPORT NotificationList {
public:
// Auto-sorted set. Matches the order in which Notifications are shown in
// Notification Center.
- typedef std::set<Notification*, ComparePriorityTimestampSerial> Notifications;
+ using Notifications =
+ std::set<Notification*, ComparePriorityTimestampSerial<Notification*>>;
+ using OwnedNotifications =
+ std::set<std::unique_ptr<Notification>,
+ ComparePriorityTimestampSerial<std::unique_ptr<Notification>>>;
// Auto-sorted set used to return the Notifications to be shown as popup
// toasts.
- typedef std::set<Notification*, CompareTimestampSerial> PopupNotifications;
+ using PopupNotifications =
+ std::set<Notification*, CompareTimestampSerial<Notification*>>;
explicit NotificationList(MessageCenter* message_center);
virtual ~NotificationList();
@@ -142,14 +165,14 @@ class MESSAGE_CENTER_EXPORT NotificationList {
TestPushingShownNotification);
// Iterates through the list and returns the first notification matching |id|.
- Notifications::iterator GetNotification(const std::string& id);
+ OwnedNotifications::iterator GetNotification(const std::string& id);
- void EraseNotification(Notifications::iterator iter);
+ void EraseNotification(OwnedNotifications::iterator iter);
void PushNotification(std::unique_ptr<Notification> notification);
MessageCenter* message_center_; // owner
- Notifications notifications_;
+ OwnedNotifications notifications_;
bool quiet_mode_;
DISALLOW_COPY_AND_ASSIGN(NotificationList);

Powered by Google App Engine
This is Rietveld 408576698