Xiyuan Xia | 7107d49 | 2019-06-05 16:58:54 | [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 | #ifndef ASH_SHUTDOWN_CONTROLLER_IMPL_H_ |
| 6 | #define ASH_SHUTDOWN_CONTROLLER_IMPL_H_ |
| 7 | |
| 8 | #include "ash/ash_export.h" |
| 9 | #include "ash/public/cpp/shutdown_controller.h" |
Xiyuan Xia | 7107d49 | 2019-06-05 16:58:54 | [diff] [blame] | 10 | #include "base/observer_list.h" |
| 11 | |
| 12 | namespace ash { |
| 13 | |
| 14 | enum class ShutdownReason; |
| 15 | |
| 16 | // Handles actual device shutdown by making requests to powerd over D-Bus. |
| 17 | // Caches the DeviceRebootOnShutdown device policy sent from Chrome. |
| 18 | class ASH_EXPORT ShutdownControllerImpl : public ShutdownController { |
| 19 | public: |
| 20 | class Observer { |
| 21 | public: |
| 22 | virtual ~Observer() {} |
| 23 | |
| 24 | // Called when shutdown policy changes. |
| 25 | virtual void OnShutdownPolicyChanged(bool reboot_on_shutdown) = 0; |
| 26 | }; |
| 27 | |
| 28 | ShutdownControllerImpl(); |
Peter Boström | ec31a04 | 2021-09-16 23:37:34 | [diff] [blame] | 29 | |
| 30 | ShutdownControllerImpl(const ShutdownControllerImpl&) = delete; |
| 31 | ShutdownControllerImpl& operator=(const ShutdownControllerImpl&) = delete; |
| 32 | |
Xiyuan Xia | 7107d49 | 2019-06-05 16:58:54 | [diff] [blame] | 33 | ~ShutdownControllerImpl() override; |
| 34 | |
| 35 | void AddObserver(Observer* observer); |
| 36 | void RemoveObserver(Observer* observer); |
| 37 | |
| 38 | bool reboot_on_shutdown() const { return reboot_on_shutdown_; } |
| 39 | |
| 40 | // ShutdownController: |
| 41 | void SetRebootOnShutdown(bool reboot_on_shutdown) override; |
| 42 | void ShutDownOrReboot(ShutdownReason reason) override; |
| 43 | |
| 44 | private: |
| 45 | // Cached copy of the DeviceRebootOnShutdown policy from chrome. |
| 46 | bool reboot_on_shutdown_ = false; |
| 47 | |
| 48 | base::ObserverList<Observer>::Unchecked observers_; |
Xiyuan Xia | 7107d49 | 2019-06-05 16:58:54 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | } // namespace ash |
| 52 | |
| 53 | #endif // ASH_SHUTDOWN_CONTROLLER_IMPL_H_ |