Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(795)

Side by Side Diff: chrome/browser/chromeos/settings/shutdown_policy_handler.h

Issue 2492063002: chromeos: Simplify ShutdownPolicyHandler
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/macros.h" 10 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
13 #include "chrome/browser/chromeos/settings/cros_settings.h" 12 #include "chrome/browser/chromeos/settings/cros_settings.h"
14 13
15 namespace chromeos { 14 namespace chromeos {
16 15
17 // This class observes the device setting |DeviceRebootOnShutdown|. Changes to 16 // This class observes the device setting |DeviceRebootOnShutdown|. Changes to
18 // this policy are communicated to the ShutdownPolicyHandler::Delegate by 17 // this policy are communicated to the ShutdownPolicyHandler::Delegate by
19 // calling its OnShutdownPolicyChanged method with the new state of the policy. 18 // calling its OnShutdownPolicyChanged method with the new state of the policy.
20 class ShutdownPolicyHandler { 19 class ShutdownPolicyHandler {
21 public: 20 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. 21 // This delegate is called when the |DeviceRebootOnShutdown| policy changes.
28 class Delegate { 22 class Delegate {
29 public: 23 public:
30 virtual void OnShutdownPolicyChanged(bool reboot_on_shutdown) = 0; 24 virtual void OnShutdownPolicyChanged(bool reboot_on_shutdown) = 0;
31 25
32 protected: 26 protected:
33 virtual ~Delegate() {} 27 virtual ~Delegate() {}
34 }; 28 };
35 29
36 ShutdownPolicyHandler(CrosSettings* cros_settings, Delegate* delegate); 30 ShutdownPolicyHandler(CrosSettings* cros_settings, Delegate* delegate);
37 ~ShutdownPolicyHandler(); 31 ~ShutdownPolicyHandler();
38 32
39 // Once a trusted set of policies is established, this function calls 33 // Once a trusted set of policies is established, this function notifies the
40 // |callback| with the trusted state of the |DeviceRebootOnShutdown| policy. 34 // |delegate_| with the trusted state of the |DeviceRebootOnShutdown| policy.
41 void CheckIfRebootOnShutdown(const RebootOnShutdownCallback& callback); 35 void CheckIfRebootOnShutdown();
42
43 // Resets the policy subscription and clears the delegate.
44 void Shutdown();
45 36
46 private: 37 private:
47 void CallDelegate(bool reboot_on_shutdown);
48
49 void OnShutdownPolicyChanged();
50
51 CrosSettings* cros_settings_; 38 CrosSettings* cros_settings_;
52 39
53 Delegate* delegate_; 40 Delegate* delegate_;
54 41
55 std::unique_ptr<CrosSettings::ObserverSubscription> 42 std::unique_ptr<CrosSettings::ObserverSubscription>
56 shutdown_policy_subscription_; 43 shutdown_policy_subscription_;
57 44
58 base::WeakPtrFactory<ShutdownPolicyHandler> weak_factory_; 45 base::WeakPtrFactory<ShutdownPolicyHandler> weak_factory_;
59 46
60 DISALLOW_COPY_AND_ASSIGN(ShutdownPolicyHandler); 47 DISALLOW_COPY_AND_ASSIGN(ShutdownPolicyHandler);
61 }; 48 };
62 49
63 } // namespace chromeos 50 } // namespace chromeos
64 51
65 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_SHUTDOWN_POLICY_HANDLER_H_ 52 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_SHUTDOWN_POLICY_HANDLER_H_
OLDNEW
« no previous file with comments | « ash/common/system/tray/system_tray_delegate.cc ('k') | chrome/browser/chromeos/settings/shutdown_policy_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698