Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_delegate_win.h" | 5 #include "chrome/browser/policy/policy_loader_win.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 | 10 |
| 11 #include <userenv.h> | |
| 12 | |
| 13 // userenv.dll is required for RegisterGPNotification(). | |
| 14 #pragma comment(lib, "userenv.lib") | |
| 15 | |
| 11 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
| 12 #include "base/json/json_reader.h" | 17 #include "base/json/json_reader.h" |
| 13 #include "base/logging.h" | 18 #include "base/logging.h" |
| 14 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
| 20 #include "base/string16.h" | |
| 15 #include "base/string_number_conversions.h" | 21 #include "base/string_number_conversions.h" |
| 16 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
| 17 #include "base/values.h" | 23 #include "base/values.h" |
| 18 #include "base/win/registry.h" | 24 #include "base/win/registry.h" |
| 19 #include "chrome/browser/policy/policy_bundle.h" | 25 #include "chrome/browser/policy/policy_bundle.h" |
| 20 #include "chrome/browser/policy/policy_map.h" | 26 #include "chrome/browser/policy/policy_map.h" |
| 21 #include "policy/policy_constants.h" | 27 #include "policy/policy_constants.h" |
| 22 | 28 |
| 23 using base::win::RegKey; | 29 using base::win::RegKey; |
| 24 | 30 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 if (!LoadHighestPriorityKey(string16(), name, &key, level, scope)) | 202 if (!LoadHighestPriorityKey(string16(), name, &key, level, scope)) |
| 197 return NULL; | 203 return NULL; |
| 198 string16 value; | 204 string16 value; |
| 199 if (!ReadRegistryString(&key, name, &value)) | 205 if (!ReadRegistryString(&key, name, &value)) |
| 200 return NULL; | 206 return NULL; |
| 201 return base::JSONReader::Read(UTF16ToUTF8(value)); | 207 return base::JSONReader::Read(UTF16ToUTF8(value)); |
| 202 } | 208 } |
| 203 | 209 |
| 204 } // namespace | 210 } // namespace |
| 205 | 211 |
| 206 ConfigurationPolicyProviderDelegateWin::ConfigurationPolicyProviderDelegateWin( | 212 WinPolicyLoader::WinPolicyLoader(const PolicyDefinitionList* policy_list) |
| 207 const PolicyDefinitionList* policy_definition_list) | 213 : is_initialized_(false), |
| 208 : policy_definition_list_(policy_definition_list) {} | 214 policy_list_(policy_list), |
| 215 user_policy_changed_event_(false, false), | |
| 216 machine_policy_changed_event_(false, false), | |
| 217 user_policy_watcher_failed_(false), | |
|
Mattias Nissler (ping if slow)
2012/06/04 09:29:41
the failed_ fields are no longer used AFAICS
Joao da Silva
2012/06/06 13:05:24
They're used in SetupWatches() to stop trying to i
| |
| 218 machine_policy_watcher_failed_(false) { | |
| 219 if (!RegisterGPNotification(user_policy_changed_event_.handle(), false)) { | |
| 220 DPLOG(WARNING) << "Failed to register user group policy notification"; | |
| 221 user_policy_watcher_failed_ = true; | |
| 222 } | |
| 223 if (!RegisterGPNotification(machine_policy_changed_event_.handle(), true)) { | |
| 224 DPLOG(WARNING) << "Failed to register machine group policy notification."; | |
| 225 machine_policy_watcher_failed_ = true; | |
| 226 } | |
| 227 } | |
| 209 | 228 |
| 210 scoped_ptr<PolicyBundle> ConfigurationPolicyProviderDelegateWin::Load() { | 229 WinPolicyLoader::~WinPolicyLoader() { |
| 230 user_policy_watcher_.StopWatching(); | |
| 231 machine_policy_watcher_.StopWatching(); | |
| 232 } | |
| 233 | |
| 234 // static | |
| 235 AsyncPolicyProvider* WinPolicyLoader::CreateProvider( | |
| 236 const PolicyDefinitionList* policy_list) { | |
| 237 WinPolicyLoader* loader = new WinPolicyLoader(policy_list); | |
| 238 return new AsyncPolicyProvider(policy_list, loader); | |
| 239 } | |
| 240 | |
| 241 void WinPolicyLoader::InitOnFile() { | |
| 242 is_initialized_ = true; | |
| 243 SetupWatches(); | |
| 244 } | |
| 245 | |
| 246 scoped_ptr<PolicyBundle> WinPolicyLoader::Load() { | |
| 247 // Reset the watches BEFORE reading the individual policies to avoid | |
| 248 // missing a change notification. | |
| 249 if (is_initialized_) | |
| 250 SetupWatches(); | |
| 251 | |
| 211 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); | 252 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); |
| 212 PolicyMap& chrome_policy = bundle->Get(POLICY_DOMAIN_CHROME, std::string()); | 253 PolicyMap& chrome_policy = bundle->Get(POLICY_DOMAIN_CHROME, std::string()); |
| 213 | 254 |
| 214 const PolicyDefinitionList::Entry* current; | 255 const PolicyDefinitionList::Entry* current; |
| 215 for (current = policy_definition_list_->begin; | 256 for (current = policy_list_->begin; current != policy_list_->end; ++current) { |
| 216 current != policy_definition_list_->end; | |
| 217 ++current) { | |
| 218 const string16 name(ASCIIToUTF16(current->name)); | 257 const string16 name(ASCIIToUTF16(current->name)); |
| 219 PolicyLevel level = POLICY_LEVEL_MANDATORY; | 258 PolicyLevel level = POLICY_LEVEL_MANDATORY; |
| 220 PolicyScope scope = POLICY_SCOPE_MACHINE; | 259 PolicyScope scope = POLICY_SCOPE_MACHINE; |
| 221 Value* value = NULL; | 260 Value* value = NULL; |
| 222 | 261 |
| 223 switch (current->value_type) { | 262 switch (current->value_type) { |
| 224 case Value::TYPE_STRING: | 263 case Value::TYPE_STRING: |
| 225 value = ReadStringValue(name, &level, &scope); | 264 value = ReadStringValue(name, &level, &scope); |
| 226 break; | 265 break; |
| 227 | 266 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 245 NOTREACHED(); | 284 NOTREACHED(); |
| 246 } | 285 } |
| 247 | 286 |
| 248 if (value) | 287 if (value) |
| 249 chrome_policy.Set(current->name, level, scope, value); | 288 chrome_policy.Set(current->name, level, scope, value); |
| 250 } | 289 } |
| 251 | 290 |
| 252 return bundle.Pass(); | 291 return bundle.Pass(); |
| 253 } | 292 } |
| 254 | 293 |
| 294 void WinPolicyLoader::SetupWatches() { | |
| 295 DCHECK(is_initialized_); | |
| 296 if (!user_policy_watcher_failed_ && | |
| 297 !user_policy_watcher_.GetWatchedObject() && | |
| 298 !user_policy_watcher_.StartWatching( | |
| 299 user_policy_changed_event_.handle(), this)) { | |
| 300 DLOG(WARNING) << "Failed to start watch for user policy change event"; | |
| 301 user_policy_watcher_failed_ = true; | |
| 302 } | |
| 303 if (!machine_policy_watcher_failed_ && | |
| 304 !machine_policy_watcher_.GetWatchedObject() && | |
| 305 !machine_policy_watcher_.StartWatching( | |
| 306 machine_policy_changed_event_.handle(), this)) { | |
| 307 DLOG(WARNING) << "Failed to start watch for machine policy change event"; | |
| 308 machine_policy_watcher_failed_ = true; | |
| 309 } | |
| 310 } | |
| 311 | |
| 312 void WinPolicyLoader::OnObjectSignaled(HANDLE object) { | |
| 313 DCHECK(object == user_policy_changed_event_.handle() || | |
| 314 object == machine_policy_changed_event_.handle()) | |
| 315 << "unexpected object signaled policy reload, obj = " | |
| 316 << std::showbase << std::hex << object; | |
| 317 Reload(false); | |
| 318 } | |
| 319 | |
| 255 } // namespace policy | 320 } // namespace policy |
| OLD | NEW |