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

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

Issue 171403004: Add touch flag to output of Schema::Normalize() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@split-1
Patch Set: rebase Created 6 years, 10 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
OLDNEW
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 25 // Option flags passed to Schema::Validate() and Schema::Normalize(), describing
26 // the strategy to handle unknown properties or invalid values for dict type. 26 // the strategy to handle unknown properties or invalid values for dict type.
27 // Note that in Schema::Normalize() allowed errors will be dropped and thus 27 // Note that in Schema::Normalize() allowed errors will be dropped and thus
28 // ignored. 28 // ignored.
29 // Unknown error indicates that some value in a dictionary (may or may not be
30 // the one in root) have unknown property name according to schema.
31 // Invalid error indicates a validation failure against the schema. As
32 // validation is done recursively, a validation failure of dict properties or
33 // list items might be ignored (or dropped in Normalize()) or trigger whole
34 // dictionary/list validation failure.
29 enum SchemaOnErrorStrategy { 35 enum SchemaOnErrorStrategy {
30 // No errors will be allowed. 36 // No errors will be allowed.
31 SCHEMA_STRICT = 0, 37 SCHEMA_STRICT = 0,
32 // Unknown properties in the top-level dictionary will be ignored. 38 // Unknown properties in the top-level dictionary will be ignored.
33 SCHEMA_ALLOW_UNKNOWN_TOPLEVEL, 39 SCHEMA_ALLOW_UNKNOWN_TOPLEVEL,
34 // Unknown properties in any dictionary will be ignored. 40 // Unknown properties in any dictionary will be ignored.
35 SCHEMA_ALLOW_UNKNOWN, 41 SCHEMA_ALLOW_UNKNOWN,
36 // Mismatched values will be ignored at the toplevel. 42 // Mismatched values will be ignored at the toplevel.
37 SCHEMA_ALLOW_INVALID_TOPLEVEL, 43 SCHEMA_ALLOW_INVALID_TOPLEVEL,
38 // Mismatched values will be ignored at the top-level value. 44 // Mismatched values will be ignored at the top-level value.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // detailed message if |value| doesn't strictly conform to the schema. If 89 // detailed message if |value| doesn't strictly conform to the schema. If
84 // |value| doesn't conform to the schema even within the allowance of 90 // |value| doesn't conform to the schema even within the allowance of
85 // |strategy|, false will be returned and |error_path| and |error| will 91 // |strategy|, false will be returned and |error_path| and |error| will
86 // contain the corresponding error that caused the failure. |error_path| can 92 // contain the corresponding error that caused the failure. |error_path| can
87 // be NULL and in that case no error path will be returned. 93 // be NULL and in that case no error path will be returned.
88 bool Validate(const base::Value& value, 94 bool Validate(const base::Value& value,
89 SchemaOnErrorStrategy strategy, 95 SchemaOnErrorStrategy strategy,
90 std::string* error_path, 96 std::string* error_path,
91 std::string* error) const; 97 std::string* error) const;
92 98
93 // Same as Validate() but drop values with errors instead of ignoring them. 99 // Similar to Validate() but drop values with errors instead of ignoring them.
100 // |changed| is a pointer to a boolean value, and indicate whether |value|
101 // is changed or not (probably dropped properties or items). Be sure to set
102 // the bool that |changed| pointed to to false before calling Normalize().
103 // |changed| can be NULL and in that case no boolean will be set.
104 // This function will also take the ownership of dropped base::Value and
105 // destroy them.
94 bool Normalize(base::Value* value, 106 bool Normalize(base::Value* value,
95 SchemaOnErrorStrategy strategy, 107 SchemaOnErrorStrategy strategy,
96 std::string* error_path, 108 std::string* error_path,
97 std::string* error) const; 109 std::string* error,
110 bool* changed) const;
98 111
99 // Used to iterate over the known properties of TYPE_DICTIONARY schemas. 112 // Used to iterate over the known properties of TYPE_DICTIONARY schemas.
100 class POLICY_EXPORT Iterator { 113 class POLICY_EXPORT Iterator {
101 public: 114 public:
102 Iterator(const scoped_refptr<const InternalStorage>& storage, 115 Iterator(const scoped_refptr<const InternalStorage>& storage,
103 const internal::PropertiesNode* node); 116 const internal::PropertiesNode* node);
104 Iterator(const Iterator& iterator); 117 Iterator(const Iterator& iterator);
105 ~Iterator(); 118 ~Iterator();
106 119
107 Iterator& operator=(const Iterator& iterator); 120 Iterator& operator=(const Iterator& iterator);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 bool ValidateIntegerRestriction(int index, int value) const; 170 bool ValidateIntegerRestriction(int index, int value) const;
158 bool ValidateStringRestriction(int index, const char* str) const; 171 bool ValidateStringRestriction(int index, const char* str) const;
159 172
160 scoped_refptr<const InternalStorage> storage_; 173 scoped_refptr<const InternalStorage> storage_;
161 const internal::SchemaNode* node_; 174 const internal::SchemaNode* node_;
162 }; 175 };
163 176
164 } // namespace policy 177 } // namespace policy
165 178
166 #endif // COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_ 179 #endif // COMPONENTS_POLICY_CORE_COMMON_SCHEMA_H_
OLDNEW
« no previous file with comments | « components/policy/core/browser/configuration_policy_handler.cc ('k') | components/policy/core/common/schema.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698