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 #include "ui/message_center/notification_list.h" | 5 #include "ui/message_center/notification_list.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 Notification* notification = *iter; | 64 Notification* notification = *iter; |
65 notification->set_shown_as_popup(true); | 65 notification->set_shown_as_popup(true); |
66 notification->set_is_read(true); | 66 notification->set_is_read(true); |
67 if (updated_ids && | 67 if (updated_ids && |
68 !(notification->shown_as_popup() && notification->is_read())) { | 68 !(notification->shown_as_popup() && notification->is_read())) { |
69 updated_ids->insert(notification->id()); | 69 updated_ids->insert(notification->id()); |
70 } | 70 } |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
74 void NotificationList::AddNotification(NotificationType type, | 74 void NotificationList::AddNotification(scoped_ptr<Notification> notification) { |
75 const std::string& id, | |
76 const string16& title, | |
77 const string16& message, | |
78 const string16& display_source, | |
79 const std::string& extension_id, | |
80 const DictionaryValue* optional_fields, | |
81 NotificationDelegate* delegate) { | |
82 scoped_ptr<Notification> notification(new Notification(type, | |
83 id, | |
84 title, | |
85 message, | |
86 display_source, | |
87 extension_id, | |
88 optional_fields, | |
89 delegate)); | |
90 PushNotification(notification.Pass()); | 75 PushNotification(notification.Pass()); |
91 } | 76 } |
92 | 77 |
93 void NotificationList::UpdateNotificationMessage( | 78 void NotificationList::UpdateNotificationMessage( |
94 const std::string& old_id, | 79 const std::string& old_id, |
95 const std::string& new_id, | 80 scoped_ptr<Notification> new_notification) { |
96 const string16& title, | |
97 const string16& message, | |
98 const base::DictionaryValue* optional_fields, | |
99 NotificationDelegate* delegate) { | |
100 Notifications::iterator iter = GetNotification(old_id); | 81 Notifications::iterator iter = GetNotification(old_id); |
101 if (iter == notifications_.end()) | 82 if (iter == notifications_.end()) |
102 return; | 83 return; |
103 | 84 |
104 // Copy and update a notification. It has an effect of setting a new timestamp | 85 new_notification->CopyState(*iter); |
105 // if not overridden by optional_fields | |
106 scoped_ptr<Notification> notification( | |
107 new Notification((*iter)->type(), | |
108 new_id, | |
109 title, | |
110 message, | |
111 (*iter)->display_source(), | |
112 (*iter)->extension_id(), | |
113 optional_fields, | |
114 delegate)); | |
115 notification->CopyState(*iter); | |
116 | 86 |
117 // Handles priority promotion. If the notification is already dismissed but | 87 // Handles priority promotion. If the notification is already dismissed but |
118 // the updated notification has higher priority, it should re-appear as a | 88 // the updated notification has higher priority, it should re-appear as a |
119 // toast. | 89 // toast. |
120 if ((*iter)->priority() < notification->priority()) { | 90 if ((*iter)->priority() < new_notification->priority()) { |
121 notification->set_is_read(false); | 91 new_notification->set_is_read(false); |
122 notification->set_shown_as_popup(false); | 92 new_notification->set_shown_as_popup(false); |
123 } | 93 } |
124 | 94 |
125 // Do not use EraseNotification and PushNotification, since we don't want to | 95 // Do not use EraseNotification and PushNotification, since we don't want to |
126 // change unread counts nor to update is_read/shown_as_popup states. | 96 // change unread counts nor to update is_read/shown_as_popup states. |
127 Notification *old = *iter; | 97 Notification* old = *iter; |
128 notifications_.erase(iter); | 98 notifications_.erase(iter); |
129 delete old; | 99 delete old; |
130 notifications_.insert(notification.release()); | 100 notifications_.insert(new_notification.release()); |
131 } | 101 } |
132 | 102 |
133 void NotificationList::RemoveNotification(const std::string& id) { | 103 void NotificationList::RemoveNotification(const std::string& id) { |
134 EraseNotification(GetNotification(id)); | 104 EraseNotification(GetNotification(id)); |
135 } | 105 } |
136 | 106 |
137 void NotificationList::RemoveAllNotifications() { | 107 void NotificationList::RemoveAllNotifications() { |
138 for (Notifications::iterator loopiter = notifications_.begin(); | 108 for (Notifications::iterator loopiter = notifications_.begin(); |
139 loopiter != notifications_.end(); ) { | 109 loopiter != notifications_.end(); ) { |
140 Notifications::iterator curiter = loopiter++; | 110 Notifications::iterator curiter = loopiter++; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 (*iter)->set_image(image); | 162 (*iter)->set_image(image); |
193 return true; | 163 return true; |
194 } | 164 } |
195 | 165 |
196 bool NotificationList::SetNotificationButtonIcon( | 166 bool NotificationList::SetNotificationButtonIcon( |
197 const std::string& notification_id, int button_index, | 167 const std::string& notification_id, int button_index, |
198 const gfx::Image& image) { | 168 const gfx::Image& image) { |
199 Notifications::iterator iter = GetNotification(notification_id); | 169 Notifications::iterator iter = GetNotification(notification_id); |
200 if (iter == notifications_.end()) | 170 if (iter == notifications_.end()) |
201 return false; | 171 return false; |
202 return (*iter)->SetButtonIcon(button_index, image); | 172 (*iter)->SetButtonIcon(button_index, image); |
| 173 return true; |
203 } | 174 } |
204 | 175 |
205 bool NotificationList::HasNotification(const std::string& id) { | 176 bool NotificationList::HasNotification(const std::string& id) { |
206 return GetNotification(id) != notifications_.end(); | 177 return GetNotification(id) != notifications_.end(); |
207 } | 178 } |
208 | 179 |
209 bool NotificationList::HasPopupNotifications() { | 180 bool NotificationList::HasPopupNotifications() { |
210 for (Notifications::iterator iter = notifications_.begin(); | 181 for (Notifications::iterator iter = notifications_.begin(); |
211 iter != notifications_.end(); ++iter) { | 182 iter != notifications_.end(); ++iter) { |
212 if ((*iter)->priority() < DEFAULT_PRIORITY) | 183 if ((*iter)->priority() < DEFAULT_PRIORITY) |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 notification->set_shown_as_popup(message_center_visible_ || quiet_mode_); | 345 notification->set_shown_as_popup(message_center_visible_ || quiet_mode_); |
375 if (!quiet_mode_ && notification->priority() > MIN_PRIORITY) | 346 if (!quiet_mode_ && notification->priority() > MIN_PRIORITY) |
376 ++unread_count_; | 347 ++unread_count_; |
377 } | 348 } |
378 // Take ownership. The notification can only be removed from the list | 349 // Take ownership. The notification can only be removed from the list |
379 // in EraseNotification(), which will delete it. | 350 // in EraseNotification(), which will delete it. |
380 notifications_.insert(notification.release()); | 351 notifications_.insert(notification.release()); |
381 } | 352 } |
382 | 353 |
383 } // namespace message_center | 354 } // namespace message_center |
OLD | NEW |