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 #include "chrome/browser/configuration_policy_provider_win.h" | 5 #include "chrome/browser/configuration_policy_provider_win.h" |
6 | 6 |
| 7 #include <userenv.h> |
| 8 |
7 #include <algorithm> | 9 #include <algorithm> |
8 | 10 |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/object_watcher.h" |
10 #include "base/registry.h" | 13 #include "base/registry.h" |
11 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
12 #include "base/string_piece.h" | 15 #include "base/string_piece.h" |
13 #include "base/sys_string_conversions.h" | 16 #include "base/sys_string_conversions.h" |
14 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
15 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "base/waitable_event.h" |
16 #include "chrome/common/policy_constants.h" | 20 #include "chrome/common/policy_constants.h" |
17 | 21 |
| 22 ConfigurationPolicyProviderWin::GroupPolicyChangeWatcher:: |
| 23 GroupPolicyChangeWatcher(ConfigurationPolicyProvider* provider) |
| 24 : provider_(provider), |
| 25 user_policy_changed_event_(false, false), |
| 26 machine_policy_changed_event_(false, false) { |
| 27 CHECK(RegisterGPNotification(user_policy_changed_event_.handle(), false)); |
| 28 CHECK(RegisterGPNotification(machine_policy_changed_event_.handle(), true)); |
| 29 user_policy_watcher_.StartWatching( |
| 30 user_policy_changed_event_.handle(), |
| 31 this); |
| 32 machine_policy_watcher_.StartWatching( |
| 33 machine_policy_changed_event_.handle(), |
| 34 this); |
| 35 } |
| 36 |
| 37 void ConfigurationPolicyProviderWin::GroupPolicyChangeWatcher:: |
| 38 OnObjectSignaled(HANDLE object) { |
| 39 provider_->NotifyStoreOfPolicyChange(); |
| 40 if (object == user_policy_changed_event_.handle()) { |
| 41 user_policy_watcher_.StartWatching( |
| 42 user_policy_changed_event_.handle(), |
| 43 this); |
| 44 } else if (object == machine_policy_changed_event_.handle()) { |
| 45 machine_policy_watcher_.StartWatching( |
| 46 machine_policy_changed_event_.handle(), |
| 47 this); |
| 48 } else { |
| 49 // This method should only be called as a result of signals |
| 50 // to the user- and machine-policy handle watchers. |
| 51 NOTREACHED(); |
| 52 } |
| 53 } |
| 54 |
18 ConfigurationPolicyProviderWin::ConfigurationPolicyProviderWin() { | 55 ConfigurationPolicyProviderWin::ConfigurationPolicyProviderWin() { |
| 56 watcher_.reset(new GroupPolicyChangeWatcher(this)); |
19 } | 57 } |
20 | 58 |
21 bool ConfigurationPolicyProviderWin::GetRegistryPolicyString( | 59 bool ConfigurationPolicyProviderWin::GetRegistryPolicyString( |
22 const wchar_t* value_name, string16* result) { | 60 const wchar_t* value_name, string16* result) { |
23 DWORD value_size = 0; | 61 DWORD value_size = 0; |
24 DWORD key_type = 0; | 62 DWORD key_type = 0; |
25 scoped_array<uint8> buffer; | 63 scoped_array<uint8> buffer; |
26 RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, policy::kRegistrySubKey); | 64 RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, policy::kRegistrySubKey); |
27 if (hkcu_policy_key.ReadValue(value_name, 0, &value_size, &key_type)) { | 65 if (hkcu_policy_key.ReadValue(value_name, 0, &value_size, &key_type)) { |
28 if (key_type != REG_SZ) | 66 if (key_type != REG_SZ) |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 } | 158 } |
121 break; | 159 break; |
122 default: | 160 default: |
123 NOTREACHED(); | 161 NOTREACHED(); |
124 return false; | 162 return false; |
125 } | 163 } |
126 } | 164 } |
127 | 165 |
128 return true; | 166 return true; |
129 } | 167 } |
OLD | NEW |