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