pe: Clean up LockStateController [1/N]
This is reland of crrev.com/c/5447993 with fixing the failed tests. - Rename the function `StartShutdownAnimation` to eliminate the confusion between it and `RequestShutdown`. - Correct the usage of the two functions, calling `RequestShutdown` when the shutdown is not cancelable from the call sites. Bug: b/333541146, b/334745250 Change-Id: Ia50e46ddb21a8591083d2b0fc918451991ce2c6d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5455314 Commit-Queue: Min Chen <minch@chromium.org> Reviewed-by: Xiyuan Xia <xiyuan@chromium.org> Cr-Commit-Position: refs/heads/main@{#1287569}
This commit is contained in:
@ -55,6 +55,11 @@ class ASH_EXPORT SessionControllerImpl : public SessionController {
|
||||
base::TimeDelta session_length_limit() const { return session_length_limit_; }
|
||||
base::Time session_start_time() const { return session_start_time_; }
|
||||
|
||||
// Returns the ash notion of login status.
|
||||
// NOTE: Prefer GetSessionState() in new code because the concept of
|
||||
// SessionState more closes matches the state in chrome.
|
||||
LoginStatus login_status() const { return login_status_; }
|
||||
|
||||
// Returns the number of signed in users. If 0 is returned, there is either
|
||||
// no session in progress or no active user.
|
||||
int NumberOfLoggedInUsers() const;
|
||||
@ -197,16 +202,11 @@ class ASH_EXPORT SessionControllerImpl : public SessionController {
|
||||
// the active user profile prefs. Returns null early during startup.
|
||||
PrefService* GetActivePrefService() const;
|
||||
|
||||
// Returns the ash notion of login status.
|
||||
// NOTE: Prefer GetSessionState() in new code because the concept of
|
||||
// SessionState more closes matches the state in chrome.
|
||||
LoginStatus login_status() const { return login_status_; }
|
||||
|
||||
// Returns an object of `ScopedScreenLockBlocker`.
|
||||
// `CanLockScreen()` returns false while there is one or more living object.
|
||||
std::unique_ptr<ScopedScreenLockBlocker> GetScopedScreenLockBlocker();
|
||||
|
||||
// SessionController
|
||||
// SessionController:
|
||||
void SetClient(SessionControllerClient* client) override;
|
||||
void SetSessionInfo(const SessionInfo& info) override;
|
||||
void UpdateUserSession(const UserSession& user_session) override;
|
||||
|
@ -49,7 +49,7 @@ constexpr base::TimeDelta kShowMenuWhenScreenOffTimeout =
|
||||
|
||||
// Time that power button should be pressed after power menu is shown before
|
||||
// starting the cancellable pre-shutdown animation.
|
||||
constexpr base::TimeDelta kStartShutdownAnimationTimeout =
|
||||
constexpr base::TimeDelta kRequestCancelableShutdownTimeout =
|
||||
base::Milliseconds(650);
|
||||
|
||||
enum PowerButtonUpState {
|
||||
@ -141,7 +141,8 @@ PowerButtonController::~PowerButtonController() {
|
||||
}
|
||||
|
||||
void PowerButtonController::OnPreShutdownTimeout() {
|
||||
lock_state_controller_->StartShutdownAnimation(ShutdownReason::POWER_BUTTON);
|
||||
lock_state_controller_->RequestCancelableShutdown(
|
||||
ShutdownReason::POWER_BUTTON);
|
||||
// |menu_widget_| might be reset on login status change while shutting down.
|
||||
if (!menu_widget_) {
|
||||
return;
|
||||
@ -212,7 +213,8 @@ void PowerButtonController::OnPowerButtonEvent(
|
||||
display_controller_->SetBacklightsForcedOff(false);
|
||||
|
||||
if (menu_shown_when_power_button_down_) {
|
||||
pre_shutdown_timer_.Start(FROM_HERE, kStartShutdownAnimationTimeout, this,
|
||||
pre_shutdown_timer_.Start(FROM_HERE, kRequestCancelableShutdownTimeout,
|
||||
this,
|
||||
&PowerButtonController::OnPreShutdownTimeout);
|
||||
return;
|
||||
}
|
||||
@ -559,7 +561,8 @@ void PowerButtonController::SetShowMenuAnimationDone() {
|
||||
show_menu_animation_done_ = true;
|
||||
if (button_type_ != ButtonType::LEGACY &&
|
||||
shutdown_reason_ == ShutdownReason::POWER_BUTTON) {
|
||||
pre_shutdown_timer_.Start(FROM_HERE, kStartShutdownAnimationTimeout, this,
|
||||
pre_shutdown_timer_.Start(FROM_HERE, kRequestCancelableShutdownTimeout,
|
||||
this,
|
||||
&PowerButtonController::OnPreShutdownTimeout);
|
||||
}
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ void PowerButtonMenuView::RecreateItems() {
|
||||
add_remove_item(
|
||||
true, PowerButtonMenuActionType::kPowerOff,
|
||||
base::BindRepeating(
|
||||
&LockStateController::StartShutdownAnimation,
|
||||
&LockStateController::RequestShutdown,
|
||||
base::Unretained(Shell::Get()->lock_state_controller()),
|
||||
shutdown_reason_),
|
||||
kSystemPowerButtonMenuPowerOffIcon,
|
||||
|
@ -200,7 +200,7 @@ class PowerButton::MenuController : public ui::SimpleMenuModel::Delegate,
|
||||
case VIEW_ID_QS_POWER_OFF_MENU_BUTTON:
|
||||
quick_settings_metrics_util::RecordQsButtonActivated(
|
||||
QsButtonCatalogName::kPowerOffMenuButton);
|
||||
Shell::Get()->lock_state_controller()->StartShutdownAnimation(
|
||||
Shell::Get()->lock_state_controller()->RequestShutdown(
|
||||
ShutdownReason::TRAY_SHUT_DOWN_BUTTON);
|
||||
break;
|
||||
case VIEW_ID_QS_POWER_SIGNOUT_MENU_BUTTON:
|
||||
|
@ -314,7 +314,7 @@ void LockStateController::StartLockAnimation() {
|
||||
OnLockStateEvent(LockStateObserver::EVENT_PRELOCK_ANIMATION_STARTED);
|
||||
}
|
||||
|
||||
void LockStateController::StartShutdownAnimation(ShutdownReason reason) {
|
||||
void LockStateController::RequestCancelableShutdown(ShutdownReason reason) {
|
||||
shutdown_reason_ = reason;
|
||||
|
||||
HideAndMaybeLockCursor(/*lock=*/false);
|
||||
@ -328,7 +328,7 @@ void LockStateController::RequestRestart(
|
||||
restart_reason_ = reason;
|
||||
restart_description_ = description;
|
||||
HideAndMaybeLockCursor(/*lock=*/false);
|
||||
TakePineImageAndShutdown(/*with_pre_animation=*/true);
|
||||
TakePineImageAndShutdown(/*with_pre_animation=*/false);
|
||||
} else {
|
||||
chromeos::PowerManagerClient::Get()->RequestRestart(reason, description);
|
||||
}
|
||||
|
@ -72,10 +72,14 @@ class ASH_EXPORT LockStateController : public aura::WindowTreeHostObserver,
|
||||
// Starts locking (with slow pre-lock animation) that can be cancelled.
|
||||
void StartLockAnimation();
|
||||
|
||||
// Starts shutting down (with slow animation) that can be cancelled.
|
||||
void StartShutdownAnimation(ShutdownReason reason);
|
||||
// The difference between this and `RequestShutdown` is that this one starts
|
||||
// the shutdown that can be canceled. It is true if the `pre_shutdown_timer_`
|
||||
// is still running (CanCancelShutdownAnimation). Please use only when
|
||||
// necessary, e.g., requesting through the physical power button that it can
|
||||
// be released with a very short press.
|
||||
void RequestCancelableShutdown(ShutdownReason reason);
|
||||
|
||||
// Requests restart with the same animation as `StartShutdownAnimation`.
|
||||
// Requests restart with the same animation as `RequestShutdown`.
|
||||
// `description` is a human-readable string describing the source of request
|
||||
// the restart.
|
||||
void RequestRestart(power_manager::RequestRestartReason reason,
|
||||
|
Reference in New Issue
Block a user