OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014 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 CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_SHUTDOWN_POLICY_OBSERVER_H_ | |
6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_SHUTDOWN_POLICY_OBSERVER_H_ | |
7 | |
8 #include "base/callback_forward.h" | |
9 #include "base/macros.h" | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "chrome/browser/chromeos/settings/cros_settings.h" | |
13 | |
14 namespace chromeos { | |
15 | |
16 // This class observes the device setting |DeviceRebootOnShutdown|. Changes to | |
17 // this policy are communicated to the ShutdownPolicyObserver::Delegate by | |
18 // calling its OnShutdownPolicyChanged method with the new state of the policy. | |
19 class ShutdownPolicyObserver { | |
20 public: | |
21 // This callback is passed to CheckIfRebootOnShutdown, which invokes it with | |
22 // the current state of the |DeviceRebootOnShutdown| policy once a trusted of | |
23 // policies is established. | |
24 using RebootOnShutdownCallback = base::Callback<void(bool)>; | |
25 | |
26 // This delegate is called when the |DeviceRebootOnShutdown| policy changes. | |
27 class Delegate { | |
28 public: | |
29 virtual void OnShutdownPolicyChanged(bool reboot_on_shutdown) = 0; | |
30 | |
31 protected: | |
32 virtual ~Delegate() {} | |
33 }; | |
34 | |
35 ShutdownPolicyObserver(CrosSettings* cros_settings, Delegate* delegate); | |
36 ~ShutdownPolicyObserver(); | |
37 | |
38 // Once a trusted set of policies is established, this function calls | |
39 // |callback| with the trusted state of the |DeviceRebootOnShutdown| policy. | |
40 void CheckIfRebootOnShutdown(const RebootOnShutdownCallback& callback); | |
41 | |
42 // Resets the policy subscription and clears the delegate. | |
43 void Shutdown(); | |
44 | |
45 private: | |
46 void CallDelegate(bool reboot_on_shutdown); | |
47 | |
48 void OnShutdownPolicyChanged(); | |
49 | |
50 CrosSettings* cros_settings_; | |
51 | |
52 Delegate* delegate_; | |
53 | |
54 scoped_ptr<CrosSettings::ObserverSubscription> shutdown_policy_subscription_; | |
55 | |
56 base::WeakPtrFactory<ShutdownPolicyObserver> weak_factory_; | |
57 | |
58 DISALLOW_COPY_AND_ASSIGN(ShutdownPolicyObserver); | |
59 }; | |
60 | |
61 } // namespace chromeos | |
62 | |
63 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_SHUTDOWN_POLICY_OBSERVER_H_ | |
OLD | NEW |