Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: components/policy/core/common/schema.h

Issue 23851022: Added new policy Schema classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « components/policy.gypi ('k') | components/policy/core/common/schema.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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_H_
6 #define COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_
7
8 #include "base/basictypes.h"
9 #include "base/values.h"
10 #include "components/policy/policy_export.h"
11
12 namespace policy {
13
14 namespace schema {
15
16 // TODO: internal stuff just needs to be forward declared here.
17 namespace internal {
18
19 struct POLICY_EXPORT SchemaNode {
20 base::Value::Type type;
21
22 // If type is TYPE_LIST then this is a SchemaNode*.
23 // If type is TYPE_DICTIONARY then this is a PropertiesNode*.
24 // Otherwise it's NULL.
25 const void* extra;
Mattias Nissler (ping if slow) 2013/09/13 12:56:48 Use a union here?
26 };
27
28 struct POLICY_EXPORT PropertyNode {
29 const char* key;
30 const SchemaNode* schema;
31 };
32
33 struct POLICY_EXPORT PropertiesNode {
34 const PropertyNode* begin;
35 const PropertyNode* end;
36 const SchemaNode* additional;
37 };
38
39 } // namespace internal
40
41 class Schema {
42 public:
43 explicit Schema(const internal::SchemaNode* schema);
44 Schema(const Schema& schema);
45
46 Schema& operator=(const Schema& schema);
47
48 bool valid() const { return schema_ != NULL; }
49 base::Value::Type type() const;
50
51 class Iterator {
52 public:
53 explicit Iterator(const internal::PropertiesNode* properties);
54 Iterator(const Iterator& iterator);
55 ~Iterator();
56
57 Iterator& operator=(const Iterator& iterator);
58
59 bool IsAtEnd() const;
60 void Advance();
61
62 const char* key() const;
63 Schema schema() const;
64
65 private:
66 const internal::PropertyNode* it_;
67 const internal::PropertyNode* end_;
68 };
69
70 // These methods can be called only if type() == TYPE_DICTIONARY.
71 Iterator GetPropertiesIterator() const;
72 Schema GetKnownProperty(const std::string& key) const;
73 Schema GetAdditionalProperties() const;
74 Schema GetProperty(const std::string& key) const;
75
76 // This method can be called only if type() == TYPE_LIST.
77 Schema GetItems() const;
78
79 private:
80 const internal::SchemaNode* schema_;
81 };
82
83 class PolicySchema {
84 public:
85 virtual ~PolicySchema() {}
86
87 // The returned Schema is valid only during the lifetime of the PolicySchema
88 // that created it.
89 virtual Schema schema() const = 0;
90
91 static scoped_ptr<PolicySchema> GetChromePolicySchema();
92
93 static scoped_ptr<PolicySchema> Parse(const std::string& schema,
94 std::string* error);
95 };
96
97 } // namespace schema
98
99 } // namespace policy
100
101 #endif // COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_
OLDNEW
« no previous file with comments | « components/policy.gypi ('k') | components/policy/core/common/schema.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698