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" |
Evan Stade | b95cbc3 | 2017-08-09 20:42:41 | [diff] [blame] | 12 | #include "ash/wm/lock_state_controller.h" |
James Cook | 8706262d | 2017-08-22 23:15:26 | [diff] [blame] | 13 | #include "base/metrics/user_metrics.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 14 | #include "base/sys_info.h" |
| 15 | #include "chromeos/dbus/dbus_thread_manager.h" |
| 16 | #include "chromeos/dbus/power_manager_client.h" |
Daniel Erat | 03de51e2 | 2017-09-09 00:51:51 | [diff] [blame^] | 17 | #include "third_party/cros_system_api/dbus/service_constants.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 18 | |
| 19 | namespace ash { |
| 20 | |
| 21 | ShutdownController::ShutdownController() {} |
| 22 | |
| 23 | ShutdownController::~ShutdownController() {} |
| 24 | |
Lann Martin | 4fd794c3 | 2017-06-30 17:51:41 | [diff] [blame] | 25 | void ShutdownController::ShutDownOrReboot(ShutdownReason reason) { |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 26 | // 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 Cook | 8706262d | 2017-08-22 23:15:26 | [diff] [blame] | 32 | if (reason == ShutdownReason::POWER_BUTTON) |
| 33 | base::RecordAction(base::UserMetricsAction("Accel_ShutDown_PowerButton")); |
Lann Martin | 4fd794c3 | 2017-06-30 17:51:41 | [diff] [blame] | 34 | |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 35 | // On real Chrome OS hardware the power manager handles shutdown. |
| 36 | using chromeos::DBusThreadManager; |
Daniel Erat | 03de51e2 | 2017-09-09 00:51:51 | [diff] [blame^] | 37 | 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 Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | void ShutdownController::SetRebootOnShutdown(bool reboot_on_shutdown) { |
| 54 | reboot_on_shutdown_ = reboot_on_shutdown; |
| 55 | } |
| 56 | |
Evan Stade | b95cbc3 | 2017-08-09 20:42:41 | [diff] [blame] | 57 | void ShutdownController::RequestShutdownFromLoginScreen() { |
| 58 | Shell::Get()->lock_state_controller()->RequestShutdown( |
| 59 | ShutdownReason::LOGIN_SHUT_DOWN_BUTTON); |
| 60 | } |
| 61 | |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 62 | void ShutdownController::BindRequest(mojom::ShutdownControllerRequest request) { |
| 63 | bindings_.AddBinding(this, std::move(request)); |
| 64 | } |
| 65 | |
| 66 | } // namespace ash |