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 20 matching lines...) Expand all Loading... |
31 if (n1->serial_number() > n2->serial_number()) // Newer come first. | 31 if (n1->serial_number() > n2->serial_number()) // Newer come first. |
32 return true; | 32 return true; |
33 if (n1->serial_number() < n2->serial_number()) | 33 if (n1->serial_number() < n2->serial_number()) |
34 return false; | 34 return false; |
35 return false; | 35 return false; |
36 } | 36 } |
37 | 37 |
38 const size_t NotificationList::kMaxVisibleMessageCenterNotifications = 100; | 38 const size_t NotificationList::kMaxVisibleMessageCenterNotifications = 100; |
39 const size_t NotificationList::kMaxVisiblePopupNotifications = 2; | 39 const size_t NotificationList::kMaxVisiblePopupNotifications = 2; |
40 | 40 |
| 41 NotificationList::Delegate::~Delegate() { |
| 42 } |
| 43 |
41 NotificationList::NotificationList(Delegate* delegate) | 44 NotificationList::NotificationList(Delegate* delegate) |
42 : delegate_(delegate), | 45 : delegate_(delegate), |
43 message_center_visible_(false), | 46 message_center_visible_(false), |
44 unread_count_(0), | 47 unread_count_(0), |
45 quiet_mode_(false) { | 48 quiet_mode_(false) { |
46 } | 49 } |
47 | 50 |
48 NotificationList::~NotificationList() { | 51 NotificationList::~NotificationList() { |
49 STLDeleteContainerPointers(notifications_.begin(), notifications_.end()); | 52 STLDeleteContainerPointers(notifications_.begin(), notifications_.end()); |
50 } | 53 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 // UI, so technically the removal is indirect. | 153 // UI, so technically the removal is indirect. |
151 delegate_->SendRemoveNotification((*curiter)->id(), false); | 154 delegate_->SendRemoveNotification((*curiter)->id(), false); |
152 } | 155 } |
153 } | 156 } |
154 | 157 |
155 bool NotificationList::SetNotificationIcon(const std::string& notification_id, | 158 bool NotificationList::SetNotificationIcon(const std::string& notification_id, |
156 const gfx::Image& image) { | 159 const gfx::Image& image) { |
157 Notifications::iterator iter = GetNotification(notification_id); | 160 Notifications::iterator iter = GetNotification(notification_id); |
158 if (iter == notifications_.end()) | 161 if (iter == notifications_.end()) |
159 return false; | 162 return false; |
160 (*iter)->set_primary_icon(image); | 163 (*iter)->set_icon(image); |
161 return true; | 164 return true; |
162 } | 165 } |
163 | 166 |
164 bool NotificationList::SetNotificationImage(const std::string& notification_id, | 167 bool NotificationList::SetNotificationImage(const std::string& notification_id, |
165 const gfx::Image& image) { | 168 const gfx::Image& image) { |
166 Notifications::iterator iter = GetNotification(notification_id); | 169 Notifications::iterator iter = GetNotification(notification_id); |
167 if (iter == notifications_.end()) | 170 if (iter == notifications_.end()) |
168 return false; | 171 return false; |
169 (*iter)->set_image(image); | 172 (*iter)->set_image(image); |
170 return true; | 173 return true; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 return; | 243 return; |
241 | 244 |
242 (*iter)->set_shown_as_popup(true); | 245 (*iter)->set_shown_as_popup(true); |
243 | 246 |
244 if (mark_notification_as_read) { | 247 if (mark_notification_as_read) { |
245 --unread_count_; | 248 --unread_count_; |
246 (*iter)->set_is_read(true); | 249 (*iter)->set_is_read(true); |
247 } | 250 } |
248 } | 251 } |
249 | 252 |
| 253 void NotificationList::MarkNotificationAsExpanded(const std::string& id) { |
| 254 Notifications::iterator iter = GetNotification(id); |
| 255 if (iter != notifications_.end()) |
| 256 (*iter)->set_is_expanded(true); |
| 257 } |
| 258 |
250 void NotificationList::SetQuietMode(bool quiet_mode) { | 259 void NotificationList::SetQuietMode(bool quiet_mode) { |
251 SetQuietModeInternal(quiet_mode); | 260 SetQuietModeInternal(quiet_mode); |
252 quiet_mode_timer_.reset(); | 261 quiet_mode_timer_.reset(); |
253 } | 262 } |
254 | 263 |
255 void NotificationList::EnterQuietModeWithExpire( | 264 void NotificationList::EnterQuietModeWithExpire( |
256 const base::TimeDelta& expires_in) { | 265 const base::TimeDelta& expires_in) { |
257 if (quiet_mode_timer_.get()) { | 266 if (quiet_mode_timer_.get()) { |
258 // Note that the capital Reset() is the method to restart the timer, not | 267 // Note that the capital Reset() is the method to restart the timer, not |
259 // scoped_ptr::reset(). | 268 // scoped_ptr::reset(). |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 notification->set_shown_as_popup(quiet_mode_); | 329 notification->set_shown_as_popup(quiet_mode_); |
321 if (!quiet_mode_ && notification->priority() > MIN_PRIORITY) | 330 if (!quiet_mode_ && notification->priority() > MIN_PRIORITY) |
322 ++unread_count_; | 331 ++unread_count_; |
323 } | 332 } |
324 // Take ownership. The notification can only be removed from the list | 333 // Take ownership. The notification can only be removed from the list |
325 // in EraseNotification(), which will delete it. | 334 // in EraseNotification(), which will delete it. |
326 notifications_.insert(notification.release()); | 335 notifications_.insert(notification.release()); |
327 } | 336 } |
328 | 337 |
329 } // namespace message_center | 338 } // namespace message_center |
OLD | NEW |