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

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 SchemaTest.ValidSchema 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
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..8e484c1a353ee1976ad7309d59a4053caa4af5cb 100644
--- a/components/policy/core/common/schema.cc
+++ b/components/policy/core/common/schema.cc
@@ -126,6 +126,10 @@ class Schema::InternalStorage
return schema_data_.string_enums + index;
}
+ bool ValidateIntegerRestriction(int index, int value) const;
+
+ bool ValidateStringRestriction(int index, const char *str) const;
Joao da Silva 2014/01/20 20:22:18 These should be private methods of Schema::, not o
binjin 2014/01/21 16:12:07 Done.
+
private:
friend class base::RefCountedThreadSafe<InternalStorage>;
@@ -275,6 +279,34 @@ Schema::InternalStorage::ParseSchema(const base::DictionaryValue& schema,
return storage;
}
+bool Schema::InternalStorage::ValidateIntegerRestriction(
+ int index, int value) const {
+ const RestrictionNode* rnode = 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 (*int_enums(i) == value)
+ return true;
+ }
+ return false;
+ }
+}
+
+bool Schema::InternalStorage::ValidateStringRestriction(
+ int index, const char *str) const {
+ const RestrictionNode* rnode = restriction(index);
+ for (int i = rnode->enumeration_restriction.offset_begin;
+ i < rnode->enumeration_restriction.offset_end; i++) {
+ if (strcmp(*string_enums(i), str) == 0)
+ return true;
+ }
+ return false;
+}
+
// static
void Schema::InternalStorage::DetermineStorageSizes(
const base::DictionaryValue& schema,
@@ -620,6 +652,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 +666,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 ||
+ storage_->ValidateIntegerRestriction(node_->extra, int_value);
+ } else if (value.GetAsString(&str_value)) {
+ return node_->extra == kInvalid ||
+ storage_->ValidateStringRestriction(node_->extra, str_value.c_str());
}
return true;
« no previous file with comments | « no previous file | components/policy/core/common/schema_unittest.cc » ('j') | components/policy/core/common/schema_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698