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 // If this map policy supports keys with any value (besides the well-known 74 // values described in the range [begin, end)) then |additional| is an offset 75 // into SchemaData::schema_nodes that indexes the SchemaNode describing the 76 // structure of the values for those keys. Otherwise |additional| is -1 and 77 // is invalid. 78 int additional; 79 }; 80 81 // Represents the restriction on TYPE_INTEGER or TYPE_STRING instance of 82 // base::Value. 83 union POLICY_EXPORT RestrictionNode { 84 // Offsets into SchemaData::int_enums or SchemaData::string_enums, the 85 // entry of which describes the enumeration of all possible values of 86 // corresponding integer or string value. |offset_begin| being strictly less 87 // than |offset_end| is assumed. 88 struct EnumerationRestriction { 89 int offset_begin; 90 int offset_end; 91 } enumeration_restriction; 92 93 // For integer type only, represents that all values between |min_value| 94 // and |max_value| can be choosen. Note that integer type in base::Value 95 // is bounded, so this can also be used if only one of |min_value| and 96 // |max_value| is stated. |max_value| being greater or equal to |min_value| 97 // is assumed. 98 struct RangedRestriction { 99 int max_value; 100 int min_value; 101 } ranged_restriction; 102 103 // For string type only, requires |pattern_index| and |pattern_index_backup| 104 // to be exactly the same. And it's an offset into SchemaData::string_enums 105 // which contains the regular expression that the target string must follow. 106 struct StringPatternRestriction { 107 int pattern_index; 108 int pattern_index_backup; 109 } string_pattern_restriction; 110 }; 111 112 113 // Contains arrays of related nodes. All of the offsets in these nodes reference 114 // other nodes in these arrays. 115 struct POLICY_EXPORT SchemaData { 116 const SchemaNode* schema_nodes; 117 const PropertyNode* property_nodes; 118 const PropertiesNode* properties_nodes; 119 const RestrictionNode* restriction_nodes; 120 121 const int* int_enums; 122 const char** string_enums; 123 }; 124 125 } // namespace internal 126 } // namespace policy 127 128 #endif // COMPONENTS_POLICY_CORE_COMMON_SCHEMA_INTERNAL_H_ 129