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