message_center_impl.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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.
  4. #ifndef UI_MESSAGE_CENTER_MESSAGE_CENTER_IMPL_H_
  5. #define UI_MESSAGE_CENTER_MESSAGE_CENTER_IMPL_H_
  6. #include <stddef.h>
  7. #include <memory>
  8. #include <string>
  9. #include <vector>
  10. #include "base/callback.h"
  11. #include "base/memory/weak_ptr.h"
  12. #include "base/observer_list.h"
  13. #include "base/threading/thread_checker.h"
  14. #include "base/time/time.h"
  15. #include "base/timer/timer.h"
  16. #include "ui/message_center/message_center.h"
  17. #include "ui/message_center/message_center_observer.h"
  18. #include "ui/message_center/message_center_stats_collector.h"
  19. #include "ui/message_center/message_center_types.h"
  20. #include "ui/message_center/notification_blocker.h"
  21. #include "ui/message_center/popup_timers_controller.h"
  22. #include "ui/message_center/public/cpp/notification.h"
  23. #include "ui/message_center/public/cpp/notifier_id.h"
  24. namespace message_center {
  25. class LockScreenController;
  26. // The default implementation of MessageCenter.
  27. class MessageCenterImpl : public MessageCenter,
  28. public NotificationBlocker::Observer {
  29. public:
  30. explicit MessageCenterImpl(
  31. std::unique_ptr<LockScreenController> lock_screen_controller);
  32. MessageCenterImpl(const MessageCenterImpl&) = delete;
  33. MessageCenterImpl& operator=(const MessageCenterImpl&) = delete;
  34. ~MessageCenterImpl() override;
  35. // MessageCenter overrides:
  36. void AddObserver(MessageCenterObserver* observer) override;
  37. void RemoveObserver(MessageCenterObserver* observer) override;
  38. void AddNotificationBlocker(NotificationBlocker* blocker) override;
  39. void RemoveNotificationBlocker(NotificationBlocker* blocker) override;
  40. void SetVisibility(Visibility visible) override;
  41. bool IsMessageCenterVisible() const override;
  42. void SetHasMessageCenterView(bool has_message_center_view) override;
  43. bool HasMessageCenterView() const override;
  44. size_t NotificationCount() const override;
  45. bool HasPopupNotifications() const override;
  46. bool IsQuietMode() const override;
  47. bool IsSpokenFeedbackEnabled() const override;
  48. Notification* FindNotificationById(const std::string& id) override;
  49. Notification* FindParentNotification(Notification* notification) override;
  50. Notification* FindPopupNotificationById(const std::string& id) override;
  51. Notification* FindVisibleNotificationById(const std::string& id) override;
  52. NotificationList::Notifications FindNotificationsByAppId(
  53. const std::string& app_id) override;
  54. NotificationList::Notifications GetNotifications() override;
  55. const NotificationList::Notifications& GetVisibleNotifications() override;
  56. NotificationList::PopupNotifications GetPopupNotifications() override;
  57. NotificationList::PopupNotifications GetPopupNotificationsWithoutBlocker(
  58. const NotificationBlocker& blocker) const override;
  59. void AddNotification(std::unique_ptr<Notification> notification) override;
  60. void UpdateNotification(
  61. const std::string& old_id,
  62. std::unique_ptr<Notification> new_notification) override;
  63. void RemoveNotification(const std::string& id, bool by_user) override;
  64. void RemoveNotificationsForNotifierId(const NotifierId& notifier_id) override;
  65. void RemoveAllNotifications(bool by_user, RemoveType type) override;
  66. void SetNotificationIcon(const std::string& notification_id,
  67. const ui::ImageModel& image) override;
  68. void SetNotificationImage(const std::string& notification_id,
  69. const gfx::Image& image) override;
  70. void ClickOnNotification(const std::string& id) override;
  71. void ClickOnNotificationButton(const std::string& id,
  72. int button_index) override;
  73. void ClickOnNotificationButtonWithReply(const std::string& id,
  74. int button_index,
  75. const std::u16string& reply) override;
  76. void ClickOnSettingsButton(const std::string& id) override;
  77. void DisableNotification(const std::string& id) override;
  78. void MarkSinglePopupAsShown(const std::string& id,
  79. bool mark_notification_as_read) override;
  80. void ResetPopupTimer(const std::string& id) override;
  81. void ResetSinglePopup(const std::string& id) override;
  82. void DisplayedNotification(const std::string& id,
  83. const DisplaySource source) override;
  84. void SetQuietMode(bool in_quiet_mode) override;
  85. void SetSpokenFeedbackEnabled(bool enabled) override;
  86. void EnterQuietModeWithExpire(const base::TimeDelta& expires_in) override;
  87. void RestartPopupTimers() override;
  88. void PausePopupTimers() override;
  89. const std::u16string& GetSystemNotificationAppName() const override;
  90. void SetSystemNotificationAppName(const std::u16string& name) override;
  91. void OnMessageViewHovered(const std::string& notification_id) override;
  92. // NotificationBlocker::Observer overrides:
  93. void OnBlockingStateChanged(NotificationBlocker* blocker) override;
  94. LockScreenController* lock_screen_controller() {
  95. return lock_screen_controller_.get();
  96. }
  97. const LockScreenController* lock_screen_controller() const {
  98. return lock_screen_controller_.get();
  99. }
  100. protected:
  101. void DisableTimersForTest() override;
  102. private:
  103. THREAD_CHECKER(thread_checker_);
  104. void ClickOnNotificationUnlocked(const std::string& id,
  105. const absl::optional<int>& button_index,
  106. const absl::optional<std::u16string>& reply);
  107. const std::unique_ptr<LockScreenController> lock_screen_controller_;
  108. std::unique_ptr<NotificationList> notification_list_;
  109. NotificationList::Notifications visible_notifications_;
  110. base::ObserverList<MessageCenterObserver> observer_list_;
  111. std::unique_ptr<PopupTimersController> popup_timers_controller_;
  112. base::OneShotTimer quiet_mode_timer_;
  113. std::vector<NotificationBlocker*> blockers_;
  114. bool visible_ = false;
  115. bool has_message_center_view_ = true;
  116. bool spoken_feedback_enabled_ = false;
  117. bool notifications_grouping_enabled_ = false;
  118. std::u16string system_notification_app_name_;
  119. MessageCenterStatsCollector stats_collector_;
  120. };
  121. } // namespace message_center
  122. #endif // UI_MESSAGE_CENTER_MESSAGE_CENTER_IMPL_H_