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
3 // found in the LICENSE file.
5 #ifndef UI_MESSAGE_CENTER_NOTIFICATION_LIST_H_
6 #define UI_MESSAGE_CENTER_NOTIFICATION_LIST_H_
12 #include "base/strings/string16.h"
13 #include "base/time/time.h"
14 #include "base/timer/timer.h"
15 #include "ui/gfx/image/image.h"
16 #include "ui/gfx/native_widget_types.h"
17 #include "ui/message_center/message_center_export.h"
18 #include "ui/message_center/notification.h"
19 #include "ui/message_center/notification_types.h"
22 class DictionaryValue
;
25 namespace message_center
{
27 class NotificationBlocker
;
28 class NotificationDelegate
;
31 class NotificationListTest
;
34 // Comparers used to auto-sort the lists of Notifications.
35 struct MESSAGE_CENTER_EXPORT ComparePriorityTimestampSerial
{
36 bool operator()(Notification
* n1
, Notification
* n2
);
39 struct CompareTimestampSerial
{
40 bool operator()(Notification
* n1
, Notification
* n2
);
43 // A helper class to manage the list of notifications.
44 class MESSAGE_CENTER_EXPORT NotificationList
{
46 // Auto-sorted set. Matches the order in which Notifications are shown in
47 // Notification Center.
48 typedef std::set
<Notification
*, ComparePriorityTimestampSerial
> Notifications
;
50 // Auto-sorted set used to return the Notifications to be shown as popup
52 typedef std::set
<Notification
*, CompareTimestampSerial
> PopupNotifications
;
54 explicit NotificationList();
55 virtual ~NotificationList();
57 // Affects whether or not a message has been "read". Collects the set of
58 // ids whose state have changed and set to |udpated_ids|. NULL if updated
60 void SetMessageCenterVisible(bool visible
,
61 std::set
<std::string
>* updated_ids
);
63 void AddNotification(scoped_ptr
<Notification
> notification
);
65 void UpdateNotificationMessage(const std::string
& old_id
,
66 scoped_ptr
<Notification
> new_notification
);
68 void RemoveNotification(const std::string
& id
);
70 void RemoveAllNotifications();
72 Notifications
GetNotificationsByNotifierId(const NotifierId
& notifier_id
);
74 // Returns true if the notification exists and was updated.
75 bool SetNotificationIcon(const std::string
& notification_id
,
76 const gfx::Image
& image
);
78 // Returns true if the notification exists and was updated.
79 bool SetNotificationImage(const std::string
& notification_id
,
80 const gfx::Image
& image
);
82 // Returns true if the notification and button exist and were updated.
83 bool SetNotificationButtonIcon(const std::string
& notification_id
,
85 const gfx::Image
& image
);
87 // Returns true if |id| matches a notification in the list.
88 bool HasNotification(const std::string
& id
);
90 // Returns true if |id| matches a notification in the list and that
91 // notification's type matches the given type.
92 bool HasNotificationOfType(const std::string
& id
,
93 const NotificationType type
);
95 // Returns false if the first notification has been shown as a popup (which
96 // means that all notifications have been shown).
97 bool HasPopupNotifications(const std::vector
<NotificationBlocker
*>& blockers
);
99 // Returns the recent notifications of the priority higher then LOW,
100 // that have not been shown as a popup. kMaxVisiblePopupNotifications are
101 // used to limit the number of notifications for the DEFAULT priority.
102 // It also stores the list of notification ids which is blocked by |blockers|
103 // to |blocked_ids|. |blocked_ids| can be NULL if the caller doesn't care
104 // which notifications are blocked.
105 PopupNotifications
GetPopupNotifications(
106 const std::vector
<NotificationBlocker
*>& blockers
,
107 std::list
<std::string
>* blocked_ids
);
109 // Marks a specific popup item as shown. Set |mark_notification_as_read| to
110 // true in case marking the notification as read too.
111 void MarkSinglePopupAsShown(const std::string
& id
,
112 bool mark_notification_as_read
);
114 // Marks a specific popup item as displayed.
115 void MarkSinglePopupAsDisplayed(const std::string
& id
);
117 // Marks the specified notification as expanded in the notification center.
118 void MarkNotificationAsExpanded(const std::string
& id
);
120 NotificationDelegate
* GetNotificationDelegate(const std::string
& id
);
122 bool quiet_mode() const { return quiet_mode_
; }
124 // Sets the current quiet mode status to |quiet_mode|.
125 void SetQuietMode(bool quiet_mode
);
127 // Sets the current quiet mode to true. The quiet mode will expire in the
128 // specified time-delta from now.
129 void EnterQuietModeWithExpire(const base::TimeDelta
& expires_in
);
131 // Returns all notifications, in a (priority-timestamp) order. Suitable for
132 // rendering notifications in a NotificationCenter.
133 const Notifications
& GetNotifications();
134 size_t NotificationCount() const;
135 size_t unread_count() const { return unread_count_
; }
136 bool is_message_center_visible() const { return message_center_visible_
; }
139 friend class test::NotificationListTest
;
141 // Iterates through the list and returns the first notification matching |id|.
142 Notifications::iterator
GetNotification(const std::string
& id
);
144 void EraseNotification(Notifications::iterator iter
);
146 void PushNotification(scoped_ptr
<Notification
> notification
);
148 Notifications notifications_
;
149 bool message_center_visible_
;
150 size_t unread_count_
;
153 DISALLOW_COPY_AND_ASSIGN(NotificationList
);
156 } // namespace message_center
158 #endif // UI_MESSAGE_CENTER_NOTIFICATION_LIST_H_