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

Side by Side Diff: components/policy/core/common/schema.h

Issue 23851022: Added new policy Schema classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: POLICY_EXPORT for Schema::Iterator 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_SCHEMA_H_
6 #define COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/values.h"
13 #include "components/policy/policy_export.h"
14
15 namespace policy {
16
Mattias Nissler (ping if slow) 2013/09/13 12:56:48 I think we usually don't put blank lines between n
Joao da Silva 2013/09/13 14:02:54 The style guide has an example with nested namespa
17 namespace schema {
Mattias Nissler (ping if slow) 2013/09/13 12:56:48 This namespace is not really useful (cf. current d
Joao da Silva 2013/09/13 14:02:54 Alright, removed. Renamed PolicySchema to SchemaOw
18
19 namespace internal {
20
21 struct POLICY_EXPORT SchemaNode;
22 struct POLICY_EXPORT PropertyNode;
23 struct POLICY_EXPORT PropertiesNode;
24
25 } // namespace internal
26
27 // Describes the expected type of one policy. Also recursively describes the
28 // types of inner elements, for structured types.
29 // Objects of this class refer to external, immutable data and are cheap to
30 // copy.
31 // Use the PolicySchema class to parse a schema and get Schema objects.
32 class POLICY_EXPORT Schema {
33 public:
34 explicit Schema(const internal::SchemaNode* schema);
35 Schema(const Schema& schema);
36
37 Schema& operator=(const Schema& schema);
38
39 // Returns true if this Schema is valid. Schemas returned by the methods below
40 // may be invalid, and in those cases the other methods must not be used.
41 bool valid() const { return schema_ != NULL; }
42
43 base::Value::Type type() const;
44
45 // Used to iterate over the known properties of TYPE_DICTIONARY schemas.
46 class POLICY_EXPORT Iterator {
47 public:
48 explicit Iterator(const internal::PropertiesNode* properties);
49 Iterator(const Iterator& iterator);
50 ~Iterator();
51
52 Iterator& operator=(const Iterator& iterator);
53
54 // The other methods must not be called if the iterator is at the end.
55 bool IsAtEnd() const;
56
57 // Advances the iterator to the next property.
58 void Advance();
59
60 // Returns the name of the current property.
61 const char* key() const;
62
63 // Returns the Schema for the current property. This Schema is always valid.
64 Schema schema() const;
65
66 private:
67 const internal::PropertyNode* it_;
68 const internal::PropertyNode* end_;
69 };
70
Mattias Nissler (ping if slow) 2013/09/13 12:56:48 remove extra whitespace
Joao da Silva 2013/09/13 14:02:54 Done.
71
72 // These methods can be called only if type() == TYPE_DICTIONARY.
Mattias Nissler (ping if slow) 2013/09/13 12:56:48 s/can/should/, and ideally describe what happens i
Joao da Silva 2013/09/13 14:02:54 Done.
73
74 // Returns an iterator that goes over the named properties of this schema.
75 // The returned iterator is at the beginning.
76 Iterator GetPropertiesIterator() const;
77
78 // Returns the Schema for the property named |key|. If |key| is not a known
79 // property name then the returned Schema is not valid.
80 Schema GetKnownProperty(const std::string& key) const;
81
82 // Returns the Schema for additional properties. If additional properties are
83 // not allowed for this Schema then the Schema returned is not valid.
84 Schema GetAdditionalProperties() const;
85
86 // Returns the Schema for |key| if it is a known property, otherwise returns
87 // the Schema for additional properties.
88 Schema GetProperty(const std::string& key) const;
89
Mattias Nissler (ping if slow) 2013/09/13 12:56:48 remove extra whitespace.
Joao da Silva 2013/09/13 14:02:54 Done.
90
91 // Returns the Schema for items of an array.
92 // This method can be called only if type() == TYPE_LIST.
93 Schema GetItems() const;
94
95 private:
96 const internal::SchemaNode* schema_;
97 };
98
99 // Abstract class that owns schemas for policies of a given component.
100 class POLICY_EXPORT PolicySchema {
101 public:
102 virtual ~PolicySchema() {}
103
104 // The returned Schema is valid only during the lifetime of the PolicySchema
105 // that created it. It may be obtained multiple times.
106 virtual Schema schema() const = 0;
107
108 // Returns a PolicySchema that references static data. This can be used by
109 // the embedder to pass structures generated at compile time, which can then
110 // be quickly loaded at runtime.
111 // Note: PropertiesNodes must have their PropertyNodes sorted by key.
112 static scoped_ptr<PolicySchema> Wrap(const internal::SchemaNode* schema);
113
114 // Parses the JSON schema in |schema| and returns a PolicySchema that owns
115 // the internal representation. If |schema| is invalid then NULL is returned
116 // and |error| contains a reason for the failure.
117 static scoped_ptr<PolicySchema> Parse(const std::string& schema,
118 std::string* error);
119 };
120
121 } // namespace schema
122
123 } // namespace policy
124
125 #endif // COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698