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; |