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..fb0c7876be308ab5af732a5a16d9ba5bbc25bc94 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 MESSAGE_CENTER_EXPORT CompareTimestampSerial { |
+ bool operator()(const T& n1, const T& n2) { |
Nico
2016/09/08 17:32:00
why move this inline?
how does _EXPORT on a templ
Avi (use Gerrit)
2016/09/13 14:36:13
Templates; don't I need to define it all to use th
|
+ if (n1->timestamp() > n2->timestamp()) // Newer come first. |
+ 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 MESSAGE_CENTER_EXPORT 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); |