Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3111)

Unified Diff: chrome/browser/policy/registry_dict_win.cc

Issue 22645011: policy: use JSON schema to deserialize entries from Windows registry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix 3rd party policy unit tests Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/policy/registry_dict_win.h ('k') | chrome/browser/policy/registry_dict_win_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/policy/registry_dict_win.cc
diff --git a/chrome/browser/policy/registry_dict_win.cc b/chrome/browser/policy/registry_dict_win.cc
index 00a519379f2fa8ee318228ef4b46438ed3ead885..732c6ddaecb88b52d730708c2f1f87127c4137f0 100644
--- a/chrome/browser/policy/registry_dict_win.cc
+++ b/chrome/browser/policy/registry_dict_win.cc
@@ -23,66 +23,33 @@ namespace policy {
namespace {
-// Returns the entry with key |name| in |dictionary| (can be NULL), or NULL.
-const base::DictionaryValue* GetEntry(const base::DictionaryValue* dictionary,
- const std::string& name) {
- if (!dictionary)
- return NULL;
- const base::DictionaryValue* entry = NULL;
- dictionary->GetDictionaryWithoutPathExpansion(name, &entry);
- return entry;
-}
-
// Returns the Value type described in |schema|, or |default_type| if not found.
-base::Value::Type GetValueTypeForSchema(const base::DictionaryValue* schema,
+base::Value::Type GetValueTypeForSchema(const PolicySchema* schema,
base::Value::Type default_type) {
- // JSON-schema types to base::Value::Type mapping.
- static const struct {
- // JSON schema type.
- const char* schema_type;
- // Correspondent value type.
- base::Value::Type value_type;
- } kSchemaToValueTypeMap[] = {
- { schema::kArray, base::Value::TYPE_LIST },
- { schema::kBoolean, base::Value::TYPE_BOOLEAN },
- { schema::kInteger, base::Value::TYPE_INTEGER },
- { schema::kNull, base::Value::TYPE_NULL },
- { schema::kNumber, base::Value::TYPE_DOUBLE },
- { schema::kObject, base::Value::TYPE_DICTIONARY },
- { schema::kString, base::Value::TYPE_STRING },
- };
-
if (!schema)
return default_type;
- std::string type;
- if (!schema->GetStringWithoutPathExpansion(schema::kType, &type))
- return default_type;
- for (size_t i = 0; i < arraysize(kSchemaToValueTypeMap); ++i) {
- if (type == kSchemaToValueTypeMap[i].schema_type)
- return kSchemaToValueTypeMap[i].value_type;
- }
- return default_type;
+ return schema->type();
}
// Returns the schema for property |name| given the |schema| of an object.
// Returns the "additionalProperties" schema if no specific schema for
// |name| is present. Returns NULL if no schema is found.
-const base::DictionaryValue* GetSchemaFor(const base::DictionaryValue* schema,
- const std::string& name) {
- const base::DictionaryValue* properties =
- GetEntry(schema, schema::kProperties);
- const base::DictionaryValue* sub_schema = GetEntry(properties, name);
+const PolicySchema* GetSchemaFor(const PolicySchema* schema,
+ const std::string& name) {
+ if (!schema)
+ return NULL;
+ const PolicySchema* sub_schema = schema->GetSchemaForProperty(name);
if (sub_schema)
return sub_schema;
// "additionalProperties" can be a boolean, but that case is ignored.
- return GetEntry(schema, schema::kAdditionalProperties);
+ return schema->GetSchemaForAdditionalProperties();
}
// Converts a value (as read from the registry) to meet |schema|, converting
// types as necessary. Unconvertible types will show up as NULL values in the
// result.
scoped_ptr<base::Value> ConvertValue(const base::Value& value,
- const base::DictionaryValue* schema) {
+ const PolicySchema* schema) {
// Figure out the type to convert to from the schema.
const base::Value::Type result_type(
GetValueTypeForSchema(schema, value.GetType()));
@@ -105,8 +72,7 @@ scoped_ptr<base::Value> ConvertValue(const base::Value& value,
return result.Pass();
} else if (value.GetAsList(&list)) {
scoped_ptr<base::ListValue> result(new base::ListValue());
- const base::DictionaryValue* item_schema =
- GetEntry(schema, schema::kItems);
+ const PolicySchema* item_schema = schema->GetSchemaForItems();
for (base::ListValue::const_iterator entry(list->begin());
entry != list->end(); ++entry) {
result->Append(ConvertValue(**entry, item_schema).release());
@@ -157,8 +123,7 @@ scoped_ptr<base::Value> ConvertValue(const base::Value& value,
const base::DictionaryValue* dict = NULL;
if (value.GetAsDictionary(&dict)) {
scoped_ptr<base::ListValue> result(new base::ListValue());
- const base::DictionaryValue* item_schema =
- GetEntry(schema, schema::kItems);
+ const PolicySchema* item_schema = schema->GetSchemaForItems();
for (int i = 1; ; ++i) {
const base::Value* entry = NULL;
if (!dict->Get(base::IntToString(i), &entry))
@@ -348,7 +313,7 @@ void RegistryDict::ReadRegistry(HKEY hive, const string16& root) {
}
scoped_ptr<base::Value> RegistryDict::ConvertToJSON(
- const base::DictionaryValue* schema) const {
+ const PolicySchema* schema) const {
base::Value::Type type =
GetValueTypeForSchema(schema, base::Value::TYPE_DICTIONARY);
switch (type) {
@@ -372,8 +337,7 @@ scoped_ptr<base::Value> RegistryDict::ConvertToJSON(
}
case base::Value::TYPE_LIST: {
scoped_ptr<base::ListValue> result(new base::ListValue());
- const base::DictionaryValue* item_schema =
- GetEntry(schema, schema::kItems);
+ const PolicySchema* item_schema = schema->GetSchemaForItems();
for (int i = 1; ; ++i) {
const std::string name(base::IntToString(i));
const RegistryDict* key = GetKey(name);
« no previous file with comments | « chrome/browser/policy/registry_dict_win.h ('k') | chrome/browser/policy/registry_dict_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698