blob: d4db149314eb7c2750abb9e8fead2f17f43cd7b9 [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"
James Cookb0bf8e82017-04-09 17:01:4412#include "base/sys_info.h"
13#include "chromeos/dbus/dbus_thread_manager.h"
14#include "chromeos/dbus/power_manager_client.h"
15
16namespace ash {
17
18ShutdownController::ShutdownController() {}
19
20ShutdownController::~ShutdownController() {}
21
Lann Martin4fd794c32017-06-30 17:51:4122void ShutdownController::ShutDownOrReboot(ShutdownReason reason) {
James Cookb0bf8e82017-04-09 17:01:4423 // For developers on Linux desktop just exit the app.
24 if (!base::SysInfo::IsRunningOnChromeOS()) {
25 Shell::Get()->shell_delegate()->Exit();
26 return;
27 }
28
Lann Martin4fd794c32017-06-30 17:51:4129 if (reason == ShutdownReason::POWER_BUTTON) {
30 Shell::Get()->metrics()->RecordUserMetricsAction(
31 UMA_ACCEL_SHUT_DOWN_POWER_BUTTON);
32 }
33
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
46void ShutdownController::BindRequest(mojom::ShutdownControllerRequest request) {
47 bindings_.AddBinding(this, std::move(request));
48}
49
50} // namespace ash