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