Commit f86314fc authored by Daniel Erat's avatar Daniel Erat Committed by Commit Bot

ash: Pass more-detailed shutdown reasons to powerd.

Make ShutdownController pass the actual cause of a shutdown
request (power button, system tray, or login screen) to
powerd rather just a generic "UI request from ash" string.

Also get rid of an "unknown" ShutdownReason enum value that
looks like it was just used as an initial placeholder within
LockStateController.

Bug: none
Change-Id: I0760e68a6bf462c508d1f2d8740b8e6a1cf31191
Reviewed-on: https://chromium-review.googlesource.com/933546Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Reviewed-by: default avatarQiang Xu <warx@google.com>
Commit-Queue: Dan Erat <derat@chromium.org>
Cr-Commit-Position: refs/heads/master@{#538896}
parent b5198056
......@@ -457,6 +457,8 @@ component("ash") {
"shell_port_mus.h",
"shutdown_controller.cc",
"shutdown_controller.h",
"shutdown_reason.cc",
"shutdown_reason.h",
"sidebar/sidebar.cc",
"sidebar/sidebar.h",
"sidebar/sidebar_widget.cc",
......
......@@ -11,6 +11,7 @@
#include "ash/shutdown_reason.h"
#include "ash/wm/lock_state_controller.h"
#include "base/metrics/user_metrics.h"
#include "base/strings/stringprintf.h"
#include "base/sys_info.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/power_manager_client.h"
......@@ -42,19 +43,14 @@ void ShutdownController::ShutDownOrReboot(ShutdownReason reason) {
// On real Chrome OS hardware the power manager handles shutdown.
using chromeos::DBusThreadManager;
constexpr char kDescription[] = "UI request from ash";
std::string description = base::StringPrintf("UI request from ash: %s",
ShutdownReasonToString(reason));
if (reboot_on_shutdown_) {
DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(
reason == ShutdownReason::UNKNOWN
? power_manager::REQUEST_RESTART_OTHER
: power_manager::REQUEST_RESTART_FOR_USER,
kDescription);
power_manager::REQUEST_RESTART_FOR_USER, description);
} else {
DBusThreadManager::Get()->GetPowerManagerClient()->RequestShutdown(
reason == ShutdownReason::UNKNOWN
? power_manager::REQUEST_SHUTDOWN_OTHER
: power_manager::REQUEST_SHUTDOWN_FOR_USER,
kDescription);
power_manager::REQUEST_SHUTDOWN_FOR_USER, description);
}
}
......
// 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.
#include "ash/shutdown_reason.h"
#include "base/logging.h"
namespace ash {
const char* ShutdownReasonToString(ShutdownReason reason) {
switch (reason) {
case ShutdownReason::POWER_BUTTON:
return "power button";
case ShutdownReason::LOGIN_SHUT_DOWN_BUTTON:
return "login shut down button";
case ShutdownReason::TRAY_SHUT_DOWN_BUTTON:
return "tray shut down button";
}
NOTREACHED() << "Invalid reason " << static_cast<int>(reason);
return "invalid";
}
} // namespace ash
......@@ -8,12 +8,14 @@
namespace ash {
enum class ShutdownReason {
UNKNOWN, // Reason unknown or not applicable.
POWER_BUTTON, // User pressed the (physical) power button.
LOGIN_SHUT_DOWN_BUTTON, // User pressed the login screen shut down button.
TRAY_SHUT_DOWN_BUTTON, // User pressed the tray shut down button.
};
// Returns a string describing |reason|.
const char* ShutdownReasonToString(ShutdownReason reason);
} // namespace ash
#endif // ASH_SHUTDOWN_REASON_H_
......@@ -273,6 +273,7 @@ void LockStateController::OnLockFailTimeout() {
}
void LockStateController::StartLockToShutdownTimer() {
DCHECK(shutdown_reason_);
shutdown_after_lock_ = false;
lock_to_shutdown_timer_.Stop();
lock_to_shutdown_timer_.Start(
......@@ -332,8 +333,9 @@ void LockStateController::StartRealShutdownTimer(bool with_animation_time) {
void LockStateController::OnRealPowerTimeout() {
VLOG(1) << "OnRealPowerTimeout";
DCHECK(shutting_down_);
DCHECK(shutdown_reason_);
// Shut down or reboot based on device policy.
shutdown_controller_->ShutDownOrReboot(shutdown_reason_);
shutdown_controller_->ShutDownOrReboot(*shutdown_reason_);
}
void LockStateController::StartCancellableShutdownAnimation() {
......
......@@ -13,6 +13,7 @@
#include "ash/wm/session_state_animator.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/time/time.h"
#include "base/timer/elapsed_timer.h"
#include "base/timer/timer.h"
......@@ -197,7 +198,7 @@ class ASH_EXPORT LockStateController : public aura::WindowTreeHostObserver,
bool shutting_down_ = false;
// The reason (e.g. user action) for a pending shutdown.
ShutdownReason shutdown_reason_ = ShutdownReason::UNKNOWN;
base::Optional<ShutdownReason> shutdown_reason_;
// Indicates whether controller should proceed to (cancellable) shutdown after
// locking.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment