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" 10 #include "base/macros.h" 11 #include "base/observer_list.h" 12 13 namespace ash { 14 15 enum class ShutdownReason; 16 17 // Handles actual device shutdown by making requests to powerd over D-Bus. 18 // Caches the DeviceRebootOnShutdown device policy sent from Chrome. 19 class ASH_EXPORT ShutdownControllerImpl : public ShutdownController { 20 public: 21 class Observer { 22 public: ~Observer()23 virtual ~Observer() {} 24 25 // Called when shutdown policy changes. 26 virtual void OnShutdownPolicyChanged(bool reboot_on_shutdown) = 0; 27 }; 28 29 ShutdownControllerImpl(); 30 ~ShutdownControllerImpl() override; 31 32 void AddObserver(Observer* observer); 33 void RemoveObserver(Observer* observer); 34 reboot_on_shutdown()35 bool reboot_on_shutdown() const { return reboot_on_shutdown_; } 36 37 // ShutdownController: 38 void SetRebootOnShutdown(bool reboot_on_shutdown) override; 39 void ShutDownOrReboot(ShutdownReason reason) override; 40 41 private: 42 // Cached copy of the DeviceRebootOnShutdown policy from chrome. 43 bool reboot_on_shutdown_ = false; 44 45 base::ObserverList<Observer>::Unchecked observers_; 46 47 DISALLOW_COPY_AND_ASSIGN(ShutdownControllerImpl); 48 }; 49 50 } // namespace ash 51 52 #endif // ASH_SHUTDOWN_CONTROLLER_IMPL_H_ 53