| 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/policy_loader_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 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 } | 256 } |
| 257 | 257 |
| 258 // Returns the default type for registry entries of |reg_type|, when there is | 258 // Returns the default type for registry entries of |reg_type|, when there is |
| 259 // no schema defined type for a policy. | 259 // no schema defined type for a policy. |
| 260 base::Value::Type GetDefaultFor(DWORD reg_type) { | 260 base::Value::Type GetDefaultFor(DWORD reg_type) { |
| 261 return reg_type == REG_DWORD ? base::Value::TYPE_INTEGER : | 261 return reg_type == REG_DWORD ? base::Value::TYPE_INTEGER : |
| 262 base::Value::TYPE_STRING; | 262 base::Value::TYPE_STRING; |
| 263 } | 263 } |
| 264 | 264 |
| 265 // Returns the entry with key |name| in |dictionary| (can be NULL), or NULL. | 265 // Returns the entry with key |name| in |dictionary| (can be NULL), or NULL. |
| 266 base::DictionaryValue* GetEntry(const base::DictionaryValue* dictionary, | 266 const base::DictionaryValue* GetEntry(const base::DictionaryValue* dictionary, |
| 267 const std::string& name) { | 267 const std::string& name) { |
| 268 if (!dictionary) | 268 if (!dictionary) |
| 269 return NULL; | 269 return NULL; |
| 270 base::DictionaryValue* entry = NULL; | 270 const base::DictionaryValue* entry = NULL; |
| 271 dictionary->GetDictionary(name, &entry); | 271 dictionary->GetDictionary(name, &entry); |
| 272 return entry; | 272 return entry; |
| 273 } | 273 } |
| 274 | 274 |
| 275 // Returns the schema for property |name| given the |schema| of an object. | 275 // Returns the schema for property |name| given the |schema| of an object. |
| 276 // Returns the "additionalProperties" schema if no specific schema for | 276 // Returns the "additionalProperties" schema if no specific schema for |
| 277 // |name| is present. Returns NULL if no schema is found. | 277 // |name| is present. Returns NULL if no schema is found. |
| 278 base::DictionaryValue* GetSchemaFor(const base::DictionaryValue* schema, | 278 const base::DictionaryValue* GetSchemaFor(const base::DictionaryValue* schema, |
| 279 const std::string& name) { | 279 const std::string& name) { |
| 280 base::DictionaryValue* properties = GetEntry(schema, kProperties); | 280 const base::DictionaryValue* properties = GetEntry(schema, kProperties); |
| 281 base::DictionaryValue* sub_schema = GetEntry(properties, name); | 281 const base::DictionaryValue* sub_schema = GetEntry(properties, name); |
| 282 if (sub_schema) | 282 if (sub_schema) |
| 283 return sub_schema; | 283 return sub_schema; |
| 284 // "additionalProperties" can be a boolean, but that case is ignored. | 284 // "additionalProperties" can be a boolean, but that case is ignored. |
| 285 return GetEntry(schema, kAdditionalProperties); | 285 return GetEntry(schema, kAdditionalProperties); |
| 286 } | 286 } |
| 287 | 287 |
| 288 // Converts string |value| to another |type|, if possible. | 288 // Converts string |value| to another |type|, if possible. |
| 289 base::Value* ConvertComponentStringValue(const string16& value, | 289 base::Value* ConvertComponentStringValue(const string16& value, |
| 290 base::Value::Type type) { | 290 base::Value::Type type) { |
| 291 switch (type) { | 291 switch (type) { |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 | 463 |
| 464 for (RegistryKeyIterator it(hive, path.c_str()); it.Valid(); ++it) { | 464 for (RegistryKeyIterator it(hive, path.c_str()); it.Valid(); ++it) { |
| 465 string16 name16(it.Name()); | 465 string16 name16(it.Name()); |
| 466 std::string name(UTF16ToUTF8(name16)); | 466 std::string name(UTF16ToUTF8(name16)); |
| 467 if (dict->HasKey(name)) { | 467 if (dict->HasKey(name)) { |
| 468 DLOG(WARNING) << "Ignoring registry key because a value exists with the " | 468 DLOG(WARNING) << "Ignoring registry key because a value exists with the " |
| 469 "same name: " << path << kPathSep << name; | 469 "same name: " << path << kPathSep << name; |
| 470 continue; | 470 continue; |
| 471 } | 471 } |
| 472 | 472 |
| 473 base::DictionaryValue* sub_schema = GetSchemaFor(schema, name); | 473 const base::DictionaryValue* sub_schema = GetSchemaFor(schema, name); |
| 474 base::Value::Type type = GetType(sub_schema, base::Value::TYPE_DICTIONARY); | 474 base::Value::Type type = GetType(sub_schema, base::Value::TYPE_DICTIONARY); |
| 475 base::Value* value = NULL; | 475 base::Value* value = NULL; |
| 476 const string16 sub_path = path + kPathSep + name16; | 476 const string16 sub_path = path + kPathSep + name16; |
| 477 if (type == base::Value::TYPE_DICTIONARY) { | 477 if (type == base::Value::TYPE_DICTIONARY) { |
| 478 value = ReadComponentDictionaryValue(hive, sub_path, sub_schema); | 478 value = ReadComponentDictionaryValue(hive, sub_path, sub_schema); |
| 479 } else if (type == base::Value::TYPE_LIST) { | 479 } else if (type == base::Value::TYPE_LIST) { |
| 480 value = ReadComponentListValue(hive, sub_path, sub_schema); | 480 value = ReadComponentListValue(hive, sub_path, sub_schema); |
| 481 } else { | 481 } else { |
| 482 DLOG(WARNING) << "Can't read a simple type in registry key at " << path; | 482 DLOG(WARNING) << "Can't read a simple type in registry key at " << path; |
| 483 } | 483 } |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 | 681 |
| 682 void PolicyLoaderWin::OnObjectSignaled(HANDLE object) { | 682 void PolicyLoaderWin::OnObjectSignaled(HANDLE object) { |
| 683 DCHECK(object == user_policy_changed_event_.handle() || | 683 DCHECK(object == user_policy_changed_event_.handle() || |
| 684 object == machine_policy_changed_event_.handle()) | 684 object == machine_policy_changed_event_.handle()) |
| 685 << "unexpected object signaled policy reload, obj = " | 685 << "unexpected object signaled policy reload, obj = " |
| 686 << std::showbase << std::hex << object; | 686 << std::showbase << std::hex << object; |
| 687 Reload(false); | 687 Reload(false); |
| 688 } | 688 } |
| 689 | 689 |
| 690 } // namespace policy | 690 } // namespace policy |
| OLD | NEW |