| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_POLICY_CORE_COMMON_POLICY_SCHEMA_H_ | |
| 6 #define COMPONENTS_POLICY_CORE_COMMON_POLICY_SCHEMA_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/values.h" | |
| 14 #include "components/policy/policy_export.h" | |
| 15 | |
| 16 namespace policy { | |
| 17 | |
| 18 class PolicySchema; | |
| 19 typedef std::map<std::string, PolicySchema*> PolicySchemaMap; | |
| 20 | |
| 21 // Maps known policy keys to their expected types, and recursively describes | |
| 22 // the known keys within dictionary or list types. | |
| 23 class POLICY_EXPORT PolicySchema { | |
| 24 public: | |
| 25 | |
| 26 // Parses |schema| as a JSON v3 schema, and additionally verifies that: | |
| 27 // - the version is JSON schema v3; | |
| 28 // - the top-level entry is of type "object"; | |
| 29 // - the top-level object doesn't contain "additionalProperties" nor | |
| 30 // "patternProperties"; | |
| 31 // - each "property" maps to a schema with one "type"; | |
| 32 // - the type "any" is not used. | |
| 33 // If all the checks pass then the parsed PolicySchema is returned; otherwise | |
| 34 // returns NULL. | |
| 35 static scoped_ptr<PolicySchema> Parse(const std::string& schema, | |
| 36 std::string* error); | |
| 37 | |
| 38 explicit PolicySchema(base::Value::Type type); | |
| 39 virtual ~PolicySchema(); | |
| 40 | |
| 41 // Returns the expected type for this policy. At the top-level PolicySchema | |
| 42 // this is always TYPE_DICTIONARY. | |
| 43 base::Value::Type type() const { return type_; } | |
| 44 | |
| 45 // It is invalid to call these methods when type() is not TYPE_DICTIONARY. | |
| 46 // | |
| 47 // GetProperties() returns a map of the known property names to their schemas; | |
| 48 // the map is never NULL. | |
| 49 // GetSchemaForAdditionalProperties() returns the schema that should be used | |
| 50 // for keys not found in the map, and may be NULL. | |
| 51 // GetSchemaForProperty() is a utility method that combines both, returning | |
| 52 // the mapped schema if found in GetProperties(), otherwise returning | |
| 53 // GetSchemaForAdditionalProperties(). | |
| 54 virtual const PolicySchemaMap* GetProperties() const; | |
| 55 virtual const PolicySchema* GetSchemaForAdditionalProperties() const; | |
| 56 const PolicySchema* GetSchemaForProperty(const std::string& key) const; | |
| 57 | |
| 58 // It is invalid to call this method when type() is not TYPE_LIST. | |
| 59 // Returns the type of the entries of this "array", which is never NULL. | |
| 60 virtual const PolicySchema* GetSchemaForItems() const; | |
| 61 | |
| 62 private: | |
| 63 const base::Value::Type type_; | |
| 64 | |
| 65 DISALLOW_COPY_AND_ASSIGN(PolicySchema); | |
| 66 }; | |
| 67 | |
| 68 } // namespace policy | |
| 69 | |
| 70 #endif // COMPONENTS_POLICY_CORE_COMMON_POLICY_SCHEMA_H_ | |
| OLD | NEW |