| 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/policy/configuration_policy_provider_win.h" | 5 #include "chrome/browser/policy/configuration_policy_provider_win.h" |
| 6 | 6 |
| 7 #include <userenv.h> | 7 #include <userenv.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 ReloadFromTask() { | 138 ReloadFromTask() { |
| 139 // Make sure to not call Cancel() on the task, since it might hold the last | 139 // Make sure to not call Cancel() on the task, since it might hold the last |
| 140 // reference that keeps this object alive. | 140 // reference that keeps this object alive. |
| 141 reload_task_ = NULL; | 141 reload_task_ = NULL; |
| 142 Reload(); | 142 Reload(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void ConfigurationPolicyProviderWin::GroupPolicyChangeWatcher:: | 145 void ConfigurationPolicyProviderWin::GroupPolicyChangeWatcher:: |
| 146 OnObjectSignaled(HANDLE object) { | 146 OnObjectSignaled(HANDLE object) { |
| 147 DCHECK(object == user_policy_changed_event_.handle() || | 147 DCHECK(object == user_policy_changed_event_.handle() || |
| 148 object == machine_policy_changed_event_.handle()); | 148 object == machine_policy_changed_event_.handle()) |
| 149 << "unexpected object signaled policy reload, obj = " |
| 150 << std::showbase << std::hex << object; |
| 149 Reload(); | 151 Reload(); |
| 150 } | 152 } |
| 151 | 153 |
| 152 void ConfigurationPolicyProviderWin::GroupPolicyChangeWatcher:: | 154 void ConfigurationPolicyProviderWin::GroupPolicyChangeWatcher:: |
| 153 WillDestroyCurrentMessageLoop() { | 155 WillDestroyCurrentMessageLoop() { |
| 154 reload_task_ = NULL; | 156 reload_task_ = NULL; |
| 155 MessageLoop::current()->RemoveDestructionObserver(this); | 157 MessageLoop::current()->RemoveDestructionObserver(this); |
| 156 } | 158 } |
| 157 | 159 |
| 158 ConfigurationPolicyProviderWin::ConfigurationPolicyProviderWin( | 160 ConfigurationPolicyProviderWin::ConfigurationPolicyProviderWin( |
| 159 const PolicyDefinitionList* policy_list) | 161 const PolicyDefinitionList* policy_list) |
| 160 : ConfigurationPolicyProvider(policy_list) { | 162 : ConfigurationPolicyProvider(policy_list) { |
| 161 watcher_ = new GroupPolicyChangeWatcher(this->AsWeakPtr(), | 163 watcher_ = new GroupPolicyChangeWatcher(this->AsWeakPtr(), |
| 162 kReloadIntervalMinutes); | 164 kReloadIntervalMinutes); |
| 163 watcher_->Start(); | 165 watcher_->Start(); |
| 164 } | 166 } |
| 165 | 167 |
| 166 ConfigurationPolicyProviderWin::~ConfigurationPolicyProviderWin() { | 168 ConfigurationPolicyProviderWin::~ConfigurationPolicyProviderWin() { |
| 167 watcher_->Stop(); | 169 watcher_->Stop(); |
| 168 } | 170 } |
| 169 | 171 |
| 170 bool ConfigurationPolicyProviderWin::GetRegistryPolicyString( | 172 bool ConfigurationPolicyProviderWin::GetRegistryPolicyString( |
| 171 const string16& name, string16* result) { | 173 const string16& name, string16* result) const { |
| 172 string16 path = string16(kRegistrySubKey); | 174 string16 path = string16(kRegistrySubKey); |
| 173 RegKey policy_key; | 175 RegKey policy_key; |
| 174 // First try the global policy. | 176 // First try the global policy. |
| 175 if (policy_key.Open(HKEY_LOCAL_MACHINE, path.c_str(), KEY_READ)) { | 177 if (policy_key.Open(HKEY_LOCAL_MACHINE, path.c_str(), KEY_READ)) { |
| 176 if (ReadRegistryStringValue(&policy_key, name, result)) | 178 if (ReadRegistryStringValue(&policy_key, name, result)) |
| 177 return true; | 179 return true; |
| 178 policy_key.Close(); | 180 policy_key.Close(); |
| 179 } | 181 } |
| 180 // Fall back on user-specific policy. | 182 // Fall back on user-specific policy. |
| 181 if (!policy_key.Open(HKEY_CURRENT_USER, path.c_str(), KEY_READ)) | 183 if (!policy_key.Open(HKEY_CURRENT_USER, path.c_str(), KEY_READ)) |
| 182 return false; | 184 return false; |
| 183 return ReadRegistryStringValue(&policy_key, name, result); | 185 return ReadRegistryStringValue(&policy_key, name, result); |
| 184 } | 186 } |
| 185 | 187 |
| 186 bool ConfigurationPolicyProviderWin::GetRegistryPolicyStringList( | 188 bool ConfigurationPolicyProviderWin::GetRegistryPolicyStringList( |
| 187 const string16& key, ListValue* result) { | 189 const string16& key, ListValue* result) const { |
| 188 string16 path = string16(kRegistrySubKey); | 190 string16 path = string16(kRegistrySubKey); |
| 189 path += ASCIIToUTF16("\\") + key; | 191 path += ASCIIToUTF16("\\") + key; |
| 190 RegKey policy_key; | 192 RegKey policy_key; |
| 191 if (!policy_key.Open(HKEY_LOCAL_MACHINE, path.c_str(), KEY_READ)) { | 193 if (!policy_key.Open(HKEY_LOCAL_MACHINE, path.c_str(), KEY_READ)) { |
| 192 policy_key.Close(); | 194 policy_key.Close(); |
| 193 // Fall back on user-specific policy. | 195 // Fall back on user-specific policy. |
| 194 if (!policy_key.Open(HKEY_CURRENT_USER, path.c_str(), KEY_READ)) | 196 if (!policy_key.Open(HKEY_CURRENT_USER, path.c_str(), KEY_READ)) |
| 195 return false; | 197 return false; |
| 196 } | 198 } |
| 197 string16 policy_string; | 199 string16 policy_string; |
| 198 int index = 0; | 200 int index = 0; |
| 199 while (ReadRegistryStringValue(&policy_key, base::IntToString16(++index), | 201 while (ReadRegistryStringValue(&policy_key, base::IntToString16(++index), |
| 200 &policy_string)) { | 202 &policy_string)) { |
| 201 result->Append(Value::CreateStringValue(policy_string)); | 203 result->Append(Value::CreateStringValue(policy_string)); |
| 202 } | 204 } |
| 203 return true; | 205 return true; |
| 204 } | 206 } |
| 205 | 207 |
| 206 bool ConfigurationPolicyProviderWin::GetRegistryPolicyBoolean( | 208 bool ConfigurationPolicyProviderWin::GetRegistryPolicyBoolean( |
| 207 const string16& value_name, bool* result) { | 209 const string16& value_name, bool* result) const { |
| 208 DWORD value; | 210 DWORD value; |
| 209 RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, kRegistrySubKey, KEY_READ); | 211 RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, kRegistrySubKey, KEY_READ); |
| 210 if (hkcu_policy_key.ReadValueDW(value_name.c_str(), &value)) { | 212 if (hkcu_policy_key.ReadValueDW(value_name.c_str(), &value)) { |
| 211 *result = value != 0; | 213 *result = value != 0; |
| 212 return true; | 214 return true; |
| 213 } | 215 } |
| 214 | 216 |
| 215 RegKey hklm_policy_key(HKEY_CURRENT_USER, kRegistrySubKey, KEY_READ); | 217 RegKey hklm_policy_key(HKEY_CURRENT_USER, kRegistrySubKey, KEY_READ); |
| 216 if (hklm_policy_key.ReadValueDW(value_name.c_str(), &value)) { | 218 if (hklm_policy_key.ReadValueDW(value_name.c_str(), &value)) { |
| 217 *result = value != 0; | 219 *result = value != 0; |
| 218 return true; | 220 return true; |
| 219 } | 221 } |
| 220 return false; | 222 return false; |
| 221 } | 223 } |
| 222 | 224 |
| 223 bool ConfigurationPolicyProviderWin::GetRegistryPolicyInteger( | 225 bool ConfigurationPolicyProviderWin::GetRegistryPolicyInteger( |
| 224 const string16& value_name, uint32* result) { | 226 const string16& value_name, uint32* result) const { |
| 225 DWORD value; | 227 DWORD value; |
| 226 RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, kRegistrySubKey, KEY_READ); | 228 RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, kRegistrySubKey, KEY_READ); |
| 227 if (hkcu_policy_key.ReadValueDW(value_name.c_str(), &value)) { | 229 if (hkcu_policy_key.ReadValueDW(value_name.c_str(), &value)) { |
| 228 *result = value; | 230 *result = value; |
| 229 return true; | 231 return true; |
| 230 } | 232 } |
| 231 | 233 |
| 232 RegKey hklm_policy_key(HKEY_CURRENT_USER, kRegistrySubKey, KEY_READ); | 234 RegKey hklm_policy_key(HKEY_CURRENT_USER, kRegistrySubKey, KEY_READ); |
| 233 if (hklm_policy_key.ReadValueDW(value_name.c_str(), &value)) { | 235 if (hklm_policy_key.ReadValueDW(value_name.c_str(), &value)) { |
| 234 *result = value; | 236 *result = value; |
| 235 return true; | 237 return true; |
| 236 } | 238 } |
| 237 return false; | 239 return false; |
| 238 } | 240 } |
| 239 | 241 |
| 240 bool ConfigurationPolicyProviderWin::Provide( | 242 bool ConfigurationPolicyProviderWin::Provide( |
| 241 ConfigurationPolicyStore* store) { | 243 ConfigurationPolicyStoreInterface* store) { |
| 242 const PolicyDefinitionList* policy_list(policy_definition_list()); | 244 const PolicyDefinitionList* policy_list(policy_definition_list()); |
| 243 for (const PolicyDefinitionList::Entry* current = policy_list->begin; | 245 for (const PolicyDefinitionList::Entry* current = policy_list->begin; |
| 244 current != policy_list->end; ++current) { | 246 current != policy_list->end; ++current) { |
| 245 std::wstring name = UTF8ToWide(current->name); | 247 std::wstring name = UTF8ToWide(current->name); |
| 246 switch (current->value_type) { | 248 switch (current->value_type) { |
| 247 case Value::TYPE_STRING: { | 249 case Value::TYPE_STRING: { |
| 248 std::wstring string_value; | 250 std::wstring string_value; |
| 249 if (GetRegistryPolicyString(name.c_str(), &string_value)) { | 251 if (GetRegistryPolicyString(name.c_str(), &string_value)) { |
| 250 store->Apply(current->policy_type, | 252 store->Apply(current->policy_type, |
| 251 Value::CreateStringValue(string_value)); | 253 Value::CreateStringValue(string_value)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 277 default: | 279 default: |
| 278 NOTREACHED(); | 280 NOTREACHED(); |
| 279 return false; | 281 return false; |
| 280 } | 282 } |
| 281 } | 283 } |
| 282 | 284 |
| 283 return true; | 285 return true; |
| 284 } | 286 } |
| 285 | 287 |
| 286 } // namespace policy | 288 } // namespace policy |
| OLD | NEW |