| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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/message_center_impl.h" | 5 #include "ui/message_center/message_center_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 // MessageCenterImpl | 421 // MessageCenterImpl |
| 422 | 422 |
| 423 MessageCenterImpl::MessageCenterImpl() | 423 MessageCenterImpl::MessageCenterImpl() |
| 424 : MessageCenter(), | 424 : MessageCenter(), |
| 425 popup_timers_controller_(new internal::PopupTimersController(this)), | 425 popup_timers_controller_(new internal::PopupTimersController(this)), |
| 426 settings_provider_(NULL) { | 426 settings_provider_(NULL) { |
| 427 notification_list_.reset(new NotificationList()); | 427 notification_list_.reset(new NotificationList()); |
| 428 notification_queue_.reset(new internal::ChangeQueue()); | 428 notification_queue_.reset(new internal::ChangeQueue()); |
| 429 } | 429 } |
| 430 | 430 |
| 431 MessageCenterImpl::~MessageCenterImpl() {} | 431 MessageCenterImpl::~MessageCenterImpl() { |
| 432 SetNotifierSettingsProvider(NULL); |
| 433 } |
| 432 | 434 |
| 433 void MessageCenterImpl::AddObserver(MessageCenterObserver* observer) { | 435 void MessageCenterImpl::AddObserver(MessageCenterObserver* observer) { |
| 434 observer_list_.AddObserver(observer); | 436 observer_list_.AddObserver(observer); |
| 435 } | 437 } |
| 436 | 438 |
| 437 void MessageCenterImpl::RemoveObserver(MessageCenterObserver* observer) { | 439 void MessageCenterImpl::RemoveObserver(MessageCenterObserver* observer) { |
| 438 observer_list_.RemoveObserver(observer); | 440 observer_list_.RemoveObserver(observer); |
| 439 } | 441 } |
| 440 | 442 |
| 441 void MessageCenterImpl::AddNotificationBlocker(NotificationBlocker* blocker) { | 443 void MessageCenterImpl::AddNotificationBlocker(NotificationBlocker* blocker) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 observer_list_, | 475 observer_list_, |
| 474 OnNotificationUpdated(*iter)); | 476 OnNotificationUpdated(*iter)); |
| 475 } | 477 } |
| 476 notification_cache_.Rebuild( | 478 notification_cache_.Rebuild( |
| 477 notification_list_->GetVisibleNotifications(blockers_)); | 479 notification_list_->GetVisibleNotifications(blockers_)); |
| 478 FOR_EACH_OBSERVER(MessageCenterObserver, | 480 FOR_EACH_OBSERVER(MessageCenterObserver, |
| 479 observer_list_, | 481 observer_list_, |
| 480 OnBlockingStateChanged(blocker)); | 482 OnBlockingStateChanged(blocker)); |
| 481 } | 483 } |
| 482 | 484 |
| 485 void MessageCenterImpl::UpdateIconImage( |
| 486 const NotifierId& notifier_id,const gfx::Image& icon) {} |
| 487 |
| 488 void MessageCenterImpl::NotifierGroupChanged() {} |
| 489 |
| 490 void MessageCenterImpl::NotifierEnabledChanged( |
| 491 const NotifierId& notifier_id, bool enabled) { |
| 492 if (!enabled) { |
| 493 RemoveNotificationsForNotifierId(notifier_id); |
| 494 } |
| 495 } |
| 496 |
| 483 void MessageCenterImpl::SetVisibility(Visibility visibility) { | 497 void MessageCenterImpl::SetVisibility(Visibility visibility) { |
| 484 std::set<std::string> updated_ids; | 498 std::set<std::string> updated_ids; |
| 485 notification_list_->SetMessageCenterVisible( | 499 notification_list_->SetMessageCenterVisible( |
| 486 (visibility == VISIBILITY_MESSAGE_CENTER), &updated_ids); | 500 (visibility == VISIBILITY_MESSAGE_CENTER), &updated_ids); |
| 487 notification_cache_.RecountUnread(); | 501 notification_cache_.RecountUnread(); |
| 488 | 502 |
| 489 for (std::set<std::string>::const_iterator iter = updated_ids.begin(); | 503 for (std::set<std::string>::const_iterator iter = updated_ids.begin(); |
| 490 iter != updated_ids.end(); | 504 iter != updated_ids.end(); |
| 491 ++iter) { | 505 ++iter) { |
| 492 FOR_EACH_OBSERVER( | 506 FOR_EACH_OBSERVER( |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 delegate->Close(by_user); | 657 delegate->Close(by_user); |
| 644 | 658 |
| 645 notification_list_->RemoveNotification(copied_id); | 659 notification_list_->RemoveNotification(copied_id); |
| 646 notification_cache_.Rebuild( | 660 notification_cache_.Rebuild( |
| 647 notification_list_->GetVisibleNotifications(blockers_)); | 661 notification_list_->GetVisibleNotifications(blockers_)); |
| 648 FOR_EACH_OBSERVER(MessageCenterObserver, | 662 FOR_EACH_OBSERVER(MessageCenterObserver, |
| 649 observer_list_, | 663 observer_list_, |
| 650 OnNotificationRemoved(copied_id, by_user)); | 664 OnNotificationRemoved(copied_id, by_user)); |
| 651 } | 665 } |
| 652 | 666 |
| 667 void MessageCenterImpl::RemoveNotificationsForNotifierId( |
| 668 const NotifierId& notifier_id) { |
| 669 NotificationList::Notifications notifications = |
| 670 notification_list_->GetNotificationsByNotifierId(notifier_id); |
| 671 for (NotificationList::Notifications::const_iterator iter = |
| 672 notifications.begin(); iter != notifications.end(); ++iter) { |
| 673 RemoveNotification((*iter)->id(), false); |
| 674 } |
| 675 if (!notifications.empty()) { |
| 676 notification_cache_.Rebuild( |
| 677 notification_list_->GetVisibleNotifications(blockers_)); |
| 678 } |
| 679 } |
| 680 |
| 653 void MessageCenterImpl::RemoveAllNotifications(bool by_user) { | 681 void MessageCenterImpl::RemoveAllNotifications(bool by_user) { |
| 654 // Using not |blockers_| but an empty list since it wants to remove literally | 682 // Using not |blockers_| but an empty list since it wants to remove literally |
| 655 // all notifications. | 683 // all notifications. |
| 656 RemoveNotifications(by_user, NotificationBlockers()); | 684 RemoveNotifications(by_user, NotificationBlockers()); |
| 657 } | 685 } |
| 658 | 686 |
| 659 void MessageCenterImpl::RemoveAllVisibleNotifications(bool by_user) { | 687 void MessageCenterImpl::RemoveAllVisibleNotifications(bool by_user) { |
| 660 RemoveNotifications(by_user, blockers_); | 688 RemoveNotifications(by_user, blockers_); |
| 661 } | 689 } |
| 662 | 690 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 OnNotificationUpdated(notification_id)); | 773 OnNotificationUpdated(notification_id)); |
| 746 } | 774 } |
| 747 } | 775 } |
| 748 | 776 |
| 749 void MessageCenterImpl::DisableNotificationsByNotifier( | 777 void MessageCenterImpl::DisableNotificationsByNotifier( |
| 750 const NotifierId& notifier_id) { | 778 const NotifierId& notifier_id) { |
| 751 if (settings_provider_) { | 779 if (settings_provider_) { |
| 752 // TODO(mukai): SetNotifierEnabled can just accept notifier_id? | 780 // TODO(mukai): SetNotifierEnabled can just accept notifier_id? |
| 753 Notifier notifier(notifier_id, base::string16(), true); | 781 Notifier notifier(notifier_id, base::string16(), true); |
| 754 settings_provider_->SetNotifierEnabled(notifier, false); | 782 settings_provider_->SetNotifierEnabled(notifier, false); |
| 755 } | 783 // The settings provider will call back to remove the notifications |
| 756 | 784 // belonging to the notifier id. |
| 757 NotificationList::Notifications notifications = | 785 } else { |
| 758 notification_list_->GetNotificationsByNotifierId(notifier_id); | 786 RemoveNotificationsForNotifierId(notifier_id); |
| 759 for (NotificationList::Notifications::const_iterator iter = | |
| 760 notifications.begin(); iter != notifications.end();) { | |
| 761 std::string id = (*iter)->id(); | |
| 762 iter++; | |
| 763 RemoveNotification(id, false); | |
| 764 } | |
| 765 if (!notifications.empty()) { | |
| 766 notification_cache_.Rebuild( | |
| 767 notification_list_->GetVisibleNotifications(blockers_)); | |
| 768 } | 787 } |
| 769 } | 788 } |
| 770 | 789 |
| 771 void MessageCenterImpl::ClickOnNotification(const std::string& id) { | 790 void MessageCenterImpl::ClickOnNotification(const std::string& id) { |
| 772 if (!HasNotification(id)) | 791 if (!HasNotification(id)) |
| 773 return; | 792 return; |
| 774 if (HasPopupNotifications()) | 793 if (HasPopupNotifications()) |
| 775 MarkSinglePopupAsShown(id, true); | 794 MarkSinglePopupAsShown(id, true); |
| 776 scoped_refptr<NotificationDelegate> delegate = | 795 scoped_refptr<NotificationDelegate> delegate = |
| 777 notification_list_->GetNotificationDelegate(id); | 796 notification_list_->GetNotificationDelegate(id); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 if (delegate.get()) | 839 if (delegate.get()) |
| 821 delegate->Display(); | 840 delegate->Display(); |
| 822 FOR_EACH_OBSERVER( | 841 FOR_EACH_OBSERVER( |
| 823 MessageCenterObserver, | 842 MessageCenterObserver, |
| 824 observer_list_, | 843 observer_list_, |
| 825 OnNotificationDisplayed(id, source)); | 844 OnNotificationDisplayed(id, source)); |
| 826 } | 845 } |
| 827 | 846 |
| 828 void MessageCenterImpl::SetNotifierSettingsProvider( | 847 void MessageCenterImpl::SetNotifierSettingsProvider( |
| 829 NotifierSettingsProvider* provider) { | 848 NotifierSettingsProvider* provider) { |
| 849 if (settings_provider_) { |
| 850 settings_provider_->RemoveObserver(this); |
| 851 settings_provider_ = NULL; |
| 852 } |
| 830 settings_provider_ = provider; | 853 settings_provider_ = provider; |
| 854 if (settings_provider_) |
| 855 settings_provider_->AddObserver(this); |
| 831 } | 856 } |
| 832 | 857 |
| 833 NotifierSettingsProvider* MessageCenterImpl::GetNotifierSettingsProvider() { | 858 NotifierSettingsProvider* MessageCenterImpl::GetNotifierSettingsProvider() { |
| 834 return settings_provider_; | 859 return settings_provider_; |
| 835 } | 860 } |
| 836 | 861 |
| 837 void MessageCenterImpl::SetQuietMode(bool in_quiet_mode) { | 862 void MessageCenterImpl::SetQuietMode(bool in_quiet_mode) { |
| 838 if (in_quiet_mode != notification_list_->quiet_mode()) { | 863 if (in_quiet_mode != notification_list_->quiet_mode()) { |
| 839 notification_list_->SetQuietMode(in_quiet_mode); | 864 notification_list_->SetQuietMode(in_quiet_mode); |
| 840 FOR_EACH_OBSERVER(MessageCenterObserver, | 865 FOR_EACH_OBSERVER(MessageCenterObserver, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 void MessageCenterImpl::PausePopupTimers() { | 897 void MessageCenterImpl::PausePopupTimers() { |
| 873 if (popup_timers_controller_.get()) | 898 if (popup_timers_controller_.get()) |
| 874 popup_timers_controller_->PauseAll(); | 899 popup_timers_controller_->PauseAll(); |
| 875 } | 900 } |
| 876 | 901 |
| 877 void MessageCenterImpl::DisableTimersForTest() { | 902 void MessageCenterImpl::DisableTimersForTest() { |
| 878 popup_timers_controller_.reset(); | 903 popup_timers_controller_.reset(); |
| 879 } | 904 } |
| 880 | 905 |
| 881 } // namespace message_center | 906 } // namespace message_center |
| OLD | NEW |