| 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 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 static Schema Parse(const std::string& schema, std::string* error); | 72 static Schema Parse(const std::string& schema, std::string* error); |
| 73 | 73 |
| 74 // Returns true if this Schema is valid. Schemas returned by the methods below | 74 // Returns true if this Schema is valid. Schemas returned by the methods below |
| 75 // may be invalid, and in those cases the other methods must not be used. | 75 // may be invalid, and in those cases the other methods must not be used. |
| 76 bool valid() const { return node_ != NULL; } | 76 bool valid() const { return node_ != NULL; } |
| 77 | 77 |
| 78 base::Value::Type type() const; | 78 base::Value::Type type() const; |
| 79 | 79 |
| 80 // Validate |value| against current schema, |strategy| is the strategy to | 80 // Validate |value| against current schema, |strategy| is the strategy to |
| 81 // handle unknown properties or invalid values. Allowed errors will be | 81 // handle unknown properties or invalid values. Allowed errors will be |
| 82 // ignored. If |value| don't conform the schema, false will be returned and | 82 // ignored. |error_path| and |error| will contain the last error location and |
| 83 // |error| will contain the detailed reason. | 83 // detailed message if |value| doesn't strictly conform to the schema. If |
| 84 // |value| doesn't conform to the schema even within the allowance of |
| 85 // |strategy|, false will be returned and |error_path| and |error| will |
| 86 // contain the corresponding error that caused the failure. |error_path| can |
| 87 // be NULL and in that case no error path will be returned. |
| 84 bool Validate(const base::Value& value, | 88 bool Validate(const base::Value& value, |
| 85 SchemaOnErrorStrategy strategy, | 89 SchemaOnErrorStrategy strategy, |
| 90 std::string* error_path, |
| 86 std::string* error) const; | 91 std::string* error) const; |
| 87 | 92 |
| 88 // Validate |value| against current schema, |strategy| is the strategy to | 93 // Same as Validate() but drop values with errors instead of ignoring them. |
| 89 // handle unknown properties or invalid values. Allowed errors will be | |
| 90 // dropped in place. If |value| don't conform the schema, false will be | |
| 91 // returned and |error| will contain the detailed message. | |
| 92 bool Normalize(base::Value* value, | 94 bool Normalize(base::Value* value, |
| 93 SchemaOnErrorStrategy strategy, | 95 SchemaOnErrorStrategy strategy, |
| 96 std::string* error_path, |
| 94 std::string* error) const; | 97 std::string* error) const; |
| 95 | 98 |
| 96 // Used to iterate over the known properties of TYPE_DICTIONARY schemas. | 99 // Used to iterate over the known properties of TYPE_DICTIONARY schemas. |
| 97 class POLICY_EXPORT Iterator { | 100 class POLICY_EXPORT Iterator { |
| 98 public: | 101 public: |
| 99 Iterator(const scoped_refptr<const InternalStorage>& storage, | 102 Iterator(const scoped_refptr<const InternalStorage>& storage, |
| 100 const internal::PropertiesNode* node); | 103 const internal::PropertiesNode* node); |
| 101 Iterator(const Iterator& iterator); | 104 Iterator(const Iterator& iterator); |
| 102 ~Iterator(); | 105 ~Iterator(); |
| 103 | 106 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 // otherwise invalid memory will be read. A CHECK is currently enforcing this. | 148 // otherwise invalid memory will be read. A CHECK is currently enforcing this. |
| 146 Schema GetItems() const; | 149 Schema GetItems() const; |
| 147 | 150 |
| 148 private: | 151 private: |
| 149 // Builds a schema pointing to the inner structure of |storage|, | 152 // Builds a schema pointing to the inner structure of |storage|, |
| 150 // rooted at |node|. | 153 // rooted at |node|. |
| 151 Schema(const scoped_refptr<const InternalStorage>& storage, | 154 Schema(const scoped_refptr<const InternalStorage>& storage, |
| 152 const internal::SchemaNode* node); | 155 const internal::SchemaNode* node); |
| 153 | 156 |
| 154 bool ValidateIntegerRestriction(int index, int value) const; | 157 bool ValidateIntegerRestriction(int index, int value) const; |
| 155 bool ValidateStringRestriction(int index, const char *str) const; | 158 bool ValidateStringRestriction(int index, const char* str) const; |
| 156 | 159 |
| 157 scoped_refptr<const InternalStorage> storage_; | 160 scoped_refptr<const InternalStorage> storage_; |
| 158 const internal::SchemaNode* node_; | 161 const internal::SchemaNode* node_; |
| 159 }; | 162 }; |
| 160 | 163 |
| 161 } // namespace policy | 164 } // namespace policy |
| 162 | 165 |
| 163 #endif // COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_ | 166 #endif // COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_ |
| OLD | NEW |