configuration_policy_provider_win.h revision 513209b27ff55e2841eac0e4120199c23acce758
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 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_WIN_H_ 6#define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_WIN_H_ 7#pragma once 8 9#include "base/object_watcher.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 17namespace base { 18namespace win { 19class RegKey; 20} // namespace win 21} // namespace base 22 23namespace policy { 24 25// An implementation of |ConfigurationPolicyProvider| using the 26// mechanism provided by Windows Groups Policy. Policy decisions are 27// 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 29// periodically updated by the Windows Group Policy machinery to contain 30// the latest version of the policy set by administrators. 31class ConfigurationPolicyProviderWin 32 : public ConfigurationPolicyProvider, 33 public base::SupportsWeakPtr<ConfigurationPolicyProviderWin> { 34 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( 87 const PolicyDefinitionList* policy_list); 88 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 98 private: 99 scoped_refptr<GroupPolicyChangeWatcher> watcher_; 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}; 115 116} // namespace policy 117 118#endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_WIN_H_ 119