| 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 #include <vector> |
| 10 | 10 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 // the bool that |changed| pointed to to false before calling Normalize(). | 106 // the bool that |changed| pointed to to false before calling Normalize(). |
| 107 // |changed| can be NULL and in that case no boolean will be set. | 107 // |changed| can be NULL and in that case no boolean will be set. |
| 108 // This function will also take the ownership of dropped base::Value and | 108 // This function will also take the ownership of dropped base::Value and |
| 109 // destroy them. | 109 // destroy them. |
| 110 bool Normalize(base::Value* value, | 110 bool Normalize(base::Value* value, |
| 111 SchemaOnErrorStrategy strategy, | 111 SchemaOnErrorStrategy strategy, |
| 112 std::string* error_path, | 112 std::string* error_path, |
| 113 std::string* error, | 113 std::string* error, |
| 114 bool* changed) const; | 114 bool* changed) const; |
| 115 | 115 |
| 116 // Used to iterate over the known properties of TYPE_DICTIONARY schemas. | 116 // Used to iterate over the known properties of Type::DICTIONARY schemas. |
| 117 class POLICY_EXPORT Iterator { | 117 class POLICY_EXPORT Iterator { |
| 118 public: | 118 public: |
| 119 Iterator(const scoped_refptr<const InternalStorage>& storage, | 119 Iterator(const scoped_refptr<const InternalStorage>& storage, |
| 120 const internal::PropertiesNode* node); | 120 const internal::PropertiesNode* node); |
| 121 Iterator(const Iterator& iterator); | 121 Iterator(const Iterator& iterator); |
| 122 ~Iterator(); | 122 ~Iterator(); |
| 123 | 123 |
| 124 Iterator& operator=(const Iterator& iterator); | 124 Iterator& operator=(const Iterator& iterator); |
| 125 | 125 |
| 126 // The other methods must not be called if the iterator is at the end. | 126 // The other methods must not be called if the iterator is at the end. |
| 127 bool IsAtEnd() const; | 127 bool IsAtEnd() const; |
| 128 | 128 |
| 129 // Advances the iterator to the next property. | 129 // Advances the iterator to the next property. |
| 130 void Advance(); | 130 void Advance(); |
| 131 | 131 |
| 132 // Returns the name of the current property. | 132 // Returns the name of the current property. |
| 133 const char* key() const; | 133 const char* key() const; |
| 134 | 134 |
| 135 // Returns the Schema for the current property. This Schema is always valid. | 135 // Returns the Schema for the current property. This Schema is always valid. |
| 136 Schema schema() const; | 136 Schema schema() const; |
| 137 | 137 |
| 138 private: | 138 private: |
| 139 scoped_refptr<const InternalStorage> storage_; | 139 scoped_refptr<const InternalStorage> storage_; |
| 140 const internal::PropertyNode* it_; | 140 const internal::PropertyNode* it_; |
| 141 const internal::PropertyNode* end_; | 141 const internal::PropertyNode* end_; |
| 142 }; | 142 }; |
| 143 | 143 |
| 144 // These methods should be called only if type() == TYPE_DICTIONARY, | 144 // These methods should be called only if type() == Type::DICTIONARY, |
| 145 // otherwise invalid memory will be read. A CHECK is currently enforcing this. | 145 // otherwise invalid memory will be read. A CHECK is currently enforcing this. |
| 146 | 146 |
| 147 // Returns an iterator that goes over the named properties of this schema. | 147 // Returns an iterator that goes over the named properties of this schema. |
| 148 // The returned iterator is at the beginning. | 148 // The returned iterator is at the beginning. |
| 149 Iterator GetPropertiesIterator() const; | 149 Iterator GetPropertiesIterator() const; |
| 150 | 150 |
| 151 // Returns the Schema for the property named |key|. If |key| is not a known | 151 // Returns the Schema for the property named |key|. If |key| is not a known |
| 152 // property name then the returned Schema is not valid. | 152 // property name then the returned Schema is not valid. |
| 153 Schema GetKnownProperty(const std::string& key) const; | 153 Schema GetKnownProperty(const std::string& key) const; |
| 154 | 154 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 165 // GetMatchingProperties() instead. | 165 // GetMatchingProperties() instead. |
| 166 // TODO(binjin): Replace calls to this function with GetKnownProperty() or | 166 // TODO(binjin): Replace calls to this function with GetKnownProperty() or |
| 167 // GetMatchingProperties() and remove this later. | 167 // GetMatchingProperties() and remove this later. |
| 168 Schema GetProperty(const std::string& key) const; | 168 Schema GetProperty(const std::string& key) const; |
| 169 | 169 |
| 170 // Returns all Schemas that are supposed to be validated against for |key|. | 170 // Returns all Schemas that are supposed to be validated against for |key|. |
| 171 // May be empty. | 171 // May be empty. |
| 172 SchemaList GetMatchingProperties(const std::string& key) const; | 172 SchemaList GetMatchingProperties(const std::string& key) const; |
| 173 | 173 |
| 174 // Returns the Schema for items of an array. | 174 // Returns the Schema for items of an array. |
| 175 // This method should be called only if type() == TYPE_LIST, | 175 // This method should be called only if type() == Type::LIST, |
| 176 // otherwise invalid memory will be read. A CHECK is currently enforcing this. | 176 // otherwise invalid memory will be read. A CHECK is currently enforcing this. |
| 177 Schema GetItems() const; | 177 Schema GetItems() const; |
| 178 | 178 |
| 179 private: | 179 private: |
| 180 // Builds a schema pointing to the inner structure of |storage|, | 180 // Builds a schema pointing to the inner structure of |storage|, |
| 181 // rooted at |node|. | 181 // rooted at |node|. |
| 182 Schema(const scoped_refptr<const InternalStorage>& storage, | 182 Schema(const scoped_refptr<const InternalStorage>& storage, |
| 183 const internal::SchemaNode* node); | 183 const internal::SchemaNode* node); |
| 184 | 184 |
| 185 bool ValidateIntegerRestriction(int index, int value) const; | 185 bool ValidateIntegerRestriction(int index, int value) const; |
| 186 bool ValidateStringRestriction(int index, const char* str) const; | 186 bool ValidateStringRestriction(int index, const char* str) const; |
| 187 | 187 |
| 188 scoped_refptr<const InternalStorage> storage_; | 188 scoped_refptr<const InternalStorage> storage_; |
| 189 const internal::SchemaNode* node_; | 189 const internal::SchemaNode* node_; |
| 190 }; | 190 }; |
| 191 | 191 |
| 192 } // namespace policy | 192 } // namespace policy |
| 193 | 193 |
| 194 #endif // COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_ | 194 #endif // COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_ |
| OLD | NEW |