| Index: chrome/browser/policy/policy_loader_win.cc
|
| diff --git a/chrome/browser/policy/policy_loader_win.cc b/chrome/browser/policy/policy_loader_win.cc
|
| index 7916874407225add91252526ffc4d741c1341b30..d0457121b9373c0420ea51a15587fd6ddd29e7c9 100644
|
| --- a/chrome/browser/policy/policy_loader_win.cc
|
| +++ b/chrome/browser/policy/policy_loader_win.cc
|
| @@ -24,8 +24,12 @@
|
| #include "base/win/registry.h"
|
| #include "chrome/browser/policy/policy_bundle.h"
|
| #include "chrome/browser/policy/policy_map.h"
|
| +#include "chrome/common/json_schema_constants.h"
|
| +#include "chrome/common/json_schema_validator.h"
|
| #include "policy/policy_constants.h"
|
|
|
| +namespace schema = json_schema_constants;
|
| +
|
| using base::win::RegKey;
|
| using base::win::RegistryKeyIterator;
|
| using base::win::RegistryValueIterator;
|
| @@ -39,10 +43,6 @@ namespace registry_constants {
|
| const wchar_t kMandatory[] = L"policy";
|
| const wchar_t kRecommended[] = L"recommended";
|
| const wchar_t kSchema[] = L"schema";
|
| - const char kType[] = "type";
|
| - const char kProperties[] = "properties";
|
| - const char kAdditionalProperties[] = "additionalProperties";
|
| - const char kItems[] = "items";
|
| } // namespace registry_constants
|
|
|
| namespace {
|
| @@ -227,30 +227,12 @@ base::Value* ReadChromeDictionaryValue(const string16& name,
|
| // Returns the Value type described in |schema|, or |default_type| if not found.
|
| base::Value::Type GetType(const base::DictionaryValue* 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[] = {
|
| - { "array", base::Value::TYPE_LIST },
|
| - { "boolean", base::Value::TYPE_BOOLEAN },
|
| - { "integer", base::Value::TYPE_INTEGER },
|
| - { "null", base::Value::TYPE_NULL },
|
| - { "number", base::Value::TYPE_DOUBLE },
|
| - { "object", base::Value::TYPE_DICTIONARY },
|
| - { "string", base::Value::TYPE_STRING },
|
| - };
|
| -
|
| - if (!schema)
|
| - return default_type;
|
| - std::string type;
|
| - if (!schema->GetString(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;
|
| + std::string schema_type;
|
| + base::Value::Type value_type;
|
| + if (schema &&
|
| + schema->GetString(schema::kType, &schema_type) &&
|
| + JSONSchemaValidator::GetValueType(schema_type, &value_type)) {
|
| + return value_type;
|
| }
|
| return default_type;
|
| }
|
| @@ -277,12 +259,13 @@ const base::DictionaryValue* GetEntry(const base::DictionaryValue* dictionary,
|
| // |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, kProperties);
|
| + const base::DictionaryValue* properties =
|
| + GetEntry(schema, schema::kProperties);
|
| const base::DictionaryValue* sub_schema = GetEntry(properties, name);
|
| if (sub_schema)
|
| return sub_schema;
|
| // "additionalProperties" can be a boolean, but that case is ignored.
|
| - return GetEntry(schema, kAdditionalProperties);
|
| + return GetEntry(schema, schema::kAdditionalProperties);
|
| }
|
|
|
| // Converts string |value| to another |type|, if possible.
|
| @@ -405,7 +388,7 @@ base::ListValue* ReadComponentListValue(HKEY hive,
|
| return NULL;
|
|
|
| // Get the schema for list items.
|
| - schema = GetEntry(schema, kItems);
|
| + schema = GetEntry(schema, schema::kItems);
|
| base::Value::Type type = GetType(schema, base::Value::TYPE_STRING);
|
| base::ListValue* list = new base::ListValue();
|
| for (int i = 1; ; ++i) {
|
|
|