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

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

Issue 143413002: Add additional restriction to policy schema internal (part2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@expand-policy-schema
Patch Set: fix comments 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 | « 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 712332261fb28cbd13a8cfd008fb7d08a5c1af04..38627df2634c95aea755e2d1305ed528a35ab10c 100644
--- a/components/policy/core/common/schema.cc
+++ b/components/policy/core/common/schema.cc
@@ -620,6 +620,8 @@ bool Schema::Validate(const base::Value& value) const {
const base::DictionaryValue* dict = NULL;
const base::ListValue* list = NULL;
+ int int_value;
+ std::string str_value;
if (value.GetAsDictionary(&dict)) {
for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd();
it.Advance()) {
@@ -632,6 +634,12 @@ bool Schema::Validate(const base::Value& value) const {
if (!*it || !GetItems().Validate(**it))
return false;
}
+ } else if (value.GetAsInteger(&int_value)) {
+ return node_->extra == kInvalid ||
+ ValidateIntegerRestriction(node_->extra, int_value);
+ } else if (value.GetAsString(&str_value)) {
+ return node_->extra == kInvalid ||
+ ValidateStringRestriction(node_->extra, str_value.c_str());
}
return true;
@@ -723,4 +731,30 @@ Schema Schema::GetItems() const {
return Schema(storage_, storage_->schema(node_->extra));
}
+bool Schema::ValidateIntegerRestriction(int index, int value) const {
+ const RestrictionNode* rnode = storage_->restriction(index);
+ if (rnode->ranged_restriction.min_value <=
+ rnode->ranged_restriction.max_value) {
+ return rnode->ranged_restriction.min_value <= value &&
+ rnode->ranged_restriction.max_value >= value;
+ } else {
+ for (int i = rnode->enumeration_restriction.offset_begin;
+ i < rnode->enumeration_restriction.offset_end; i++) {
+ if (*storage_->int_enums(i) == value)
+ return true;
+ }
+ return false;
+ }
+}
+
+bool Schema::ValidateStringRestriction(int index, const char *str) const {
+ const RestrictionNode* rnode = storage_->restriction(index);
+ for (int i = rnode->enumeration_restriction.offset_begin;
+ i < rnode->enumeration_restriction.offset_end; i++) {
+ if (strcmp(*storage_->string_enums(i), str) == 0)
+ return true;
+ }
+ return false;
+}
+
} // namespace policy
« 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