ash_message_center_lock_screen_controller.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2018 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_ASH_MESSAGE_CENTER_LOCK_SCREEN_CONTROLLER_H_
  5. #define ASH_SYSTEM_MESSAGE_CENTER_ASH_MESSAGE_CENTER_LOCK_SCREEN_CONTROLLER_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/public/cpp/session/session_observer.h"
  8. #include "base/gtest_prod_util.h"
  9. #include "components/account_id/account_id.h"
  10. #include "third_party/abseil-cpp/absl/types/optional.h"
  11. #include "ui/message_center/lock_screen/lock_screen_controller.h"
  12. namespace ash {
  13. // This class implements the ASH logic for the message center.
  14. class AshMessageCenterLockScreenController
  15. : public message_center::LockScreenController,
  16. public SessionObserver {
  17. public:
  18. // Returns if the message center shows the notifications on the lock screen
  19. // or not. True if it shows, false if doesn't.
  20. static ASH_EXPORT bool IsEnabled();
  21. // Returns if the message center on the lock screen is forcibly disabled,
  22. // due to the policy or the corrupt state.
  23. // When this returns true, |IsEnabled()| must return false.
  24. static ASH_EXPORT bool IsAllowed();
  25. AshMessageCenterLockScreenController();
  26. AshMessageCenterLockScreenController(
  27. const AshMessageCenterLockScreenController&) = delete;
  28. AshMessageCenterLockScreenController& operator=(
  29. const AshMessageCenterLockScreenController&) = delete;
  30. ~AshMessageCenterLockScreenController() override;
  31. // message_center::LockScreenController:
  32. void DismissLockScreenThenExecute(base::OnceClosure pending_callback,
  33. base::OnceClosure cancel_callback,
  34. int message_id) override;
  35. bool IsScreenLocked() const override;
  36. private:
  37. FRIEND_TEST_ALL_PREFIXES(UnifiedSystemTrayControllerTest,
  38. NotificationHiddenView_ModeShow);
  39. FRIEND_TEST_ALL_PREFIXES(UnifiedSystemTrayControllerTest,
  40. NotificationHiddenView_ModeHide);
  41. FRIEND_TEST_ALL_PREFIXES(UnifiedSystemTrayControllerTest,
  42. NotificationHiddenView_ModeHideSensitive);
  43. FRIEND_TEST_ALL_PREFIXES(UnifiedSystemTrayControllerTest,
  44. NotificationHiddenView_ModeProhibited);
  45. // Modes of the lock screen notification.
  46. enum class Mode { PROHIBITED, HIDE, SHOW, HIDE_SENSITIVE };
  47. // Returns the current mode of the lock screen notification.
  48. static Mode GetMode();
  49. // Override the current mode for tests.
  50. // Exporting for test.
  51. static ASH_EXPORT void OverrideModeForTest(absl::optional<Mode> new_mode);
  52. static absl::optional<Mode> overridden_mode_for_testing_;
  53. // SessionObserver:
  54. void OnLockStateChanged(bool locked) override;
  55. void OnActiveUserSessionChanged(const AccountId& account_id) override;
  56. // Shows a message that asks a user to unlock the device.
  57. void EncourageUserToUnlock(int message_id);
  58. bool locked_;
  59. AccountId active_account_id_ = EmptyAccountId();
  60. base::OnceClosure pending_task_;
  61. base::OnceClosure cancel_task_;
  62. ScopedSessionObserver scoped_session_observer_{this};
  63. };
  64. } // namespace ash
  65. #endif // ASH_SYSTEM_MESSAGE_CENTER_ASH_MESSAGE_CENTER_LOCK_SCREEN_CONTROLLER_H_