OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_ | 5 #ifndef COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_ |
6 #define COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_ | 6 #define COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | |
9 | 10 |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
12 #include "base/values.h" | 13 #include "base/values.h" |
13 #include "components/policy/policy_export.h" | 14 #include "components/policy/policy_export.h" |
14 | 15 |
15 namespace policy { | 16 namespace policy { |
16 namespace internal { | 17 namespace internal { |
17 | 18 |
18 struct POLICY_EXPORT SchemaData; | 19 struct POLICY_EXPORT SchemaData; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 | 51 |
51 // Describes the expected type of one policy. Also recursively describes the | 52 // Describes the expected type of one policy. Also recursively describes the |
52 // types of inner elements, for structured types. | 53 // types of inner elements, for structured types. |
53 // Objects of this class refer to external, immutable data and are cheap to | 54 // Objects of this class refer to external, immutable data and are cheap to |
54 // copy. | 55 // copy. |
55 class POLICY_EXPORT Schema { | 56 class POLICY_EXPORT Schema { |
56 public: | 57 public: |
57 // Used internally to store shared data. | 58 // Used internally to store shared data. |
58 class InternalStorage; | 59 class InternalStorage; |
59 | 60 |
61 typedef std::vector<Schema> SchemaList; | |
Joao da Silva
2014/04/02 09:51:11
Put this outside the class. It will require a forw
binjin
2014/04/03 10:13:37
Done.
| |
62 | |
60 // Builds an empty, invalid schema. | 63 // Builds an empty, invalid schema. |
61 Schema(); | 64 Schema(); |
62 | 65 |
63 // Makes a copy of |schema| that shares the same internal storage. | 66 // Makes a copy of |schema| that shares the same internal storage. |
64 Schema(const Schema& schema); | 67 Schema(const Schema& schema); |
65 | 68 |
66 ~Schema(); | 69 ~Schema(); |
67 | 70 |
68 Schema& operator=(const Schema& schema); | 71 Schema& operator=(const Schema& schema); |
69 | 72 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 // otherwise invalid memory will be read. A CHECK is currently enforcing this. | 144 // otherwise invalid memory will be read. A CHECK is currently enforcing this. |
142 | 145 |
143 // Returns an iterator that goes over the named properties of this schema. | 146 // Returns an iterator that goes over the named properties of this schema. |
144 // The returned iterator is at the beginning. | 147 // The returned iterator is at the beginning. |
145 Iterator GetPropertiesIterator() const; | 148 Iterator GetPropertiesIterator() const; |
146 | 149 |
147 // Returns the Schema for the property named |key|. If |key| is not a known | 150 // Returns the Schema for the property named |key|. If |key| is not a known |
148 // property name then the returned Schema is not valid. | 151 // property name then the returned Schema is not valid. |
149 Schema GetKnownProperty(const std::string& key) const; | 152 Schema GetKnownProperty(const std::string& key) const; |
150 | 153 |
154 // Returns all Schemas from pattern properties that matchs |key|, might be | |
Joao da Silva
2014/04/02 09:51:11
[...] that match |key|. May be empty.
binjin
2014/04/03 10:13:37
Done.
| |
155 // empty. | |
156 SchemaList GetPatternProperties(const std::string& key) const; | |
157 | |
151 // Returns the Schema for additional properties. If additional properties are | 158 // Returns the Schema for additional properties. If additional properties are |
152 // not allowed for this Schema then the Schema returned is not valid. | 159 // not allowed for this Schema then the Schema returned is not valid. |
153 Schema GetAdditionalProperties() const; | 160 Schema GetAdditionalProperties() const; |
154 | 161 |
155 // Returns the Schema for |key| if it is a known property, otherwise returns | 162 // Returns the Schema for |key| if it is a known property, otherwise returns |
156 // the Schema for additional properties. | 163 // the Schema for additional properties. |
164 // DEPRECATED: This function didn't consider patternProperties, use | |
165 // GetMatchingProperties() instead. | |
157 Schema GetProperty(const std::string& key) const; | 166 Schema GetProperty(const std::string& key) const; |
Joao da Silva
2014/04/02 09:51:11
Leave a TODO to remove this.
binjin
2014/04/03 10:13:37
Done.
| |
158 | 167 |
168 // Returns all Schemas that are supposed to be validate against for |key|, | |
169 // might be empty. | |
Joao da Silva
2014/04/02 09:51:11
Returns all Schemas that are supposed to be valida
binjin
2014/04/03 10:13:37
Done.
| |
170 SchemaList GetMatchingProperties(const std::string& key) const; | |
171 | |
159 // Returns the Schema for items of an array. | 172 // Returns the Schema for items of an array. |
160 // This method should be called only if type() == TYPE_LIST, | 173 // This method should be called only if type() == TYPE_LIST, |
161 // otherwise invalid memory will be read. A CHECK is currently enforcing this. | 174 // otherwise invalid memory will be read. A CHECK is currently enforcing this. |
162 Schema GetItems() const; | 175 Schema GetItems() const; |
163 | 176 |
164 private: | 177 private: |
165 // Builds a schema pointing to the inner structure of |storage|, | 178 // Builds a schema pointing to the inner structure of |storage|, |
166 // rooted at |node|. | 179 // rooted at |node|. |
167 Schema(const scoped_refptr<const InternalStorage>& storage, | 180 Schema(const scoped_refptr<const InternalStorage>& storage, |
168 const internal::SchemaNode* node); | 181 const internal::SchemaNode* node); |
169 | 182 |
170 bool ValidateIntegerRestriction(int index, int value) const; | 183 bool ValidateIntegerRestriction(int index, int value) const; |
171 bool ValidateStringRestriction(int index, const char* str) const; | 184 bool ValidateStringRestriction(int index, const char* str) const; |
172 | 185 |
173 scoped_refptr<const InternalStorage> storage_; | 186 scoped_refptr<const InternalStorage> storage_; |
174 const internal::SchemaNode* node_; | 187 const internal::SchemaNode* node_; |
175 }; | 188 }; |
176 | 189 |
177 } // namespace policy | 190 } // namespace policy |
178 | 191 |
179 #endif // COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_ | 192 #endif // COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_ |
OLD | NEW |