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.
5 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_SHUTDOWN_POLICY_HANDLER_H_
6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_SHUTDOWN_POLICY_HANDLER_H_
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"
16 // This class observes the device setting |DeviceRebootOnShutdown|. Changes to
17 // this policy are communicated to the ShutdownPolicyHandler::Delegate by
18 // calling its OnShutdownPolicyChanged method with the new state of the policy.
19 class ShutdownPolicyHandler
{
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)>;
26 // This delegate is called when the |DeviceRebootOnShutdown| policy changes.
29 virtual void OnShutdownPolicyChanged(bool reboot_on_shutdown
) = 0;
32 virtual ~Delegate() {}
35 ShutdownPolicyHandler(CrosSettings
* cros_settings
, Delegate
* delegate
);
36 ~ShutdownPolicyHandler();
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
);
42 // Resets the policy subscription and clears the delegate.
46 void CallDelegate(bool reboot_on_shutdown
);
48 void OnShutdownPolicyChanged();
50 CrosSettings
* cros_settings_
;
54 scoped_ptr
<CrosSettings::ObserverSubscription
> shutdown_policy_subscription_
;
56 base::WeakPtrFactory
<ShutdownPolicyHandler
> weak_factory_
;
58 DISALLOW_COPY_AND_ASSIGN(ShutdownPolicyHandler
);
61 } // namespace chromeos
63 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_SHUTDOWN_POLICY_HANDLER_H_