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 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_POLICY_CORE_COMMON_SCHEMA_INTERNAL_H_ 6 #define COMPONENTS_POLICY_CORE_COMMON_SCHEMA_INTERNAL_H_ 7 8 #include "base/values.h" 9 #include "components/policy/policy_export.h" 10 11 namespace policy { 12 namespace internal { 13 14 // These types are used internally by the SchemaOwner parser, and by the 15 // compile-time code generator. They shouldn't be used directly. 16 17 // Represents the type of one policy, or an item of a list policy, or a 18 // property of a map policy. 19 struct POLICY_EXPORT SchemaNode { 20 // The policy type. 21 base::Value::Type type; 22 23 // If |type| is Type::DICTIONARY then |extra| is an offset into 24 // SchemaData::properties_nodes that indexes the PropertiesNode describing 25 // the entries of this dictionary. 26 // 27 // If |type| is Type::LIST then |extra| is an offset into 28 // SchemaData::schema_nodes that indexes the SchemaNode describing the items 29 // of this list. 30 // 31 // If |type| is Type::INTEGER or Type::STRING, and contains corresponding 32 // restriction (enumeration of possible values, or range for integer), then 33 // |extra| is an offset into SchemaData::restriction_nodes that indexes the 34 // RestrictionNode describing the restriction on the value. 35 // 36 // Otherwise extra is -1 and is invalid. 37 int extra; 38 }; 39 40 // Represents an entry of a map policy. 41 struct POLICY_EXPORT PropertyNode { 42 // The entry key. 43 const char* key; 44 45 // An offset into SchemaData::schema_nodes that indexes the SchemaNode 46 // describing the structure of this key. 47 int schema; 48 }; 49 50 // Represents the list of keys of a map policy. 51 struct POLICY_EXPORT PropertiesNode { 52 // An offset into SchemaData::property_nodes that indexes the PropertyNode 53 // describing the first known property of this map policy. 54 int begin; 55 56 // An offset into SchemaData::property_nodes that indexes the PropertyNode 57 // right beyond the last known property of this map policy. 58 // 59 // If |begin == end| then the map policy that this PropertiesNode corresponds 60 // to does not have known properties. 61 // 62 // Note that the range [begin, end) is sorted by PropertyNode::key, so that 63 // properties can be looked up by binary searching in the range. 64 int end; 65 66 // An offset into SchemaData::property_nodes that indexes the PropertyNode 67 // right beyond the last known pattern property. 68 // 69 // [end, pattern_end) is the range that covers all pattern properties 70 // defined. It's not required to be sorted. 71 int pattern_end; 72 73 // An offset into SchemaData::required_properties that indexes the first 74 // required property of this map policy. 75 int required_begin; 76 77 // An offset into SchemaData::required_properties that indexes the property 78 // right beyond the last required property. 79 // 80 // If |required_begin == required_end|, then the map policy that this 81 // PropertiesNode corresponds to does not have any required properties. 82 // 83 // Note that the range [required_begin, required_end) is not sorted. 84 int required_end; 85 86 // If this map policy supports keys with any value (besides the well-known 87 // values described in the range [begin, end)) then |additional| is an offset 88 // into SchemaData::schema_nodes that indexes the SchemaNode describing the 89 // structure of the values for those keys. Otherwise |additional| is -1 and 90 // is invalid. 91 int additional; 92 }; 93 94 // Represents the restriction on Type::INTEGER or Type::STRING instance of 95 // base::Value. 96 union POLICY_EXPORT RestrictionNode { 97 // Offsets into SchemaData::int_enums or SchemaData::string_enums, the 98 // entry of which describes the enumeration of all possible values of 99 // corresponding integer or string value. |offset_begin| being strictly less 100 // than |offset_end| is assumed. 101 struct EnumerationRestriction { 102 int offset_begin; 103 int offset_end; 104 } enumeration_restriction; 105 106 // For integer type only, represents that all values between |min_value| 107 // and |max_value| can be choosen. Note that integer type in base::Value 108 // is bounded, so this can also be used if only one of |min_value| and 109 // |max_value| is stated. |max_value| being greater or equal to |min_value| 110 // is assumed. 111 struct RangedRestriction { 112 int max_value; 113 int min_value; 114 } ranged_restriction; 115 116 // For string type only, requires |pattern_index| and |pattern_index_backup| 117 // to be exactly the same. And it's an offset into SchemaData::string_enums 118 // which contains the regular expression that the target string must follow. 119 struct StringPatternRestriction { 120 int pattern_index; 121 int pattern_index_backup; 122 } string_pattern_restriction; 123 }; 124 125 126 // Contains arrays of related nodes. All of the offsets in these nodes reference 127 // other nodes in these arrays. 128 struct POLICY_EXPORT SchemaData { 129 const SchemaNode* schema_nodes; 130 const PropertyNode* property_nodes; 131 const PropertiesNode* properties_nodes; 132 const RestrictionNode* restriction_nodes; 133 const char* const* required_properties; 134 135 const int* int_enums; 136 const char* const* string_enums; 137 int validation_schema_root_index; 138 }; 139 140 } // namespace internal 141 } // namespace policy 142 143 #endif // COMPONENTS_POLICY_CORE_COMMON_SCHEMA_INTERNAL_H_ 144