1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/message_center/message_center_impl.h"
9 #include "base/memory/scoped_vector.h"
10 #include "base/observer_list.h"
11 #include "ui/message_center/message_center_style.h"
12 #include "ui/message_center/message_center_types.h"
13 #include "ui/message_center/notification.h"
14 #include "ui/message_center/notification_blocker.h"
15 #include "ui/message_center/notification_list.h"
16 #include "ui/message_center/notification_types.h"
20 base::TimeDelta GetTimeoutForPriority(int priority) {
21 if (priority > message_center::DEFAULT_PRIORITY) {
22 return base::TimeDelta::FromSeconds(
23 message_center::kAutocloseHighPriorityDelaySeconds);
25 return base::TimeDelta::FromSeconds(
26 message_center::kAutocloseDefaultDelaySeconds);
31 namespace message_center {
34 // ChangeQueue keeps track of all the changes that we need to make to the
35 // notification list once the visibility is set to VISIBILITY_TRANSIENT.
44 // Change represents an operation made on a notification. Since it contains
45 // the final state of the notification, we only keep the last change for a
46 // particular notification that is in the notification list around. There are
47 // two ids; |id_| is the newest notification id that has been assigned by an
48 // update, and |notification_list_id_| is the id of the notification it should
49 // be updating as it exists in the notification list.
52 Change(ChangeType type,
53 const std::string& id,
54 scoped_ptr<Notification> notification);
57 // Used to transfer ownership of the contained notification.
58 scoped_ptr<Notification> PassNotification();
60 Notification* notification() const { return notification_.get(); }
61 const std::string& id() const { return id_; }
62 ChangeType type() const { return type_; }
63 bool by_user() const { return by_user_; }
64 void set_by_user(bool by_user) { by_user_ = by_user; }
65 const std::string& notification_list_id() const {
66 return notification_list_id_;
68 void set_notification_list_id(const std::string& id) {
69 notification_list_id_ = id;
73 const ChangeType type_;
74 const std::string id_;
75 std::string notification_list_id_;
77 scoped_ptr<Notification> notification_;
79 DISALLOW_COPY_AND_ASSIGN(Change);
85 // Called when the message center has appropriate visibility. Modifies
86 // |message_center| but does not retain it. This also causes the queue to
88 void ApplyChanges(MessageCenter* message_center);
90 // Causes a TYPE_ADD change to be added to the queue.
91 void AddNotification(scoped_ptr<Notification> notification);
93 // Causes a TYPE_UPDATE change to be added to the queue.
94 void UpdateNotification(const std::string& old_id,
95 scoped_ptr<Notification> notification);
97 // Causes a TYPE_DELETE change to be added to the queue.
98 void EraseNotification(const std::string& id, bool by_user);
100 // Returns whether the queue matches an id. The id given will be matched
101 // against the ID of all changes post-update, not the id of the notification
102 // as it stands in the notification list.
103 bool Has(const std::string& id) const;
105 // Returns a Change that can be modified by the caller. ChangeQueue retains
106 // ownership of the Change; pointers should not be retained.
107 Notification* GetLatestNotification(const std::string& id) const;
110 void Replace(const std::string& id, scoped_ptr<Change> change);
112 ScopedVector<Change> changes_;
115 ////////////////////////////////////////////////////////////////////////////////
118 struct ChangeFinder {
119 explicit ChangeFinder(const std::string& id) : id(id) {}
120 bool operator()(ChangeQueue::Change* change) { return change->id() == id; }
125 ////////////////////////////////////////////////////////////////////////////////
126 // ChangeQueue::Change
128 ChangeQueue::Change::Change(ChangeType type,
129 const std::string& id,
130 scoped_ptr<Notification> notification)
133 notification_list_id_(id),
135 notification_(notification.Pass()) {
136 DCHECK(!id.empty() &&
137 (type != CHANGE_TYPE_DELETE || notification_.get() == NULL));
140 ChangeQueue::Change::~Change() {}
142 scoped_ptr<Notification> ChangeQueue::Change::PassNotification() {
143 return notification_.Pass();
146 ////////////////////////////////////////////////////////////////////////////////
149 ChangeQueue::ChangeQueue() {}
151 ChangeQueue::~ChangeQueue() {}
153 void ChangeQueue::ApplyChanges(MessageCenter* message_center) {
154 // This method is re-entrant.
155 while (!changes_.empty()) {
156 ScopedVector<Change>::iterator iter = changes_.begin();
157 scoped_ptr<Change> change(*iter);
158 // TODO(dewittj): Replace changes_ with a deque.
159 changes_.weak_erase(iter);
160 // |message_center| is taking ownership of each element here.
161 switch (change->type()) {
162 case CHANGE_TYPE_ADD:
163 message_center->AddNotification(change->PassNotification());
165 case CHANGE_TYPE_UPDATE:
166 message_center->UpdateNotification(change->notification_list_id(),
167 change->PassNotification());
169 case CHANGE_TYPE_DELETE:
170 message_center->RemoveNotification(change->notification_list_id(),
179 void ChangeQueue::AddNotification(scoped_ptr<Notification> notification) {
180 std::string id = notification->id();
182 scoped_ptr<Change> change(
183 new Change(CHANGE_TYPE_ADD, id, notification.Pass()));
184 Replace(id, change.Pass());
187 void ChangeQueue::UpdateNotification(const std::string& old_id,
188 scoped_ptr<Notification> notification) {
189 std::string new_id = notification->id();
190 scoped_ptr<Change> change(
191 new Change(CHANGE_TYPE_UPDATE, new_id, notification.Pass()));
192 Replace(old_id, change.Pass());
195 void ChangeQueue::EraseNotification(const std::string& id, bool by_user) {
196 scoped_ptr<Change> change(
197 new Change(CHANGE_TYPE_DELETE, id, scoped_ptr<Notification>()));
198 change->set_by_user(by_user);
199 Replace(id, change.Pass());
202 bool ChangeQueue::Has(const std::string& id) const {
203 ScopedVector<Change>::const_iterator iter =
204 std::find_if(changes_.begin(), changes_.end(), ChangeFinder(id));
205 return iter != changes_.end();
208 Notification* ChangeQueue::GetLatestNotification(const std::string& id) const {
209 ScopedVector<Change>::const_iterator iter =
210 std::find_if(changes_.begin(), changes_.end(), ChangeFinder(id));
211 if (iter == changes_.end())
214 return (*iter)->notification();
217 void ChangeQueue::Replace(const std::string& changed_id,
218 scoped_ptr<Change> new_change) {
219 ScopedVector<Change>::iterator iter =
220 std::find_if(changes_.begin(), changes_.end(), ChangeFinder(changed_id));
221 if (iter != changes_.end()) {
222 Change* old_change = *iter;
223 new_change->set_notification_list_id(old_change->notification_list_id());
224 changes_.erase(iter);
226 new_change->set_notification_list_id(changed_id);
229 changes_.push_back(new_change.release());
232 ////////////////////////////////////////////////////////////////////////////////
235 PopupTimer::PopupTimer(const std::string& id,
236 base::TimeDelta timeout,
237 base::WeakPtr<PopupTimersController> controller)
240 timer_controller_(controller),
241 timer_(new base::OneShotTimer<PopupTimersController>) {}
243 PopupTimer::~PopupTimer() {
247 if (timer_->IsRunning())
251 void PopupTimer::Start() {
252 if (timer_->IsRunning())
254 base::TimeDelta timeout_to_close =
255 timeout_ <= passed_ ? base::TimeDelta() : timeout_ - passed_;
256 start_time_ = base::Time::Now();
261 &PopupTimersController::TimerFinished, timer_controller_, id_));
264 void PopupTimer::Pause() {
265 if (!timer_.get() || !timer_->IsRunning())
269 passed_ += base::Time::Now() - start_time_;
272 void PopupTimer::Reset() {
275 passed_ = base::TimeDelta();
278 ////////////////////////////////////////////////////////////////////////////////
279 // PopupTimersController
281 PopupTimersController::PopupTimersController(MessageCenter* message_center)
282 : message_center_(message_center), popup_deleter_(&popup_timers_) {
283 message_center_->AddObserver(this);
286 PopupTimersController::~PopupTimersController() {
287 message_center_->RemoveObserver(this);
290 void PopupTimersController::StartTimer(const std::string& id,
291 const base::TimeDelta& timeout) {
292 PopupTimerCollection::iterator iter = popup_timers_.find(id);
293 if (iter != popup_timers_.end()) {
294 DCHECK(iter->second);
295 iter->second->Start();
299 PopupTimer* timer = new PopupTimer(id, timeout, AsWeakPtr());
302 popup_timers_[id] = timer;
305 void PopupTimersController::StartAll() {
306 std::map<std::string, PopupTimer*>::iterator iter;
307 for (iter = popup_timers_.begin(); iter != popup_timers_.end(); iter++) {
308 iter->second->Start();
312 void PopupTimersController::ResetTimer(const std::string& id,
313 const base::TimeDelta& timeout) {
315 StartTimer(id, timeout);
318 void PopupTimersController::PauseTimer(const std::string& id) {
319 PopupTimerCollection::iterator iter = popup_timers_.find(id);
320 if (iter == popup_timers_.end())
322 iter->second->Pause();
325 void PopupTimersController::PauseAll() {
326 std::map<std::string, PopupTimer*>::iterator iter;
327 for (iter = popup_timers_.begin(); iter != popup_timers_.end(); iter++) {
328 iter->second->Pause();
332 void PopupTimersController::CancelTimer(const std::string& id) {
333 PopupTimerCollection::iterator iter = popup_timers_.find(id);
334 if (iter == popup_timers_.end())
337 PopupTimer* timer = iter->second;
340 popup_timers_.erase(iter);
343 void PopupTimersController::CancelAll() {
344 STLDeleteValues(&popup_timers_);
345 popup_timers_.clear();
348 void PopupTimersController::TimerFinished(const std::string& id) {
349 PopupTimerCollection::iterator iter = popup_timers_.find(id);
350 if (iter == popup_timers_.end())
354 message_center_->MarkSinglePopupAsShown(id, false);
357 void PopupTimersController::OnNotificationDisplayed(
358 const std::string& id,
359 const DisplaySource source) {
360 OnNotificationUpdated(id);
363 void PopupTimersController::OnNotificationUpdated(const std::string& id) {
364 NotificationList::PopupNotifications popup_notifications =
365 message_center_->GetPopupNotifications();
367 if (!popup_notifications.size()) {
372 NotificationList::PopupNotifications::const_iterator iter =
373 popup_notifications.begin();
374 for (; iter != popup_notifications.end(); iter++) {
375 if ((*iter)->id() == id)
379 if (iter == popup_notifications.end() || (*iter)->never_timeout()) {
384 // Start the timer if not yet.
385 if (popup_timers_.find(id) == popup_timers_.end())
386 StartTimer(id, GetTimeoutForPriority((*iter)->priority()));
389 void PopupTimersController::OnNotificationRemoved(const std::string& id,
394 } // namespace internal
396 ////////////////////////////////////////////////////////////////////////////////
397 // MessageCenterImpl::NotificationCache
399 MessageCenterImpl::NotificationCache::NotificationCache()
402 MessageCenterImpl::NotificationCache::~NotificationCache() {}
404 void MessageCenterImpl::NotificationCache::Rebuild(
405 const NotificationList::Notifications& notifications) {
406 visible_notifications = notifications;
410 void MessageCenterImpl::NotificationCache::RecountUnread() {
412 for (NotificationList::Notifications::const_iterator iter =
413 visible_notifications.begin();
414 iter != visible_notifications.end(); ++iter) {
415 if (!(*iter)->IsRead())
420 ////////////////////////////////////////////////////////////////////////////////
423 MessageCenterImpl::MessageCenterImpl()
425 popup_timers_controller_(new internal::PopupTimersController(this)),
426 settings_provider_(NULL) {
427 notification_list_.reset(new NotificationList());
428 notification_queue_.reset(new internal::ChangeQueue());
431 MessageCenterImpl::~MessageCenterImpl() {}
433 void MessageCenterImpl::AddObserver(MessageCenterObserver* observer) {
434 observer_list_.AddObserver(observer);
437 void MessageCenterImpl::RemoveObserver(MessageCenterObserver* observer) {
438 observer_list_.RemoveObserver(observer);
441 void MessageCenterImpl::AddNotificationBlocker(NotificationBlocker* blocker) {
442 if (std::find(blockers_.begin(), blockers_.end(), blocker) !=
446 blocker->AddObserver(this);
447 blockers_.push_back(blocker);
450 void MessageCenterImpl::RemoveNotificationBlocker(
451 NotificationBlocker* blocker) {
452 std::vector<NotificationBlocker*>::iterator iter =
453 std::find(blockers_.begin(), blockers_.end(), blocker);
454 if (iter == blockers_.end())
456 blocker->RemoveObserver(this);
457 blockers_.erase(iter);
460 void MessageCenterImpl::OnBlockingStateChanged(NotificationBlocker* blocker) {
461 std::list<std::string> blocked_ids;
462 NotificationList::PopupNotifications popups =
463 notification_list_->GetPopupNotifications(blockers_, &blocked_ids);
465 for (std::list<std::string>::const_iterator iter = blocked_ids.begin();
466 iter != blocked_ids.end(); ++iter) {
467 // Do not call MessageCenterImpl::MarkSinglePopupAsShown() directly here
468 // just for performance reason. MessageCenterImpl::MarkSinglePopupAsShown()
469 // calls NotificationList::MarkSinglePopupAsShown() and then updates the
470 // unread count, but the whole cache will be recreated below.
471 notification_list_->MarkSinglePopupAsShown((*iter), true);
472 FOR_EACH_OBSERVER(MessageCenterObserver,
474 OnNotificationUpdated(*iter));
476 notification_cache_.Rebuild(
477 notification_list_->GetVisibleNotifications(blockers_));
478 FOR_EACH_OBSERVER(MessageCenterObserver,
480 OnBlockingStateChanged(blocker));
483 void MessageCenterImpl::SetVisibility(Visibility visibility) {
484 std::set<std::string> updated_ids;
485 notification_list_->SetMessageCenterVisible(
486 (visibility == VISIBILITY_MESSAGE_CENTER), &updated_ids);
487 notification_cache_.RecountUnread();
489 for (std::set<std::string>::const_iterator iter = updated_ids.begin();
490 iter != updated_ids.end();
493 MessageCenterObserver, observer_list_, OnNotificationUpdated(*iter));
496 if (visibility == VISIBILITY_TRANSIENT)
497 notification_queue_->ApplyChanges(this);
499 FOR_EACH_OBSERVER(MessageCenterObserver,
501 OnCenterVisibilityChanged(visibility));
504 bool MessageCenterImpl::IsMessageCenterVisible() const {
505 return notification_list_->is_message_center_visible();
508 size_t MessageCenterImpl::NotificationCount() const {
509 return notification_cache_.visible_notifications.size();
512 size_t MessageCenterImpl::UnreadNotificationCount() const {
513 return notification_cache_.unread_count;
516 bool MessageCenterImpl::HasPopupNotifications() const {
517 return !IsMessageCenterVisible() &&
518 notification_list_->HasPopupNotifications(blockers_);
521 bool MessageCenterImpl::HasNotification(const std::string& id) {
522 // This will return true if the notification with |id| is hidden by the
523 // ChromeOS multi-profile feature. This would be harmless for now because
524 // this check will be used from the UI, so the |id| for hidden profile won't
526 // TODO(mukai): fix this if necessary.
527 return notification_list_->HasNotification(id);
530 bool MessageCenterImpl::IsQuietMode() const {
531 return notification_list_->quiet_mode();
534 bool MessageCenterImpl::HasClickedListener(const std::string& id) {
535 scoped_refptr<NotificationDelegate> delegate =
536 notification_list_->GetNotificationDelegate(id);
537 return delegate.get() && delegate->HasClickedListener();
540 const NotificationList::Notifications&
541 MessageCenterImpl::GetVisibleNotifications() {
542 return notification_cache_.visible_notifications;
545 NotificationList::PopupNotifications
546 MessageCenterImpl::GetPopupNotifications() {
547 return notification_list_->GetPopupNotifications(blockers_, NULL);
550 //------------------------------------------------------------------------------
551 // Client code interface.
552 void MessageCenterImpl::AddNotification(scoped_ptr<Notification> notification) {
553 DCHECK(notification.get());
554 const std::string id = notification->id();
555 for (size_t i = 0; i < blockers_.size(); ++i)
556 blockers_[i]->CheckState();
558 if (notification_list_->is_message_center_visible()) {
559 notification_queue_->AddNotification(notification.Pass());
563 // Sometimes the notification can be added with the same id and the
564 // |notification_list| will replace the notification instead of adding new.
565 // This is essentially an update rather than addition.
566 bool already_exists = notification_list_->HasNotification(id);
567 notification_list_->AddNotification(notification.Pass());
568 notification_cache_.Rebuild(
569 notification_list_->GetVisibleNotifications(blockers_));
571 if (already_exists) {
573 MessageCenterObserver, observer_list_, OnNotificationUpdated(id));
576 MessageCenterObserver, observer_list_, OnNotificationAdded(id));
580 void MessageCenterImpl::UpdateNotification(
581 const std::string& old_id,
582 scoped_ptr<Notification> new_notification) {
583 for (size_t i = 0; i < blockers_.size(); ++i)
584 blockers_[i]->CheckState();
586 if (notification_list_->is_message_center_visible()) {
587 // We will allow notifications that are progress types (and stay progress
588 // types) to be updated even if the message center is open. There are 3
589 // requirements here:
590 // * Notification of type PROGRESS exists with same ID in the center
591 // * There are no queued updates for this notification (they imply a change
592 // that violates the PROGRESS invariant
593 // * The new notification is type PROGRESS.
594 // TODO(dewittj): Ensure this works when the ID is changed by the caller.
595 // This shouldn't be an issue in practice since only W3C notifications
596 // change the ID on update, and they don't have progress type notifications.
597 bool update_keeps_progress_type =
598 new_notification->type() == NOTIFICATION_TYPE_PROGRESS &&
599 !notification_queue_->Has(old_id) &&
600 notification_list_->HasNotificationOfType(old_id,
601 NOTIFICATION_TYPE_PROGRESS);
602 if (!update_keeps_progress_type) {
603 // Updates are allowed only for progress notifications.
604 notification_queue_->UpdateNotification(old_id, new_notification.Pass());
609 std::string new_id = new_notification->id();
610 notification_list_->UpdateNotificationMessage(old_id,
611 new_notification.Pass());
612 notification_cache_.Rebuild(
613 notification_list_->GetVisibleNotifications(blockers_));
614 if (old_id == new_id) {
616 MessageCenterObserver, observer_list_, OnNotificationUpdated(new_id));
618 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_,
619 OnNotificationRemoved(old_id, false));
620 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_,
621 OnNotificationAdded(new_id));
625 void MessageCenterImpl::RemoveNotification(const std::string& id,
627 if (!by_user && notification_list_->is_message_center_visible()) {
628 notification_queue_->EraseNotification(id, by_user);
632 if (!HasNotification(id))
635 // In many cases |id| is a reference to an existing notification instance
636 // but the instance can be destructed in RemoveNotification(). Hence
637 // copies the id explicitly here.
638 std::string copied_id(id);
640 scoped_refptr<NotificationDelegate> delegate =
641 notification_list_->GetNotificationDelegate(copied_id);
643 delegate->Close(by_user);
645 notification_list_->RemoveNotification(copied_id);
646 notification_cache_.Rebuild(
647 notification_list_->GetVisibleNotifications(blockers_));
648 FOR_EACH_OBSERVER(MessageCenterObserver,
650 OnNotificationRemoved(copied_id, by_user));
653 void MessageCenterImpl::RemoveAllNotifications(bool by_user) {
654 // Using not |blockers_| but an empty list since it wants to remove literally
655 // all notifications.
656 RemoveNotifications(by_user, NotificationBlockers());
659 void MessageCenterImpl::RemoveAllVisibleNotifications(bool by_user) {
660 RemoveNotifications(by_user, blockers_);
663 void MessageCenterImpl::RemoveNotifications(
665 const NotificationBlockers& blockers) {
666 const NotificationList::Notifications notifications =
667 notification_list_->GetVisibleNotifications(blockers);
668 std::set<std::string> ids;
669 for (NotificationList::Notifications::const_iterator iter =
670 notifications.begin(); iter != notifications.end(); ++iter) {
671 ids.insert((*iter)->id());
672 scoped_refptr<NotificationDelegate> delegate = (*iter)->delegate();
674 delegate->Close(by_user);
675 notification_list_->RemoveNotification((*iter)->id());
679 notification_cache_.Rebuild(
680 notification_list_->GetVisibleNotifications(blockers_));
682 for (std::set<std::string>::const_iterator iter = ids.begin();
683 iter != ids.end(); ++iter) {
684 FOR_EACH_OBSERVER(MessageCenterObserver,
686 OnNotificationRemoved(*iter, by_user));
690 void MessageCenterImpl::SetNotificationIcon(const std::string& notification_id,
691 const gfx::Image& image) {
692 bool updated = false;
693 Notification* queue_notification = notification_queue_->GetLatestNotification(
696 if (queue_notification) {
697 queue_notification->set_icon(image);
700 updated = notification_list_->SetNotificationIcon(notification_id, image);
704 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_,
705 OnNotificationUpdated(notification_id));
709 void MessageCenterImpl::SetNotificationImage(const std::string& notification_id,
710 const gfx::Image& image) {
711 bool updated = false;
712 Notification* queue_notification = notification_queue_->GetLatestNotification(
715 if (queue_notification) {
716 queue_notification->set_image(image);
719 updated = notification_list_->SetNotificationImage(notification_id, image);
723 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_,
724 OnNotificationUpdated(notification_id));
728 void MessageCenterImpl::SetNotificationButtonIcon(
729 const std::string& notification_id, int button_index,
730 const gfx::Image& image) {
731 bool updated = false;
732 Notification* queue_notification = notification_queue_->GetLatestNotification(
735 if (queue_notification) {
736 queue_notification->SetButtonIcon(button_index, image);
739 updated = notification_list_->SetNotificationButtonIcon(
740 notification_id, button_index, image);
744 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_,
745 OnNotificationUpdated(notification_id));
749 void MessageCenterImpl::DisableNotificationsByNotifier(
750 const NotifierId& notifier_id) {
751 if (settings_provider_) {
752 // TODO(mukai): SetNotifierEnabled can just accept notifier_id?
753 Notifier notifier(notifier_id, base::string16(), true);
754 settings_provider_->SetNotifierEnabled(notifier, false);
757 NotificationList::Notifications notifications =
758 notification_list_->GetNotificationsByNotifierId(notifier_id);
759 for (NotificationList::Notifications::const_iterator iter =
760 notifications.begin(); iter != notifications.end();) {
761 std::string id = (*iter)->id();
763 RemoveNotification(id, false);
765 if (!notifications.empty()) {
766 notification_cache_.Rebuild(
767 notification_list_->GetVisibleNotifications(blockers_));
771 void MessageCenterImpl::ClickOnNotification(const std::string& id) {
772 if (!HasNotification(id))
774 if (HasPopupNotifications())
775 MarkSinglePopupAsShown(id, true);
776 scoped_refptr<NotificationDelegate> delegate =
777 notification_list_->GetNotificationDelegate(id);
781 MessageCenterObserver, observer_list_, OnNotificationClicked(id));
784 void MessageCenterImpl::ClickOnNotificationButton(const std::string& id,
786 if (!HasNotification(id))
788 if (HasPopupNotifications())
789 MarkSinglePopupAsShown(id, true);
790 scoped_refptr<NotificationDelegate> delegate =
791 notification_list_->GetNotificationDelegate(id);
793 delegate->ButtonClick(button_index);
795 MessageCenterObserver, observer_list_, OnNotificationButtonClicked(
799 void MessageCenterImpl::MarkSinglePopupAsShown(const std::string& id,
800 bool mark_notification_as_read) {
801 if (!HasNotification(id))
803 notification_list_->MarkSinglePopupAsShown(id, mark_notification_as_read);
804 notification_cache_.RecountUnread();
806 MessageCenterObserver, observer_list_, OnNotificationUpdated(id));
809 void MessageCenterImpl::DisplayedNotification(
810 const std::string& id,
811 const DisplaySource source) {
812 if (!HasNotification(id))
815 if (HasPopupNotifications())
816 notification_list_->MarkSinglePopupAsDisplayed(id);
817 notification_cache_.RecountUnread();
818 scoped_refptr<NotificationDelegate> delegate =
819 notification_list_->GetNotificationDelegate(id);
823 MessageCenterObserver,
825 OnNotificationDisplayed(id, source));
828 void MessageCenterImpl::SetNotifierSettingsProvider(
829 NotifierSettingsProvider* provider) {
830 settings_provider_ = provider;
833 NotifierSettingsProvider* MessageCenterImpl::GetNotifierSettingsProvider() {
834 return settings_provider_;
837 void MessageCenterImpl::SetQuietMode(bool in_quiet_mode) {
838 if (in_quiet_mode != notification_list_->quiet_mode()) {
839 notification_list_->SetQuietMode(in_quiet_mode);
840 FOR_EACH_OBSERVER(MessageCenterObserver,
842 OnQuietModeChanged(in_quiet_mode));
844 quiet_mode_timer_.reset();
847 void MessageCenterImpl::EnterQuietModeWithExpire(
848 const base::TimeDelta& expires_in) {
849 if (quiet_mode_timer_.get()) {
850 // Note that the capital Reset() is the method to restart the timer, not
851 // scoped_ptr::reset().
852 quiet_mode_timer_->Reset();
854 notification_list_->SetQuietMode(true);
856 MessageCenterObserver, observer_list_, OnQuietModeChanged(true));
858 quiet_mode_timer_.reset(new base::OneShotTimer<MessageCenterImpl>);
859 quiet_mode_timer_->Start(
863 &MessageCenterImpl::SetQuietMode, base::Unretained(this), false));
867 void MessageCenterImpl::RestartPopupTimers() {
868 if (popup_timers_controller_.get())
869 popup_timers_controller_->StartAll();
872 void MessageCenterImpl::PausePopupTimers() {
873 if (popup_timers_controller_.get())
874 popup_timers_controller_->PauseAll();
877 void MessageCenterImpl::DisableTimersForTest() {
878 popup_timers_controller_.reset();
881 } // namespace message_center