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 <list> |
| 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 |
| 27 // A helper class to manage the list of notifications. | 26 // A helper class to manage the list of notifications. |
| 28 class MESSAGE_CENTER_EXPORT NotificationList { | 27 class MESSAGE_CENTER_EXPORT NotificationList { |
| 29 public: | 28 public: |
| 30 typedef std::list<Notification> Notifications; | 29 // A 'list' because we use sort() to ensure display order by priority/time. |
|
dewittj
2013/02/20 23:47:54
What if we use a std::set<Notification*> which is
Dmitry Titov
2013/02/23 00:58:51
Done.
| |
| 30 typedef std::list<Notification*> Notifications; | |
| 31 | 31 |
| 32 class MESSAGE_CENTER_EXPORT Delegate { | 32 class MESSAGE_CENTER_EXPORT Delegate { |
| 33 public: | 33 public: |
| 34 Delegate() {} | 34 Delegate() {} |
| 35 virtual ~Delegate() {} | 35 virtual ~Delegate() {} |
| 36 | 36 |
| 37 // Removes notifications | 37 // Removes notifications |
| 38 virtual void SendRemoveNotification(const std::string& id) = 0; | 38 virtual void SendRemoveNotification(const std::string& id) = 0; |
| 39 virtual void SendRemoveAllNotifications() = 0; | 39 virtual void SendRemoveAllNotifications() = 0; |
| 40 | 40 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 62 // Returns the list of notifications to display. | 62 // Returns the list of notifications to display. |
| 63 virtual NotificationList* GetNotificationList() = 0; | 63 virtual NotificationList* GetNotificationList() = 0; |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 explicit NotificationList(Delegate* delegate); | 66 explicit NotificationList(Delegate* delegate); |
| 67 virtual ~NotificationList(); | 67 virtual ~NotificationList(); |
| 68 | 68 |
| 69 // Affects whether or not a message has been "read". | 69 // Affects whether or not a message has been "read". |
| 70 void SetMessageCenterVisible(bool visible); | 70 void SetMessageCenterVisible(bool visible); |
| 71 | 71 |
| 72 void AddNotification(ui::notifications::NotificationType type, | 72 void AddNotification(NotificationType type, |
| 73 const std::string& id, | 73 const std::string& id, |
| 74 const string16& title, | 74 const string16& title, |
| 75 const string16& message, | 75 const string16& message, |
| 76 const string16& display_source, | 76 const string16& display_source, |
| 77 const std::string& extension_id, | 77 const std::string& extension_id, |
| 78 const base::DictionaryValue* optional_fields); | 78 const base::DictionaryValue* optional_fields); |
| 79 | 79 |
| 80 void UpdateNotificationMessage(const std::string& old_id, | 80 void UpdateNotificationMessage(const std::string& old_id, |
| 81 const std::string& new_id, | 81 const std::string& new_id, |
| 82 const string16& title, | 82 const string16& title, |
| 83 const string16& message, | 83 const string16& message, |
| 84 const base::DictionaryValue* optional_fields); | 84 const base::DictionaryValue* optional_fields); |
| 85 | 85 |
| 86 // Returns true if the notification was removed. | 86 void RemoveNotification(const std::string& id); |
| 87 bool RemoveNotification(const std::string& id); | |
| 88 | 87 |
| 89 void RemoveAllNotifications(); | 88 void RemoveAllNotifications(); |
| 90 | 89 |
| 91 void SendRemoveNotificationsBySource(const std::string& id); | 90 void SendRemoveNotificationsBySource(const std::string& id); |
| 92 | 91 |
| 93 void SendRemoveNotificationsByExtension(const std::string& id); | 92 void SendRemoveNotificationsByExtension(const std::string& id); |
| 94 | 93 |
| 95 // Returns true if the notification exists and was updated. | 94 // Returns true if the notification exists and was updated. |
| 96 bool SetNotificationIcon(const std::string& notification_id, | 95 bool SetNotificationIcon(const std::string& notification_id, |
| 97 const gfx::ImageSkia& image); | 96 const gfx::ImageSkia& image); |
| 98 | 97 |
| 99 // Returns true if the notification exists and was updated. | 98 // Returns true if the notification exists and was updated. |
| 100 bool SetNotificationImage(const std::string& notification_id, | 99 bool SetNotificationImage(const std::string& notification_id, |
| 101 const gfx::ImageSkia& image); | 100 const gfx::ImageSkia& image); |
| 102 | 101 |
| 103 // Returns true if the notification and button exist and were updated. | 102 // Returns true if the notification and button exist and were updated. |
| 104 bool SetNotificationButtonIcon(const std::string& notification_id, | 103 bool SetNotificationButtonIcon(const std::string& notification_id, |
| 105 int button_index, | 104 int button_index, |
| 106 const gfx::ImageSkia& image); | 105 const gfx::ImageSkia& image); |
| 107 | 106 |
| 108 bool HasNotification(const std::string& id); | 107 bool HasNotification(const std::string& id); |
| 109 | 108 |
| 110 // Returns false if the first notification has been shown as a popup (which | 109 // Returns false if the first notification has been shown as a popup (which |
| 111 // means that all notifications have been shown). | 110 // means that all notifications have been shown). |
| 112 bool HasPopupNotifications(); | 111 bool HasPopupNotifications(); |
| 113 | 112 |
| 114 // Modifies |notifications| to contain the |kMaxVisiblePopupNotifications| | 113 // Returns the recent notifications of the priority higher then LOW, |
| 115 // least recent notifications that have not been shown as a popup. | 114 // that have not been shown as a popup. kMaxVisiblePopupNotifications are |
| 116 void GetPopupNotifications(Notifications* notifications); | 115 // used to limit the number of notifications for the DEFAULT priority. |
| 116 Notifications GetPopupNotifications(); | |
| 117 | 117 |
| 118 // Marks the popups for the |priority| as shown. | 118 // Marks the popups for the |priority| as shown. |
| 119 void MarkPopupsAsShown(int priority); | 119 void MarkPopupsAsShown(int priority); |
| 120 | 120 |
| 121 // Marks a specific popup item as shown. Set |mark_notification_as_read| to | 121 // Marks a specific popup item as shown. Set |mark_notification_as_read| to |
| 122 // true in case marking the notification as read too. | 122 // true in case marking the notification as read too. |
| 123 void MarkSinglePopupAsShown(const std::string& id, | 123 void MarkSinglePopupAsShown(const std::string& id, |
| 124 bool mark_notification_as_read); | 124 bool mark_notification_as_read); |
| 125 | 125 |
| 126 bool quiet_mode() const { return quiet_mode_; } | 126 bool quiet_mode() const { return quiet_mode_; } |
| 127 | 127 |
| 128 // Sets the current quiet mode status to |quiet_mode|. The new status is not | 128 // Sets the current quiet mode status to |quiet_mode|. The new status is not |
| 129 // expired. | 129 // expired. |
| 130 void SetQuietMode(bool quiet_mode); | 130 void SetQuietMode(bool quiet_mode); |
| 131 | 131 |
| 132 // Sets the current quiet mode to true. The quiet mode will expire in the | 132 // Sets the current quiet mode to true. The quiet mode will expire in the |
| 133 // specified time-delta from now. | 133 // specified time-delta from now. |
| 134 void EnterQuietModeWithExpire(const base::TimeDelta& expires_in); | 134 void EnterQuietModeWithExpire(const base::TimeDelta& expires_in); |
| 135 | 135 |
| 136 void GetNotifications(Notifications* notifications) const; | 136 // Returns all notifications, in a (priority-timestamp) order. |
| 137 const Notifications& GetNotifications(); | |
| 137 size_t NotificationCount() const; | 138 size_t NotificationCount() const; |
| 138 size_t unread_count() const { return unread_count_; } | 139 size_t unread_count() const { return unread_count_; } |
| 139 | 140 |
| 140 static const size_t kMaxVisiblePopupNotifications; | 141 static const size_t kMaxVisiblePopupNotifications; |
| 141 static const size_t kMaxVisibleMessageCenterNotifications; | 142 static const size_t kMaxVisibleMessageCenterNotifications; |
| 142 | 143 |
| 143 private: | 144 private: |
| 144 typedef std::map<int, Notifications> NotificationMap; | 145 // Iterates through the list and returns the first notification matching |id|. |
| 145 | 146 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 | 147 |
| 150 void EraseNotification(Notifications::iterator iter); | 148 void EraseNotification(Notifications::iterator iter); |
| 151 | 149 |
| 152 void PushNotification(Notification& notification); | 150 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 | 151 |
| 168 // Sets the current quiet mode status to |quiet_mode|. | 152 // Sets the current quiet mode status to |quiet_mode|. |
| 169 void SetQuietModeInternal(bool quiet_mode); | 153 void SetQuietModeInternal(bool quiet_mode); |
| 170 | 154 |
| 171 Delegate* delegate_; | 155 Delegate* delegate_; |
| 172 NotificationMap notifications_; | 156 Notifications notifications_; |
|
Jun Mukai
2013/02/20 22:52:16
can we use std::priority_queue rather than std::li
Dmitry Titov
2013/02/23 00:58:51
I've replaced it with a std::set<T*, Comparer>. It
| |
| 173 bool message_center_visible_; | 157 bool message_center_visible_; |
| 174 size_t unread_count_; | 158 size_t unread_count_; |
| 175 bool quiet_mode_; | 159 bool quiet_mode_; |
| 176 scoped_ptr<base::OneShotTimer<NotificationList> > quiet_mode_timer_; | 160 scoped_ptr<base::OneShotTimer<NotificationList> > quiet_mode_timer_; |
| 177 | 161 |
| 178 DISALLOW_COPY_AND_ASSIGN(NotificationList); | 162 DISALLOW_COPY_AND_ASSIGN(NotificationList); |
| 179 }; | 163 }; |
| 180 | 164 |
| 181 } // namespace message_center | 165 } // namespace message_center |
| 182 | 166 |
| 183 #endif // UI_MESSAGE_CENTER_NOTIFICATION_LIST_H_ | 167 #endif // UI_MESSAGE_CENTER_NOTIFICATION_LIST_H_ |
| OLD | NEW |