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

Side by Side Diff: ui/message_center/notification_list.h

Issue 2314833002: Remove some uses of stl_util's STLDeleteContainerPointers. (Closed)
Patch Set: remove more 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_MESSAGE_CENTER_NOTIFICATION_LIST_H_ 5 #ifndef UI_MESSAGE_CENTER_NOTIFICATION_LIST_H_
6 #define UI_MESSAGE_CENTER_NOTIFICATION_LIST_H_ 6 #define UI_MESSAGE_CENTER_NOTIFICATION_LIST_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <list> 10 #include <list>
(...skipping 19 matching lines...) Expand all
30 30
31 namespace test { 31 namespace test {
32 class NotificationListTest; 32 class NotificationListTest;
33 } 33 }
34 34
35 class Notification; 35 class Notification;
36 class NotificationDelegate; 36 class NotificationDelegate;
37 struct NotifierId; 37 struct NotifierId;
38 38
39 // Comparers used to auto-sort the lists of Notifications. 39 // Comparers used to auto-sort the lists of Notifications.
40 struct MESSAGE_CENTER_EXPORT ComparePriorityTimestampSerial { 40 template <typename T>
41 bool operator()(Notification* n1, Notification* n2); 41 struct MESSAGE_CENTER_EXPORT CompareTimestampSerial {
42 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
43 if (n1->timestamp() > n2->timestamp()) // Newer come first.
44 return true;
45 if (n1->timestamp() < n2->timestamp())
46 return false;
47 if (n1->serial_number() > n2->serial_number()) // Newer come first.
48 return true;
49 if (n1->serial_number() < n2->serial_number())
50 return false;
51 return false;
52 }
42 }; 53 };
43 54
44 struct MESSAGE_CENTER_EXPORT CompareTimestampSerial { 55 template <typename T>
45 bool operator()(Notification* n1, Notification* n2); 56 struct MESSAGE_CENTER_EXPORT ComparePriorityTimestampSerial {
57 bool operator()(const T& n1, const T& n2) {
58 if (n1->priority() > n2->priority()) // Higher pri go first.
59 return true;
60 if (n1->priority() < n2->priority())
61 return false;
62 return CompareTimestampSerial<T>()(n1, n2);
63 }
46 }; 64 };
47 65
48 // A helper class to manage the list of notifications. 66 // A helper class to manage the list of notifications.
49 class MESSAGE_CENTER_EXPORT NotificationList { 67 class MESSAGE_CENTER_EXPORT NotificationList {
50 public: 68 public:
51 // Auto-sorted set. Matches the order in which Notifications are shown in 69 // Auto-sorted set. Matches the order in which Notifications are shown in
52 // Notification Center. 70 // Notification Center.
53 typedef std::set<Notification*, ComparePriorityTimestampSerial> Notifications; 71 using Notifications =
72 std::set<Notification*, ComparePriorityTimestampSerial<Notification*>>;
73 using OwnedNotifications =
74 std::set<std::unique_ptr<Notification>,
75 ComparePriorityTimestampSerial<std::unique_ptr<Notification>>>;
54 76
55 // Auto-sorted set used to return the Notifications to be shown as popup 77 // Auto-sorted set used to return the Notifications to be shown as popup
56 // toasts. 78 // toasts.
57 typedef std::set<Notification*, CompareTimestampSerial> PopupNotifications; 79 using PopupNotifications =
80 std::set<Notification*, CompareTimestampSerial<Notification*>>;
58 81
59 explicit NotificationList(MessageCenter* message_center); 82 explicit NotificationList(MessageCenter* message_center);
60 virtual ~NotificationList(); 83 virtual ~NotificationList();
61 84
62 // Makes a message "read". Collects the set of ids whose state have changed 85 // Makes a message "read". Collects the set of ids whose state have changed
63 // and set to |udpated_ids|. NULL if updated ids don't matter. 86 // and set to |udpated_ids|. NULL if updated ids don't matter.
64 void SetNotificationsShown(const NotificationBlockers& blockers, 87 void SetNotificationsShown(const NotificationBlockers& blockers,
65 std::set<std::string>* updated_ids); 88 std::set<std::string>* updated_ids);
66 89
67 void AddNotification(std::unique_ptr<Notification> notification); 90 void AddNotification(std::unique_ptr<Notification> notification);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 const NotificationBlockers& blockers) const; 158 const NotificationBlockers& blockers) const;
136 size_t NotificationCount(const NotificationBlockers& blockers) const; 159 size_t NotificationCount(const NotificationBlockers& blockers) const;
137 size_t UnreadCount(const NotificationBlockers& blockers) const; 160 size_t UnreadCount(const NotificationBlockers& blockers) const;
138 161
139 private: 162 private:
140 friend class NotificationListTest; 163 friend class NotificationListTest;
141 FRIEND_TEST_ALL_PREFIXES(NotificationListTest, 164 FRIEND_TEST_ALL_PREFIXES(NotificationListTest,
142 TestPushingShownNotification); 165 TestPushingShownNotification);
143 166
144 // Iterates through the list and returns the first notification matching |id|. 167 // Iterates through the list and returns the first notification matching |id|.
145 Notifications::iterator GetNotification(const std::string& id); 168 OwnedNotifications::iterator GetNotification(const std::string& id);
146 169
147 void EraseNotification(Notifications::iterator iter); 170 void EraseNotification(OwnedNotifications::iterator iter);
148 171
149 void PushNotification(std::unique_ptr<Notification> notification); 172 void PushNotification(std::unique_ptr<Notification> notification);
150 173
151 MessageCenter* message_center_; // owner 174 MessageCenter* message_center_; // owner
152 Notifications notifications_; 175 OwnedNotifications notifications_;
153 bool quiet_mode_; 176 bool quiet_mode_;
154 177
155 DISALLOW_COPY_AND_ASSIGN(NotificationList); 178 DISALLOW_COPY_AND_ASSIGN(NotificationList);
156 }; 179 };
157 180
158 } // namespace message_center 181 } // namespace message_center
159 182
160 #endif // UI_MESSAGE_CENTER_NOTIFICATION_LIST_H_ 183 #endif // UI_MESSAGE_CENTER_NOTIFICATION_LIST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698