| 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 22 matching lines...) Expand all Loading... |
| 41 SCHEMA_ALLOW_UNKNOWN, | 42 SCHEMA_ALLOW_UNKNOWN, |
| 42 // Mismatched values will be ignored at the toplevel. | 43 // Mismatched values will be ignored at the toplevel. |
| 43 SCHEMA_ALLOW_INVALID_TOPLEVEL, | 44 SCHEMA_ALLOW_INVALID_TOPLEVEL, |
| 44 // Mismatched values will be ignored at the top-level value. | 45 // Mismatched values will be ignored at the top-level value. |
| 45 // Unknown properties in any dictionary will be ignored. | 46 // Unknown properties in any dictionary will be ignored. |
| 46 SCHEMA_ALLOW_INVALID_TOPLEVEL_AND_ALLOW_UNKNOWN, | 47 SCHEMA_ALLOW_INVALID_TOPLEVEL_AND_ALLOW_UNKNOWN, |
| 47 // Mismatched values will be ignored. | 48 // Mismatched values will be ignored. |
| 48 SCHEMA_ALLOW_INVALID, | 49 SCHEMA_ALLOW_INVALID, |
| 49 }; | 50 }; |
| 50 | 51 |
| 52 class Schema; |
| 53 |
| 54 typedef std::vector<Schema> SchemaList; |
| 55 |
| 51 // Describes the expected type of one policy. Also recursively describes the | 56 // Describes the expected type of one policy. Also recursively describes the |
| 52 // types of inner elements, for structured types. | 57 // types of inner elements, for structured types. |
| 53 // Objects of this class refer to external, immutable data and are cheap to | 58 // Objects of this class refer to external, immutable data and are cheap to |
| 54 // copy. | 59 // copy. |
| 55 class POLICY_EXPORT Schema { | 60 class POLICY_EXPORT Schema { |
| 56 public: | 61 public: |
| 57 // Used internally to store shared data. | 62 // Used internally to store shared data. |
| 58 class InternalStorage; | 63 class InternalStorage; |
| 59 | 64 |
| 60 // Builds an empty, invalid schema. | 65 // Builds an empty, invalid schema. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 // otherwise invalid memory will be read. A CHECK is currently enforcing this. | 146 // otherwise invalid memory will be read. A CHECK is currently enforcing this. |
| 142 | 147 |
| 143 // Returns an iterator that goes over the named properties of this schema. | 148 // Returns an iterator that goes over the named properties of this schema. |
| 144 // The returned iterator is at the beginning. | 149 // The returned iterator is at the beginning. |
| 145 Iterator GetPropertiesIterator() const; | 150 Iterator GetPropertiesIterator() const; |
| 146 | 151 |
| 147 // Returns the Schema for the property named |key|. If |key| is not a known | 152 // Returns the Schema for the property named |key|. If |key| is not a known |
| 148 // property name then the returned Schema is not valid. | 153 // property name then the returned Schema is not valid. |
| 149 Schema GetKnownProperty(const std::string& key) const; | 154 Schema GetKnownProperty(const std::string& key) const; |
| 150 | 155 |
| 156 // Returns all Schemas from pattern properties that match |key|. May be empty. |
| 157 SchemaList GetPatternProperties(const std::string& key) const; |
| 158 |
| 151 // Returns the Schema for additional properties. If additional properties are | 159 // Returns the Schema for additional properties. If additional properties are |
| 152 // not allowed for this Schema then the Schema returned is not valid. | 160 // not allowed for this Schema then the Schema returned is not valid. |
| 153 Schema GetAdditionalProperties() const; | 161 Schema GetAdditionalProperties() const; |
| 154 | 162 |
| 155 // Returns the Schema for |key| if it is a known property, otherwise returns | 163 // Returns the Schema for |key| if it is a known property, otherwise returns |
| 156 // the Schema for additional properties. | 164 // the Schema for additional properties. |
| 165 // DEPRECATED: This function didn't consider patternProperties, use |
| 166 // GetMatchingProperties() instead. |
| 167 // TODO(binjin): Replace calls to this function with GetKnownProperty() or |
| 168 // GetMatchingProperties() and remove this later. |
| 157 Schema GetProperty(const std::string& key) const; | 169 Schema GetProperty(const std::string& key) const; |
| 158 | 170 |
| 171 // Returns all Schemas that are supposed to be validated against for |key|. |
| 172 // May be empty. |
| 173 SchemaList GetMatchingProperties(const std::string& key) const; |
| 174 |
| 159 // Returns the Schema for items of an array. | 175 // Returns the Schema for items of an array. |
| 160 // This method should be called only if type() == TYPE_LIST, | 176 // This method should be called only if type() == TYPE_LIST, |
| 161 // otherwise invalid memory will be read. A CHECK is currently enforcing this. | 177 // otherwise invalid memory will be read. A CHECK is currently enforcing this. |
| 162 Schema GetItems() const; | 178 Schema GetItems() const; |
| 163 | 179 |
| 164 private: | 180 private: |
| 165 // Builds a schema pointing to the inner structure of |storage|, | 181 // Builds a schema pointing to the inner structure of |storage|, |
| 166 // rooted at |node|. | 182 // rooted at |node|. |
| 167 Schema(const scoped_refptr<const InternalStorage>& storage, | 183 Schema(const scoped_refptr<const InternalStorage>& storage, |
| 168 const internal::SchemaNode* node); | 184 const internal::SchemaNode* node); |
| 169 | 185 |
| 170 bool ValidateIntegerRestriction(int index, int value) const; | 186 bool ValidateIntegerRestriction(int index, int value) const; |
| 171 bool ValidateStringRestriction(int index, const char* str) const; | 187 bool ValidateStringRestriction(int index, const char* str) const; |
| 172 | 188 |
| 173 scoped_refptr<const InternalStorage> storage_; | 189 scoped_refptr<const InternalStorage> storage_; |
| 174 const internal::SchemaNode* node_; | 190 const internal::SchemaNode* node_; |
| 175 }; | 191 }; |
| 176 | 192 |
| 177 } // namespace policy | 193 } // namespace policy |
| 178 | 194 |
| 179 #endif // COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_ | 195 #endif // COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_ |
| OLD | NEW |