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" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "components/policy/policy_export.h" | 13 #include "components/policy/policy_export.h" |
14 | 14 |
15 namespace policy { | 15 namespace policy { |
16 namespace internal { | 16 namespace internal { |
17 | 17 |
18 struct POLICY_EXPORT SchemaData; | 18 struct POLICY_EXPORT SchemaData; |
19 struct POLICY_EXPORT SchemaNode; | 19 struct POLICY_EXPORT SchemaNode; |
20 struct POLICY_EXPORT PropertyNode; | 20 struct POLICY_EXPORT PropertyNode; |
21 struct POLICY_EXPORT PropertiesNode; | 21 struct POLICY_EXPORT PropertiesNode; |
22 | 22 |
23 } // namespace internal | 23 } // namespace internal |
24 | 24 |
25 // Option flags passed to Schema::Validate() and Schema::Normalize(), describing | |
26 // the strategy to handle unknown or invalid properties for dict type. Note | |
27 // that in Schema::Normalize() allowed errors will be dropped and thus | |
28 // ignored. | |
29 enum SchemaOnErrorStrategy { | |
30 SCHEMA_VERY_STRICT = 0, | |
Joao da Silva
2014/01/22 10:49:53
just SCHEMA_STRICT. Add a documenting comment:
//
binjin
2014/01/23 12:01:31
Done.
| |
31 SCHEMA_ALLOW_UNKNOWN_TOPLEVEL, | |
Joao da Silva
2014/01/22 10:49:53
Add a comment:
// Unknown properties in the top-l
binjin
2014/01/23 12:01:31
Done.
| |
32 SCHEMA_ALLOW_UNKNOWN, | |
Joao da Silva
2014/01/22 10:49:53
Add a comment:
// Unknown properties in any dicti
binjin
2014/01/23 12:01:31
Done.
| |
33 SCHEMA_ALLOW_INVALID_TOPLEVEL, | |
Joao da Silva
2014/01/22 10:49:53
Add a comment:
// Mismatched values will be ignor
binjin
2014/01/23 12:01:31
Done.
| |
34 SCHEMA_ALLOW_INVALID_TOPLEVEL_AND_ALLOW_UNKNOWN, | |
Joao da Silva
2014/01/22 10:49:53
Add a comment:
// Mismatched values will be ignor
binjin
2014/01/23 12:01:31
Done.
| |
35 SCHEMA_ALLOW_INVALID, | |
Joao da Silva
2014/01/22 10:49:53
Add a comment:
// Mismatched values will be ignor
binjin
2014/01/23 12:01:31
Done.
| |
36 }; | |
37 | |
25 // Describes the expected type of one policy. Also recursively describes the | 38 // Describes the expected type of one policy. Also recursively describes the |
26 // types of inner elements, for structured types. | 39 // types of inner elements, for structured types. |
27 // Objects of this class refer to external, immutable data and are cheap to | 40 // Objects of this class refer to external, immutable data and are cheap to |
28 // copy. | 41 // copy. |
29 class POLICY_EXPORT Schema { | 42 class POLICY_EXPORT Schema { |
30 public: | 43 public: |
31 // Used internally to store shared data. | 44 // Used internally to store shared data. |
32 class InternalStorage; | 45 class InternalStorage; |
33 | 46 |
34 // Builds an empty, invalid schema. | 47 // Builds an empty, invalid schema. |
(...skipping 15 matching lines...) Expand all Loading... | |
50 // the internal representation. If |schema| is invalid then an invalid Schema | 63 // the internal representation. If |schema| is invalid then an invalid Schema |
51 // is returned and |error| contains a reason for the failure. | 64 // is returned and |error| contains a reason for the failure. |
52 static Schema Parse(const std::string& schema, std::string* error); | 65 static Schema Parse(const std::string& schema, std::string* error); |
53 | 66 |
54 // Returns true if this Schema is valid. Schemas returned by the methods below | 67 // Returns true if this Schema is valid. Schemas returned by the methods below |
55 // may be invalid, and in those cases the other methods must not be used. | 68 // may be invalid, and in those cases the other methods must not be used. |
56 bool valid() const { return node_ != NULL; } | 69 bool valid() const { return node_ != NULL; } |
57 | 70 |
58 base::Value::Type type() const; | 71 base::Value::Type type() const; |
59 | 72 |
60 // Returns true if |value| conforms to this Schema. | 73 // Validate |value| against current schema, |strategy| is the strategy to |
61 bool Validate(const base::Value& value) const; | 74 // handle unknown or invalid properties in dict type. Allowed errors will be |
75 // ignored. If |value| don't conform the schema, false will be returned and | |
76 // |error| will contain a message state the detailed reason. | |
Joao da Silva
2014/01/22 10:49:53
|error| will contain the detailed reason.
binjin
2014/01/23 12:01:31
Done.
| |
77 bool Validate(const base::Value& value, | |
78 SchemaOnErrorStrategy strategy, | |
79 std::string* error) const; | |
80 | |
81 // Validate |value| against current schema, |strategy| is the strategy to | |
82 // handle unknown or invalid properties in dict type. Allowed errors will be | |
83 // dropped in place. If |value| don't conform the schema, false will be | |
84 // returned and |error| will contain a message state the detailed message. | |
Joao da Silva
2014/01/22 10:49:53
returned and |error| will contain the detailed rea
binjin
2014/01/23 12:01:31
Done.
| |
85 bool Normalize(base::Value* value, | |
86 SchemaOnErrorStrategy strategy, | |
87 std::string* error) const; | |
62 | 88 |
63 // Used to iterate over the known properties of TYPE_DICTIONARY schemas. | 89 // Used to iterate over the known properties of TYPE_DICTIONARY schemas. |
64 class POLICY_EXPORT Iterator { | 90 class POLICY_EXPORT Iterator { |
65 public: | 91 public: |
66 Iterator(const scoped_refptr<const InternalStorage>& storage, | 92 Iterator(const scoped_refptr<const InternalStorage>& storage, |
67 const internal::PropertiesNode* node); | 93 const internal::PropertiesNode* node); |
68 Iterator(const Iterator& iterator); | 94 Iterator(const Iterator& iterator); |
69 ~Iterator(); | 95 ~Iterator(); |
70 | 96 |
71 Iterator& operator=(const Iterator& iterator); | 97 Iterator& operator=(const Iterator& iterator); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 bool ValidateIntegerRestriction(int index, int value) const; | 147 bool ValidateIntegerRestriction(int index, int value) const; |
122 bool ValidateStringRestriction(int index, const char *str) const; | 148 bool ValidateStringRestriction(int index, const char *str) const; |
123 | 149 |
124 scoped_refptr<const InternalStorage> storage_; | 150 scoped_refptr<const InternalStorage> storage_; |
125 const internal::SchemaNode* node_; | 151 const internal::SchemaNode* node_; |
126 }; | 152 }; |
127 | 153 |
128 } // namespace policy | 154 } // namespace policy |
129 | 155 |
130 #endif // COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_ | 156 #endif // COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_ |
OLD | NEW |