blob: 4cbf57db238b236e57033107bedc34dc42f7694b [file] [log] [blame]
James Cookb0bf8e82017-04-09 17:01:441// Copyright 2016 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
5#include "ash/shutdown_controller.h"
6
Lann Martin4fd794c32017-06-30 17:51:417#include <utility>
8
James Cookb0bf8e82017-04-09 17:01:449#include "ash/shell.h"
10#include "ash/shell_delegate.h"
Lann Martin4fd794c32017-06-30 17:51:4111#include "ash/shutdown_reason.h"
Evan Stadeb95cbc32017-08-09 20:42:4112#include "ash/wm/lock_state_controller.h"
James Cook8706262d2017-08-22 23:15:2613#include "base/metrics/user_metrics.h"
James Cookb0bf8e82017-04-09 17:01:4414#include "base/sys_info.h"
15#include "chromeos/dbus/dbus_thread_manager.h"
16#include "chromeos/dbus/power_manager_client.h"
Daniel Erat03de51e22017-09-09 00:51:5117#include "third_party/cros_system_api/dbus/service_constants.h"
James Cookb0bf8e82017-04-09 17:01:4418
19namespace ash {
20
21ShutdownController::ShutdownController() {}
22
23ShutdownController::~ShutdownController() {}
24
Lann Martin4fd794c32017-06-30 17:51:4125void ShutdownController::ShutDownOrReboot(ShutdownReason reason) {
James Cookb0bf8e82017-04-09 17:01:4426 // For developers on Linux desktop just exit the app.
27 if (!base::SysInfo::IsRunningOnChromeOS()) {
28 Shell::Get()->shell_delegate()->Exit();
29 return;
30 }
31
James Cook8706262d2017-08-22 23:15:2632 if (reason == ShutdownReason::POWER_BUTTON)
33 base::RecordAction(base::UserMetricsAction("Accel_ShutDown_PowerButton"));
Lann Martin4fd794c32017-06-30 17:51:4134
James Cookb0bf8e82017-04-09 17:01:4435 // On real Chrome OS hardware the power manager handles shutdown.
36 using chromeos::DBusThreadManager;
Daniel Erat03de51e22017-09-09 00:51:5137 constexpr char kDescription[] = "UI request from ash";
38 if (reboot_on_shutdown_) {
39 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(
40 reason == ShutdownReason::UNKNOWN
41 ? power_manager::REQUEST_RESTART_OTHER
42 : power_manager::REQUEST_RESTART_FOR_USER,
43 kDescription);
44 } else {
45 DBusThreadManager::Get()->GetPowerManagerClient()->RequestShutdown(
46 reason == ShutdownReason::UNKNOWN
47 ? power_manager::REQUEST_SHUTDOWN_OTHER
48 : power_manager::REQUEST_SHUTDOWN_FOR_USER,
49 kDescription);
50 }
James Cookb0bf8e82017-04-09 17:01:4451}
52
53void ShutdownController::SetRebootOnShutdown(bool reboot_on_shutdown) {
54 reboot_on_shutdown_ = reboot_on_shutdown;
55}
56
Evan Stadeb95cbc32017-08-09 20:42:4157void ShutdownController::RequestShutdownFromLoginScreen() {
58 Shell::Get()->lock_state_controller()->RequestShutdown(
59 ShutdownReason::LOGIN_SHUT_DOWN_BUTTON);
60}
61
James Cookb0bf8e82017-04-09 17:01:4462void ShutdownController::BindRequest(mojom::ShutdownControllerRequest request) {
63 bindings_.AddBinding(this, std::move(request));
64}
65
66} // namespace ash