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