OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_POLICY_CONFIGURATION_POLICY_PROVIDER_WIN_H_ | 5 #ifndef CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_WIN_H_ |
6 #define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_WIN_H_ | 6 #define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_WIN_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/object_watcher.h" | 9 #include "chrome/browser/policy/asynchronous_policy_provider.h" |
10 #include "base/ref_counted.h" | |
11 #include "base/scoped_ptr.h" | |
12 #include "base/waitable_event.h" | |
13 #include "base/weak_ptr.h" | |
14 #include "chrome/browser/policy/configuration_policy_store_interface.h" | |
15 #include "chrome/browser/policy/configuration_policy_provider.h" | |
16 | |
17 namespace base { | |
18 namespace win { | |
19 class RegKey; | |
20 } // namespace win | |
21 } // namespace base | |
22 | 10 |
23 namespace policy { | 11 namespace policy { |
24 | 12 |
25 // An implementation of |ConfigurationPolicyProvider| using the | 13 // An implementation of |ConfigurationPolicyProvider| using the |
26 // mechanism provided by Windows Groups Policy. Policy decisions are | 14 // mechanism provided by Windows Groups Policy. Policy decisions are |
27 // stored as values in a special section of the Windows Registry. | 15 // stored as values in a special section of the Windows Registry. |
28 // On a managed machine in a domain, this portion of the registry is | 16 // On a managed machine in a domain, this portion of the registry is |
29 // periodically updated by the Windows Group Policy machinery to contain | 17 // periodically updated by the Windows Group Policy machinery to contain |
30 // the latest version of the policy set by administrators. | 18 // the latest version of the policy set by administrators. |
31 class ConfigurationPolicyProviderWin | 19 class ConfigurationPolicyProviderWin : public AsynchronousPolicyProvider { |
32 : public ConfigurationPolicyProvider, | |
33 public base::SupportsWeakPtr<ConfigurationPolicyProviderWin> { | |
34 public: | 20 public: |
35 // Keeps watch on Windows Group Policy notification event to trigger a policy | |
36 // reload when Group Policy changes. This class is reference counted to | |
37 // facilitate timer-based reloads through the message loop. It is not safe to | |
38 // access GroupPolicyChangeWatcher concurrently from multiple threads. | |
39 class GroupPolicyChangeWatcher | |
40 : public base::ObjectWatcher::Delegate, | |
41 public MessageLoop::DestructionObserver, | |
42 public base::RefCountedThreadSafe<GroupPolicyChangeWatcher> { | |
43 public: | |
44 GroupPolicyChangeWatcher( | |
45 base::WeakPtr<ConfigurationPolicyProviderWin> provider, | |
46 int reload_interval_minutes); | |
47 virtual ~GroupPolicyChangeWatcher(); | |
48 | |
49 // Start watching. | |
50 void Start(); | |
51 | |
52 // Stop any pending watch activity in order to allow for timely shutdown. | |
53 void Stop(); | |
54 | |
55 private: | |
56 // Updates the watchers and schedules the reload task if appropriate. | |
57 void SetupWatches(); | |
58 | |
59 // Post a reload notification and update the watch machinery. | |
60 void Reload(); | |
61 | |
62 // Called for timer-based refresh from the message loop. | |
63 void ReloadFromTask(); | |
64 | |
65 // ObjectWatcher::Delegate implementation: | |
66 virtual void OnObjectSignaled(HANDLE object); | |
67 | |
68 // MessageLoop::DestructionObserver implementation: | |
69 virtual void WillDestroyCurrentMessageLoop(); | |
70 | |
71 base::WeakPtr<ConfigurationPolicyProviderWin> provider_; | |
72 base::WaitableEvent user_policy_changed_event_; | |
73 base::WaitableEvent machine_policy_changed_event_; | |
74 base::ObjectWatcher user_policy_watcher_; | |
75 base::ObjectWatcher machine_policy_watcher_; | |
76 bool user_policy_watcher_failed_; | |
77 bool machine_policy_watcher_failed_; | |
78 | |
79 // Period to schedule the reload task at. | |
80 int reload_interval_minutes_; | |
81 | |
82 // A reference to a delayed task for timer-based reloading. | |
83 CancelableTask* reload_task_; | |
84 }; | |
85 | |
86 explicit ConfigurationPolicyProviderWin( | 21 explicit ConfigurationPolicyProviderWin( |
87 const PolicyDefinitionList* policy_list); | 22 const PolicyDefinitionList* policy_list); |
88 virtual ~ConfigurationPolicyProviderWin(); | 23 virtual ~ConfigurationPolicyProviderWin() {} |
89 | |
90 // ConfigurationPolicyProvider method overrides: | |
91 virtual bool Provide(ConfigurationPolicyStoreInterface* store); | |
92 | |
93 protected: | |
94 // The sub key path for Chromium's Group Policy information in the | |
95 // Windows registry. | |
96 static const wchar_t kPolicyRegistrySubKey[]; | |
97 | 24 |
98 private: | 25 private: |
99 scoped_refptr<GroupPolicyChangeWatcher> watcher_; | 26 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyProviderWin); |
100 | |
101 // Methods to perform type-specific policy lookups in the registry. | |
102 // HKLM is checked first, then HKCU. | |
103 | |
104 // Reads a string registry value |name| at the specified |key| and puts the | |
105 // resulting string in |result|. | |
106 bool GetRegistryPolicyString(const string16& name, string16* result) const; | |
107 // Gets a list value contained under |key| one level below the policy root. | |
108 bool GetRegistryPolicyStringList(const string16& key, | |
109 ListValue* result) const; | |
110 bool GetRegistryPolicyBoolean(const string16& value_name, | |
111 bool* result) const; | |
112 bool GetRegistryPolicyInteger(const string16& value_name, | |
113 uint32* result) const; | |
114 }; | 27 }; |
115 | 28 |
116 } // namespace policy | 29 } // namespace policy |
117 | 30 |
118 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_WIN_H_ | 31 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_WIN_H_ |
OLD | NEW |