blob: b11d4e71b404948514c7ba3d5526139e4aabc1ff [file] [log] [blame]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_MESSAGE_CENTER_ASH_MESSAGE_CENTER_LOCK_SCREEN_CONTROLLER_H_
#define ASH_SYSTEM_MESSAGE_CENTER_ASH_MESSAGE_CENTER_LOCK_SCREEN_CONTROLLER_H_
#include "ash/ash_export.h"
#include "ash/session/session_observer.h"
#include "base/optional.h"
#include "components/account_id/account_id.h"
#include "ui/message_center/lock_screen/lock_screen_controller.h"
namespace ash {
// This class implements the ASH logic for the message center.
class AshMessageCenterLockScreenController
: public message_center::LockScreenController,
public SessionObserver {
public:
// Returns if the message center shows the notifications on the lock screen
// or not. True if it shows, false if doesn't.
static ASH_EXPORT bool IsEnabled();
// Returns if the message center on the lock screen is forcibly disabled,
// due to the policy or the corrupt state.
// When this returns true, |IsEnabled()| must return false.
static ASH_EXPORT bool IsAllowed();
AshMessageCenterLockScreenController();
~AshMessageCenterLockScreenController() override;
// message_center::LockScreenController:
void DismissLockScreenThenExecute(base::OnceClosure pending_callback,
base::OnceClosure cancel_callback,
int message_id) override;
bool IsScreenLocked() const override;
private:
FRIEND_TEST_ALL_PREFIXES(UnifiedSystemTrayControllerTest,
NotificationHiddenView_ModeShow);
FRIEND_TEST_ALL_PREFIXES(UnifiedSystemTrayControllerTest,
NotificationHiddenView_ModeHide);
FRIEND_TEST_ALL_PREFIXES(UnifiedSystemTrayControllerTest,
NotificationHiddenView_ModeHideSensitive);
FRIEND_TEST_ALL_PREFIXES(UnifiedSystemTrayControllerTest,
NotificationHiddenView_ModeProhibited);
// Modes of the lock screen notification.
enum class Mode { PROHIBITED, HIDE, SHOW, HIDE_SENSITIVE };
// Returns the current mode of the lock screen notification.
static Mode GetMode();
// Override the current mode for tests.
// Exporting for test.
static ASH_EXPORT void OverrideModeForTest(base::Optional<Mode> new_mode);
static base::Optional<Mode> overridden_mode_for_testing_;
// SessionObserver:
void OnLockStateChanged(bool locked) override;
void OnActiveUserSessionChanged(const AccountId& account_id) override;
// Shows a message that asks a user to unlock the device.
void EncourageUserToUnlock(int message_id);
bool locked_;
AccountId active_account_id_ = EmptyAccountId();
base::OnceClosure pending_task_;
base::OnceClosure cancel_task_;
ScopedSessionObserver scoped_session_observer_{this};
DISALLOW_COPY_AND_ASSIGN(AshMessageCenterLockScreenController);
};
} // namespace ash
#endif // ASH_SYSTEM_MESSAGE_CENTER_ASH_MESSAGE_CENTER_LOCK_SCREEN_CONTROLLER_H_