blob: 1799aad649b53a45af904cdb4e2a38db732a25ed [file] [log] [blame]
Xiyuan Xia7107d492019-06-05 16:58:541// 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 Xia7107d492019-06-05 16:58:5410#include "base/observer_list.h"
11
12namespace ash {
13
14enum 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.
18class 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ömec31a042021-09-16 23:37:3429
30 ShutdownControllerImpl(const ShutdownControllerImpl&) = delete;
31 ShutdownControllerImpl& operator=(const ShutdownControllerImpl&) = delete;
32
Xiyuan Xia7107d492019-06-05 16:58:5433 ~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 Xia7107d492019-06-05 16:58:5449};
50
51} // namespace ash
52
53#endif // ASH_SHUTDOWN_CONTROLLER_IMPL_H_