James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 1 | // 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 Martin | 4fd794c3 | 2017-06-30 17:51:41 | [diff] [blame^] | 7 | #include <utility> |
| 8 | |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 9 | #include "ash/shell.h" |
| 10 | #include "ash/shell_delegate.h" |
Lann Martin | 4fd794c3 | 2017-06-30 17:51:41 | [diff] [blame^] | 11 | #include "ash/shutdown_reason.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 12 | #include "base/sys_info.h" |
| 13 | #include "chromeos/dbus/dbus_thread_manager.h" |
| 14 | #include "chromeos/dbus/power_manager_client.h" |
| 15 | |
| 16 | namespace ash { |
| 17 | |
| 18 | ShutdownController::ShutdownController() {} |
| 19 | |
| 20 | ShutdownController::~ShutdownController() {} |
| 21 | |
Lann Martin | 4fd794c3 | 2017-06-30 17:51:41 | [diff] [blame^] | 22 | void ShutdownController::ShutDownOrReboot(ShutdownReason reason) { |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 23 | // 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 Martin | 4fd794c3 | 2017-06-30 17:51:41 | [diff] [blame^] | 29 | if (reason == ShutdownReason::POWER_BUTTON) { |
| 30 | Shell::Get()->metrics()->RecordUserMetricsAction( |
| 31 | UMA_ACCEL_SHUT_DOWN_POWER_BUTTON); |
| 32 | } |
| 33 | |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 34 | // 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 | |
| 42 | void ShutdownController::SetRebootOnShutdown(bool reboot_on_shutdown) { |
| 43 | reboot_on_shutdown_ = reboot_on_shutdown; |
| 44 | } |
| 45 | |
| 46 | void ShutdownController::BindRequest(mojom::ShutdownControllerRequest request) { |
| 47 | bindings_.AddBinding(this, std::move(request)); |
| 48 | } |
| 49 | |
| 50 | } // namespace ash |