Index: components/policy/core/common/schema.h |
diff --git a/components/policy/core/common/schema.h b/components/policy/core/common/schema.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6a904a41d4b76f970098f4c6b02b3189c5fbe7cc |
--- /dev/null |
+++ b/components/policy/core/common/schema.h |
@@ -0,0 +1,101 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_ |
+#define COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_ |
+ |
+#include "base/basictypes.h" |
+#include "base/values.h" |
+#include "components/policy/policy_export.h" |
+ |
+namespace policy { |
+ |
+namespace schema { |
+ |
+// TODO: internal stuff just needs to be forward declared here. |
+namespace internal { |
+ |
+struct POLICY_EXPORT SchemaNode { |
+ base::Value::Type type; |
+ |
+ // If type is TYPE_LIST then this is a SchemaNode*. |
+ // If type is TYPE_DICTIONARY then this is a PropertiesNode*. |
+ // Otherwise it's NULL. |
+ const void* extra; |
Mattias Nissler (ping if slow)
2013/09/13 12:56:48
Use a union here?
|
+}; |
+ |
+struct POLICY_EXPORT PropertyNode { |
+ const char* key; |
+ const SchemaNode* schema; |
+}; |
+ |
+struct POLICY_EXPORT PropertiesNode { |
+ const PropertyNode* begin; |
+ const PropertyNode* end; |
+ const SchemaNode* additional; |
+}; |
+ |
+} // namespace internal |
+ |
+class Schema { |
+ public: |
+ explicit Schema(const internal::SchemaNode* schema); |
+ Schema(const Schema& schema); |
+ |
+ Schema& operator=(const Schema& schema); |
+ |
+ bool valid() const { return schema_ != NULL; } |
+ base::Value::Type type() const; |
+ |
+ class Iterator { |
+ public: |
+ explicit Iterator(const internal::PropertiesNode* properties); |
+ Iterator(const Iterator& iterator); |
+ ~Iterator(); |
+ |
+ Iterator& operator=(const Iterator& iterator); |
+ |
+ bool IsAtEnd() const; |
+ void Advance(); |
+ |
+ const char* key() const; |
+ Schema schema() const; |
+ |
+ private: |
+ const internal::PropertyNode* it_; |
+ const internal::PropertyNode* end_; |
+ }; |
+ |
+ // These methods can be called only if type() == TYPE_DICTIONARY. |
+ Iterator GetPropertiesIterator() const; |
+ Schema GetKnownProperty(const std::string& key) const; |
+ Schema GetAdditionalProperties() const; |
+ Schema GetProperty(const std::string& key) const; |
+ |
+ // This method can be called only if type() == TYPE_LIST. |
+ Schema GetItems() const; |
+ |
+ private: |
+ const internal::SchemaNode* schema_; |
+}; |
+ |
+class PolicySchema { |
+ public: |
+ virtual ~PolicySchema() {} |
+ |
+ // The returned Schema is valid only during the lifetime of the PolicySchema |
+ // that created it. |
+ virtual Schema schema() const = 0; |
+ |
+ static scoped_ptr<PolicySchema> GetChromePolicySchema(); |
+ |
+ static scoped_ptr<PolicySchema> Parse(const std::string& schema, |
+ std::string* error); |
+}; |
+ |
+} // namespace schema |
+ |
+} // namespace policy |
+ |
+#endif // COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_ |