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

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

Issue 50143010: Added a SchemaMap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@chrome-policy-schema-5-ref-counted-schema
Patch Set: rebase Created 7 years, 1 month 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 | « components/policy/core/common/schema.h ('k') | components/policy/core/common/schema_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/policy/core/common/schema.cc
diff --git a/components/policy/core/common/schema.cc b/components/policy/core/common/schema.cc
index 325ec2a26e11fe5715937ba0d0c57e5931d7b42e..20af5f815f2460f2815a046ce191fa8cf3039380 100644
--- a/components/policy/core/common/schema.cc
+++ b/components/policy/core/common/schema.cc
@@ -299,6 +299,34 @@ Schema Schema::Wrap(const SchemaData* data) {
return Schema(storage, storage->root_node());
}
+bool Schema::Validate(const base::Value& value) const {
+ if (!valid()) {
+ // Schema not found, invalid entry.
+ return false;
+ }
+
+ if (!value.IsType(type()))
+ return false;
+
+ const base::DictionaryValue* dict = NULL;
+ const base::ListValue* list = NULL;
+ if (value.GetAsDictionary(&dict)) {
+ for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd();
+ it.Advance()) {
+ if (!GetProperty(it.key()).Validate(it.value()))
+ return false;
+ }
+ } else if (value.GetAsList(&list)) {
+ for (base::ListValue::const_iterator it = list->begin();
+ it != list->end(); ++it) {
+ if (!*it || !GetItems().Validate(**it))
+ return false;
+ }
+ }
+
+ return true;
+}
+
// static
Schema Schema::Parse(const std::string& content, std::string* error) {
// Validate as a generic JSON schema.
« no previous file with comments | « components/policy/core/common/schema.h ('k') | components/policy/core/common/schema_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698