session_state_notification_blocker.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 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 ASH_SYSTEM_MESSAGE_CENTER_SESSION_STATE_NOTIFICATION_BLOCKER_H_
  5. #define ASH_SYSTEM_MESSAGE_CENTER_SESSION_STATE_NOTIFICATION_BLOCKER_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/public/cpp/session/session_observer.h"
  8. #include "base/timer/timer.h"
  9. #include "ui/message_center/notification_blocker.h"
  10. namespace ash {
  11. // A notification blocker which suppresses notifications popups based on the
  12. // session state and active user PrefService readiness reported by the
  13. // SessionController. Only active (logged in, unlocked) sessions with
  14. // initialized PrefService will show user notifications. Kiosk mode sessions
  15. // will never show even system notifications. System notifications with
  16. // elevated priority will be shown regardless of the login/lock state.
  17. class ASH_EXPORT SessionStateNotificationBlocker
  18. : public message_center::NotificationBlocker,
  19. public SessionObserver {
  20. public:
  21. explicit SessionStateNotificationBlocker(
  22. message_center::MessageCenter* message_center);
  23. SessionStateNotificationBlocker(const SessionStateNotificationBlocker&) =
  24. delete;
  25. SessionStateNotificationBlocker& operator=(
  26. const SessionStateNotificationBlocker&) = delete;
  27. ~SessionStateNotificationBlocker() override;
  28. static void SetUseLoginNotificationDelayForTest(bool use_delay);
  29. private:
  30. void OnLoginTimerEnded();
  31. // message_center::NotificationBlocker overrides:
  32. bool ShouldShowNotification(
  33. const message_center::Notification& notification) const override;
  34. bool ShouldShowNotificationAsPopup(
  35. const message_center::Notification& notification) const override;
  36. // SessionObserver overrides:
  37. void OnFirstSessionStarted() override;
  38. void OnSessionStateChanged(session_manager::SessionState state) override;
  39. void OnActiveUserPrefServiceChanged(PrefService* pref_service) override;
  40. void CheckStateAndNotifyIfChanged();
  41. base::OneShotTimer login_delay_timer_;
  42. bool should_show_notification_ = false;
  43. bool should_show_popup_ = false;
  44. };
  45. } // namespace ash
  46. #endif // ASH_SYSTEM_MESSAGE_CENTER_SESSION_STATE_NOTIFICATION_BLOCKER_H_