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

Unified Diff: components/policy/core/common/schema.h

Issue 134153005: Add strictness to Schema::Validate() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@expand-policy-schema-2
Patch Set: minor fixes Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/policy/core/common/schema.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/policy/core/common/schema.h
diff --git a/components/policy/core/common/schema.h b/components/policy/core/common/schema.h
index e4190fbde4a65b4c0b8c0a0de5ebc6a30142d8cd..169fff5bc3651459c653ecdf340ac9e677d28fbb 100644
--- a/components/policy/core/common/schema.h
+++ b/components/policy/core/common/schema.h
@@ -22,6 +22,26 @@ struct POLICY_EXPORT PropertiesNode;
} // namespace internal
+// Option flags passed to Schema::Validate() and Schema::Normalize(), describing
+// the strategy to handle unknown properties or invalid values for dict type.
+// Note that in Schema::Normalize() allowed errors will be dropped and thus
+// ignored.
+enum SchemaOnErrorStrategy {
+ // No errors will be allowed.
+ SCHEMA_STRICT = 0,
+ // Unknown properties in the top-level dictionary will be ignored.
+ SCHEMA_ALLOW_UNKNOWN_TOPLEVEL,
+ // Unknown properties in any dictionary will be ignored.
+ SCHEMA_ALLOW_UNKNOWN,
+ // Mismatched values will be ignored at the toplevel.
+ SCHEMA_ALLOW_INVALID_TOPLEVEL,
+ // Mismatched values will be ignored at the top-level value.
+ // Unknown properties in any dictionary will be ignored.
+ SCHEMA_ALLOW_INVALID_TOPLEVEL_AND_ALLOW_UNKNOWN,
+ // Mismatched values will be ignored.
+ SCHEMA_ALLOW_INVALID,
+};
+
// Describes the expected type of one policy. Also recursively describes the
// types of inner elements, for structured types.
// Objects of this class refer to external, immutable data and are cheap to
@@ -57,8 +77,21 @@ class POLICY_EXPORT Schema {
base::Value::Type type() const;
- // Returns true if |value| conforms to this Schema.
- bool Validate(const base::Value& value) const;
+ // Validate |value| against current schema, |strategy| is the strategy to
+ // handle unknown properties or invalid values. Allowed errors will be
+ // ignored. If |value| don't conform the schema, false will be returned and
+ // |error| will contain the detailed reason.
+ bool Validate(const base::Value& value,
+ SchemaOnErrorStrategy strategy,
+ std::string* error) const;
+
+ // Validate |value| against current schema, |strategy| is the strategy to
+ // handle unknown properties or invalid values. Allowed errors will be
+ // dropped in place. If |value| don't conform the schema, false will be
+ // returned and |error| will contain the detailed message.
+ bool Normalize(base::Value* value,
+ SchemaOnErrorStrategy strategy,
+ std::string* error) const;
// Used to iterate over the known properties of TYPE_DICTIONARY schemas.
class POLICY_EXPORT Iterator {
« no previous file with comments | « no previous file | components/policy/core/common/schema.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698