| 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( | 74 void NotificationList::AddNotification(NotificationType type, |
| 75 NotificationType type, | 75 const std::string& id, |
| 76 const std::string& id, | 76 const string16& title, |
| 77 const string16& title, | 77 const string16& message, |
| 78 const string16& message, | 78 const string16& display_source, |
| 79 const string16& display_source, | 79 const std::string& extension_id, |
| 80 const std::string& extension_id, | 80 const DictionaryValue* optional_fields, |
| 81 const DictionaryValue* optional_fields) { | 81 NotificationDelegate* delegate) { |
| 82 scoped_ptr<Notification> notification( | 82 scoped_ptr<Notification> notification(new Notification(type, |
| 83 new Notification(type, id, title, message, display_source, extension_id, | 83 id, |
| 84 optional_fields)); | 84 title, |
| 85 message, |
| 86 display_source, |
| 87 extension_id, |
| 88 optional_fields, |
| 89 delegate)); |
| 85 PushNotification(notification.Pass()); | 90 PushNotification(notification.Pass()); |
| 86 } | 91 } |
| 87 | 92 |
| 88 void NotificationList::UpdateNotificationMessage( | 93 void NotificationList::UpdateNotificationMessage( |
| 89 const std::string& old_id, | 94 const std::string& old_id, |
| 90 const std::string& new_id, | 95 const std::string& new_id, |
| 91 const string16& title, | 96 const string16& title, |
| 92 const string16& message, | 97 const string16& message, |
| 93 const base::DictionaryValue* optional_fields) { | 98 const base::DictionaryValue* optional_fields, |
| 99 NotificationDelegate* delegate) { |
| 94 Notifications::iterator iter = GetNotification(old_id); | 100 Notifications::iterator iter = GetNotification(old_id); |
| 95 if (iter == notifications_.end()) | 101 if (iter == notifications_.end()) |
| 96 return; | 102 return; |
| 97 | 103 |
| 98 // Copy and update a notification. It has an effect of setting a new timestamp | 104 // Copy and update a notification. It has an effect of setting a new timestamp |
| 99 // if not overridden by optional_fields | 105 // if not overridden by optional_fields |
| 100 scoped_ptr<Notification> notification( | 106 scoped_ptr<Notification> notification( |
| 101 new Notification((*iter)->type(), | 107 new Notification((*iter)->type(), |
| 102 new_id, | 108 new_id, |
| 103 title, | 109 title, |
| 104 message, | 110 message, |
| 105 (*iter)->display_source(), | 111 (*iter)->display_source(), |
| 106 (*iter)->extension_id(), | 112 (*iter)->extension_id(), |
| 107 optional_fields)); | 113 optional_fields, |
| 114 delegate)); |
| 108 notification->CopyState(*iter); | 115 notification->CopyState(*iter); |
| 109 | 116 |
| 110 // Handles priority promotion. If the notification is already dismissed but | 117 // Handles priority promotion. If the notification is already dismissed but |
| 111 // the updated notification has higher priority, it should re-appear as a | 118 // the updated notification has higher priority, it should re-appear as a |
| 112 // toast. | 119 // toast. |
| 113 if ((*iter)->priority() < notification->priority()) { | 120 if ((*iter)->priority() < notification->priority()) { |
| 114 notification->set_is_read(false); | 121 notification->set_is_read(false); |
| 115 notification->set_shown_as_popup(false); | 122 notification->set_shown_as_popup(false); |
| 116 } | 123 } |
| 117 | 124 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 --unread_count_; | 285 --unread_count_; |
| 279 } | 286 } |
| 280 } | 287 } |
| 281 | 288 |
| 282 void NotificationList::MarkNotificationAsExpanded(const std::string& id) { | 289 void NotificationList::MarkNotificationAsExpanded(const std::string& id) { |
| 283 Notifications::iterator iter = GetNotification(id); | 290 Notifications::iterator iter = GetNotification(id); |
| 284 if (iter != notifications_.end()) | 291 if (iter != notifications_.end()) |
| 285 (*iter)->set_is_expanded(true); | 292 (*iter)->set_is_expanded(true); |
| 286 } | 293 } |
| 287 | 294 |
| 295 NotificationDelegate* NotificationList::GetNotificationDelegate( |
| 296 const std::string& id) { |
| 297 Notifications::iterator iter = GetNotification(id); |
| 298 if (iter == notifications_.end()) |
| 299 return NULL; |
| 300 return (*iter)->delegate(); |
| 301 } |
| 302 |
| 288 void NotificationList::SetQuietMode(bool quiet_mode) { | 303 void NotificationList::SetQuietMode(bool quiet_mode) { |
| 289 SetQuietModeInternal(quiet_mode); | 304 SetQuietModeInternal(quiet_mode); |
| 290 quiet_mode_timer_.reset(); | 305 quiet_mode_timer_.reset(); |
| 291 } | 306 } |
| 292 | 307 |
| 293 void NotificationList::EnterQuietModeWithExpire( | 308 void NotificationList::EnterQuietModeWithExpire( |
| 294 const base::TimeDelta& expires_in) { | 309 const base::TimeDelta& expires_in) { |
| 295 if (quiet_mode_timer_.get()) { | 310 if (quiet_mode_timer_.get()) { |
| 296 // Note that the capital Reset() is the method to restart the timer, not | 311 // Note that the capital Reset() is the method to restart the timer, not |
| 297 // scoped_ptr::reset(). | 312 // scoped_ptr::reset(). |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 notification->set_shown_as_popup(message_center_visible_ || quiet_mode_); | 374 notification->set_shown_as_popup(message_center_visible_ || quiet_mode_); |
| 360 if (!quiet_mode_ && notification->priority() > MIN_PRIORITY) | 375 if (!quiet_mode_ && notification->priority() > MIN_PRIORITY) |
| 361 ++unread_count_; | 376 ++unread_count_; |
| 362 } | 377 } |
| 363 // Take ownership. The notification can only be removed from the list | 378 // Take ownership. The notification can only be removed from the list |
| 364 // in EraseNotification(), which will delete it. | 379 // in EraseNotification(), which will delete it. |
| 365 notifications_.insert(notification.release()); | 380 notifications_.insert(notification.release()); |
| 366 } | 381 } |
| 367 | 382 |
| 368 } // namespace message_center | 383 } // namespace message_center |
| OLD | NEW |