blob: 6d0eb6c138098186b3961102f6d4c9f2e4a036ea [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"
17
18namespace ash {
19
20ShutdownController::ShutdownController() {}
21
22ShutdownController::~ShutdownController() {}
23
Lann Martin4fd794c32017-06-30 17:51:4124void ShutdownController::ShutDownOrReboot(ShutdownReason reason) {
James Cookb0bf8e82017-04-09 17:01:4425 // For developers on Linux desktop just exit the app.
26 if (!base::SysInfo::IsRunningOnChromeOS()) {
27 Shell::Get()->shell_delegate()->Exit();
28 return;
29 }
30
James Cook8706262d2017-08-22 23:15:2631 if (reason == ShutdownReason::POWER_BUTTON)
32 base::RecordAction(base::UserMetricsAction("Accel_ShutDown_PowerButton"));
Lann Martin4fd794c32017-06-30 17:51:4133
James Cookb0bf8e82017-04-09 17:01:4434 // On real Chrome OS hardware the power manager handles shutdown.
35 using chromeos::DBusThreadManager;
36 if (reboot_on_shutdown_)
37 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart();
38 else
39 DBusThreadManager::Get()->GetPowerManagerClient()->RequestShutdown();
40}
41
42void ShutdownController::SetRebootOnShutdown(bool reboot_on_shutdown) {
43 reboot_on_shutdown_ = reboot_on_shutdown;
44}
45
Evan Stadeb95cbc32017-08-09 20:42:4146void ShutdownController::RequestShutdownFromLoginScreen() {
47 Shell::Get()->lock_state_controller()->RequestShutdown(
48 ShutdownReason::LOGIN_SHUT_DOWN_BUTTON);
49}
50
James Cookb0bf8e82017-04-09 17:01:4451void ShutdownController::BindRequest(mojom::ShutdownControllerRequest request) {
52 bindings_.AddBinding(this, std::move(request));
53}
54
55} // namespace ash