Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <list> | 8 #include <set> |
| 9 #include <map> | |
| 10 #include <string> | 9 #include <string> |
| 11 | 10 |
| 12 #include "base/string16.h" | 11 #include "base/string16.h" |
| 13 #include "base/time.h" | 12 #include "base/time.h" |
| 14 #include "base/timer.h" | 13 #include "base/timer.h" |
| 15 #include "ui/gfx/image/image_skia.h" | 14 #include "ui/gfx/image/image_skia.h" |
| 16 #include "ui/gfx/native_widget_types.h" | 15 #include "ui/gfx/native_widget_types.h" |
| 17 #include "ui/message_center/message_center_export.h" | 16 #include "ui/message_center/message_center_export.h" |
| 18 #include "ui/message_center/notification.h" | 17 #include "ui/message_center/notification.h" |
| 19 #include "ui/notifications/notification_types.h" | 18 #include "ui/message_center/notification_types.h" |
| 20 | 19 |
| 21 namespace base { | 20 namespace base { |
| 22 class DictionaryValue; | 21 class DictionaryValue; |
| 23 } | 22 } |
| 24 | 23 |
| 25 namespace message_center { | 24 namespace message_center { |
| 26 | 25 |
| 26 // Comparers used to auto-sort the lists of Notifications. | |
| 27 struct ComparePriorityTimestampSerial { | |
| 28 bool operator()(Notification* n1, Notification* n2); | |
|
Jun Mukai
2013/02/23 01:19:10
nit: 2 space indent?
Dmitry Titov
2013/02/23 01:35:48
Done.
| |
| 29 }; | |
| 30 struct CompareTimestampSerial { | |
| 31 bool operator()(Notification* n1, Notification* n2); | |
|
Jun Mukai
2013/02/23 01:19:10
ditto
Dmitry Titov
2013/02/23 01:35:48
Done.
| |
| 32 }; | |
| 33 | |
| 27 // A helper class to manage the list of notifications. | 34 // A helper class to manage the list of notifications. |
| 28 class MESSAGE_CENTER_EXPORT NotificationList { | 35 class MESSAGE_CENTER_EXPORT NotificationList { |
| 29 public: | 36 public: |
| 30 typedef std::list<Notification> Notifications; | 37 // Auto-sorted set. Matches the order in which Notifications are shown in |
| 38 // Notification Center. | |
| 39 typedef std::set<Notification*, ComparePriorityTimestampSerial> Notifications; | |
| 40 | |
| 41 // Auto-sorted set used to return the Notifications to be shown as popup | |
| 42 // toasts. | |
| 43 typedef std::set<Notification*, CompareTimestampSerial> PopupNotifications; | |
| 31 | 44 |
| 32 class MESSAGE_CENTER_EXPORT Delegate { | 45 class MESSAGE_CENTER_EXPORT Delegate { |
| 33 public: | 46 public: |
| 34 Delegate() {} | 47 Delegate() {} |
| 35 virtual ~Delegate() {} | 48 virtual ~Delegate() {} |
| 36 | 49 |
| 37 // Removes notifications | 50 // Removes notifications |
| 38 virtual void SendRemoveNotification(const std::string& id) = 0; | 51 virtual void SendRemoveNotification(const std::string& id) = 0; |
| 39 virtual void SendRemoveAllNotifications() = 0; | 52 virtual void SendRemoveAllNotifications() = 0; |
| 40 | 53 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 62 // Returns the list of notifications to display. | 75 // Returns the list of notifications to display. |
| 63 virtual NotificationList* GetNotificationList() = 0; | 76 virtual NotificationList* GetNotificationList() = 0; |
| 64 }; | 77 }; |
| 65 | 78 |
| 66 explicit NotificationList(Delegate* delegate); | 79 explicit NotificationList(Delegate* delegate); |
| 67 virtual ~NotificationList(); | 80 virtual ~NotificationList(); |
| 68 | 81 |
| 69 // Affects whether or not a message has been "read". | 82 // Affects whether or not a message has been "read". |
| 70 void SetMessageCenterVisible(bool visible); | 83 void SetMessageCenterVisible(bool visible); |
| 71 | 84 |
| 72 void AddNotification(ui::notifications::NotificationType type, | 85 void AddNotification(NotificationType type, |
| 73 const std::string& id, | 86 const std::string& id, |
| 74 const string16& title, | 87 const string16& title, |
| 75 const string16& message, | 88 const string16& message, |
| 76 const string16& display_source, | 89 const string16& display_source, |
| 77 const std::string& extension_id, | 90 const std::string& extension_id, |
| 78 const base::DictionaryValue* optional_fields); | 91 const base::DictionaryValue* optional_fields); |
| 79 | 92 |
| 80 void UpdateNotificationMessage(const std::string& old_id, | 93 void UpdateNotificationMessage(const std::string& old_id, |
| 81 const std::string& new_id, | 94 const std::string& new_id, |
| 82 const string16& title, | 95 const string16& title, |
| 83 const string16& message, | 96 const string16& message, |
| 84 const base::DictionaryValue* optional_fields); | 97 const base::DictionaryValue* optional_fields); |
| 85 | 98 |
| 86 // Returns true if the notification was removed. | 99 void RemoveNotification(const std::string& id); |
| 87 bool RemoveNotification(const std::string& id); | |
| 88 | 100 |
| 89 void RemoveAllNotifications(); | 101 void RemoveAllNotifications(); |
| 90 | 102 |
| 91 void SendRemoveNotificationsBySource(const std::string& id); | 103 void SendRemoveNotificationsBySource(const std::string& id); |
| 92 | 104 |
| 93 void SendRemoveNotificationsByExtension(const std::string& id); | 105 void SendRemoveNotificationsByExtension(const std::string& id); |
| 94 | 106 |
| 95 // Returns true if the notification exists and was updated. | 107 // Returns true if the notification exists and was updated. |
| 96 bool SetNotificationIcon(const std::string& notification_id, | 108 bool SetNotificationIcon(const std::string& notification_id, |
| 97 const gfx::ImageSkia& image); | 109 const gfx::ImageSkia& image); |
| 98 | 110 |
| 99 // Returns true if the notification exists and was updated. | 111 // Returns true if the notification exists and was updated. |
| 100 bool SetNotificationImage(const std::string& notification_id, | 112 bool SetNotificationImage(const std::string& notification_id, |
| 101 const gfx::ImageSkia& image); | 113 const gfx::ImageSkia& image); |
| 102 | 114 |
| 103 // Returns true if the notification and button exist and were updated. | 115 // Returns true if the notification and button exist and were updated. |
| 104 bool SetNotificationButtonIcon(const std::string& notification_id, | 116 bool SetNotificationButtonIcon(const std::string& notification_id, |
| 105 int button_index, | 117 int button_index, |
| 106 const gfx::ImageSkia& image); | 118 const gfx::ImageSkia& image); |
| 107 | 119 |
| 108 bool HasNotification(const std::string& id); | 120 bool HasNotification(const std::string& id); |
| 109 | 121 |
| 110 // Returns false if the first notification has been shown as a popup (which | 122 // Returns false if the first notification has been shown as a popup (which |
| 111 // means that all notifications have been shown). | 123 // means that all notifications have been shown). |
| 112 bool HasPopupNotifications(); | 124 bool HasPopupNotifications(); |
| 113 | 125 |
| 114 // Modifies |notifications| to contain the |kMaxVisiblePopupNotifications| | 126 // Returns the recent notifications of the priority higher then LOW, |
| 115 // least recent notifications that have not been shown as a popup. | 127 // that have not been shown as a popup. kMaxVisiblePopupNotifications are |
| 116 void GetPopupNotifications(Notifications* notifications); | 128 // used to limit the number of notifications for the DEFAULT priority. |
| 129 // The returned list is sorted by timestamp, newer first. | |
| 130 PopupNotifications GetPopupNotifications(); | |
| 117 | 131 |
| 118 // Marks the popups for the |priority| as shown. | 132 // Marks the popups for the |priority| as shown. |
| 119 void MarkPopupsAsShown(int priority); | 133 void MarkPopupsAsShown(int priority); |
| 120 | 134 |
| 121 // Marks a specific popup item as shown. Set |mark_notification_as_read| to | 135 // Marks a specific popup item as shown. Set |mark_notification_as_read| to |
| 122 // true in case marking the notification as read too. | 136 // true in case marking the notification as read too. |
| 123 void MarkSinglePopupAsShown(const std::string& id, | 137 void MarkSinglePopupAsShown(const std::string& id, |
| 124 bool mark_notification_as_read); | 138 bool mark_notification_as_read); |
| 125 | 139 |
| 126 bool quiet_mode() const { return quiet_mode_; } | 140 bool quiet_mode() const { return quiet_mode_; } |
| 127 | 141 |
| 128 // Sets the current quiet mode status to |quiet_mode|. The new status is not | 142 // Sets the current quiet mode status to |quiet_mode|. The new status is not |
| 129 // expired. | 143 // expired. |
| 130 void SetQuietMode(bool quiet_mode); | 144 void SetQuietMode(bool quiet_mode); |
| 131 | 145 |
| 132 // Sets the current quiet mode to true. The quiet mode will expire in the | 146 // Sets the current quiet mode to true. The quiet mode will expire in the |
| 133 // specified time-delta from now. | 147 // specified time-delta from now. |
| 134 void EnterQuietModeWithExpire(const base::TimeDelta& expires_in); | 148 void EnterQuietModeWithExpire(const base::TimeDelta& expires_in); |
| 135 | 149 |
| 136 void GetNotifications(Notifications* notifications) const; | 150 // Returns all notifications, in a (priority-timestamp) order. Suitable for |
| 151 // rendering notifications in a NotificationCenter. | |
| 152 const Notifications& GetNotifications(); | |
| 137 size_t NotificationCount() const; | 153 size_t NotificationCount() const; |
| 138 size_t unread_count() const { return unread_count_; } | 154 size_t unread_count() const { return unread_count_; } |
| 139 | 155 |
| 140 static const size_t kMaxVisiblePopupNotifications; | 156 static const size_t kMaxVisiblePopupNotifications; |
| 141 static const size_t kMaxVisibleMessageCenterNotifications; | 157 static const size_t kMaxVisibleMessageCenterNotifications; |
| 142 | 158 |
| 143 private: | 159 private: |
| 144 typedef std::map<int, Notifications> NotificationMap; | 160 // Iterates through the list and returns the first notification matching |id|. |
| 145 | 161 Notifications::iterator GetNotification(const std::string& id); |
| 146 // Iterates through the list and stores the first notification matching |id| | |
| 147 // (should always be unique) to |iter|. Returns true if it's found. | |
| 148 bool GetNotification(const std::string& id, Notifications::iterator* iter); | |
| 149 | 162 |
| 150 void EraseNotification(Notifications::iterator iter); | 163 void EraseNotification(Notifications::iterator iter); |
| 151 | 164 |
| 152 void PushNotification(Notification& notification); | 165 void PushNotification(scoped_ptr<Notification> notification); |
| 153 | |
| 154 // Returns the recent notifications of the |priority| that have not been shown | |
| 155 // as a popup. kMaxVisiblePopupNotifications are used to limit the number of | |
| 156 // notifications for the default priority. | |
| 157 void GetPopupIterators(int priority, | |
| 158 Notifications::iterator* first, | |
| 159 Notifications::iterator* last); | |
| 160 | |
| 161 // Given a dictionary of optional notification fields (or NULL), unpacks all | |
| 162 // recognized values into the given Notification struct. We assume prior | |
| 163 // proper initialization of |notification| fields that correspond to | |
| 164 // |optional_fields|. | |
| 165 void UnpackOptionalFields(const base::DictionaryValue* optional_fields, | |
| 166 Notification* notification); | |
| 167 | 166 |
| 168 // Sets the current quiet mode status to |quiet_mode|. | 167 // Sets the current quiet mode status to |quiet_mode|. |
| 169 void SetQuietModeInternal(bool quiet_mode); | 168 void SetQuietModeInternal(bool quiet_mode); |
| 170 | 169 |
| 171 Delegate* delegate_; | 170 Delegate* delegate_; |
| 172 NotificationMap notifications_; | 171 Notifications notifications_; |
| 173 bool message_center_visible_; | 172 bool message_center_visible_; |
| 174 size_t unread_count_; | 173 size_t unread_count_; |
| 175 bool quiet_mode_; | 174 bool quiet_mode_; |
| 176 scoped_ptr<base::OneShotTimer<NotificationList> > quiet_mode_timer_; | 175 scoped_ptr<base::OneShotTimer<NotificationList> > quiet_mode_timer_; |
| 177 | 176 |
| 178 DISALLOW_COPY_AND_ASSIGN(NotificationList); | 177 DISALLOW_COPY_AND_ASSIGN(NotificationList); |
| 179 }; | 178 }; |
| 180 | 179 |
| 181 } // namespace message_center | 180 } // namespace message_center |
| 182 | 181 |
| 183 #endif // UI_MESSAGE_CENTER_NOTIFICATION_LIST_H_ | 182 #endif // UI_MESSAGE_CENTER_NOTIFICATION_LIST_H_ |
| OLD | NEW |