shutdown_controller_impl.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #ifndef ASH_SHUTDOWN_CONTROLLER_IMPL_H_
  5. #define ASH_SHUTDOWN_CONTROLLER_IMPL_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/public/cpp/shutdown_controller.h"
  8. #include "base/observer_list.h"
  9. namespace ash {
  10. enum class ShutdownReason;
  11. // Handles actual device shutdown by making requests to powerd over D-Bus.
  12. // Caches the DeviceRebootOnShutdown device policy sent from Chrome.
  13. class ASH_EXPORT ShutdownControllerImpl : public ShutdownController {
  14. public:
  15. class Observer {
  16. public:
  17. virtual ~Observer() {}
  18. // Called when shutdown policy changes.
  19. virtual void OnShutdownPolicyChanged(bool reboot_on_shutdown) = 0;
  20. };
  21. ShutdownControllerImpl();
  22. ShutdownControllerImpl(const ShutdownControllerImpl&) = delete;
  23. ShutdownControllerImpl& operator=(const ShutdownControllerImpl&) = delete;
  24. ~ShutdownControllerImpl() override;
  25. void AddObserver(Observer* observer);
  26. void RemoveObserver(Observer* observer);
  27. bool reboot_on_shutdown() const { return reboot_on_shutdown_; }
  28. // ShutdownController:
  29. void SetRebootOnShutdown(bool reboot_on_shutdown) override;
  30. void ShutDownOrReboot(ShutdownReason reason) override;
  31. private:
  32. // Cached copy of the DeviceRebootOnShutdown policy from chrome.
  33. bool reboot_on_shutdown_ = false;
  34. base::ObserverList<Observer>::Unchecked observers_;
  35. };
  36. } // namespace ash
  37. #endif // ASH_SHUTDOWN_CONTROLLER_IMPL_H_