[M108 Migration] Support standard build for armv7hl architecture
[platform/framework/web/chromium-efl.git] / ash / shutdown_controller_impl.cc
1 // Copyright 2016 The Chromium Authors
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_impl.h"
6
7 #include <utility>
8
9 #include "ash/session/session_controller_impl.h"
10 #include "ash/shell.h"
11 #include "ash/shutdown_reason.h"
12 #include "base/metrics/user_metrics.h"
13 #include "base/strings/stringprintf.h"
14 #include "base/system/sys_info.h"
15 #include "chromeos/dbus/power/power_manager_client.h"
16 #include "third_party/cros_system_api/dbus/service_constants.h"
17
18 namespace ash {
19
20 ShutdownControllerImpl::ShutdownControllerImpl() = default;
21
22 ShutdownControllerImpl::~ShutdownControllerImpl() = default;
23
24 void ShutdownControllerImpl::AddObserver(Observer* observer) {
25   observers_.AddObserver(observer);
26 }
27
28 void ShutdownControllerImpl::RemoveObserver(Observer* observer) {
29   observers_.RemoveObserver(observer);
30 }
31
32 void ShutdownControllerImpl::SetRebootOnShutdown(bool reboot_on_shutdown) {
33   if (reboot_on_shutdown_ == reboot_on_shutdown)
34     return;
35   reboot_on_shutdown_ = reboot_on_shutdown;
36   for (auto& observer : observers_)
37     observer.OnShutdownPolicyChanged(reboot_on_shutdown_);
38 }
39
40 void ShutdownControllerImpl::ShutDownOrReboot(ShutdownReason reason) {
41   // For developers on Linux desktop just exit the app.
42   if (!base::SysInfo::IsRunningOnChromeOS()) {
43     Shell::Get()->session_controller()->RequestSignOut();
44     return;
45   }
46
47   if (reason == ShutdownReason::POWER_BUTTON)
48     base::RecordAction(base::UserMetricsAction("Accel_ShutDown_PowerButton"));
49
50   // On real Chrome OS hardware the power manager handles shutdown.
51   std::string description = base::StringPrintf("UI request from ash: %s",
52                                                ShutdownReasonToString(reason));
53   if (reboot_on_shutdown_) {
54     chromeos::PowerManagerClient::Get()->RequestRestart(
55         power_manager::REQUEST_RESTART_FOR_USER, description);
56   } else {
57     chromeos::PowerManagerClient::Get()->RequestShutdown(
58         power_manager::REQUEST_SHUTDOWN_FOR_USER, description);
59   }
60 }
61
62 }  // namespace ash