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

Unified Diff: components/json_schema/json_schema_validator.cc

Issue 2539363004: Make base::Value::TYPE a scoped enum. (Closed)
Patch Set: Rebase Created 4 years 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/json_schema/json_schema_validator.cc
diff --git a/components/json_schema/json_schema_validator.cc b/components/json_schema/json_schema_validator.cc
index cf3b3dadac66fc47f3572577bcdcad6656f166e1..695b8c96dc89b59faebc8aa046f058dbb58ef7f9 100644
--- a/components/json_schema/json_schema_validator.cc
+++ b/components/json_schema/json_schema_validator.cc
@@ -79,25 +79,25 @@ bool IsValidSchema(const base::DictionaryValue* dict,
// binary search.
static const ExpectedType kExpectedTypes[] = {
// Note: kRef == "$ref", kSchema == "$schema"
- { schema::kRef, base::Value::TYPE_STRING },
- { schema::kSchema, base::Value::TYPE_STRING },
-
- { schema::kAdditionalProperties, base::Value::TYPE_DICTIONARY },
- { schema::kChoices, base::Value::TYPE_LIST },
- { schema::kDescription, base::Value::TYPE_STRING },
- { schema::kEnum, base::Value::TYPE_LIST },
- { schema::kId, base::Value::TYPE_STRING },
- { schema::kMaxItems, base::Value::TYPE_INTEGER },
- { schema::kMaxLength, base::Value::TYPE_INTEGER },
- { schema::kMaximum, base::Value::TYPE_DOUBLE },
- { schema::kMinItems, base::Value::TYPE_INTEGER },
- { schema::kMinLength, base::Value::TYPE_INTEGER },
- { schema::kMinimum, base::Value::TYPE_DOUBLE },
- { schema::kOptional, base::Value::TYPE_BOOLEAN },
- { schema::kPattern, base::Value::TYPE_STRING },
- { schema::kPatternProperties, base::Value::TYPE_DICTIONARY },
- { schema::kProperties, base::Value::TYPE_DICTIONARY },
- { schema::kTitle, base::Value::TYPE_STRING },
+ { schema::kRef, base::Value::Type::STRING },
+ { schema::kSchema, base::Value::Type::STRING },
+
+ { schema::kAdditionalProperties, base::Value::Type::DICTIONARY },
+ { schema::kChoices, base::Value::Type::LIST },
+ { schema::kDescription, base::Value::Type::STRING },
+ { schema::kEnum, base::Value::Type::LIST },
+ { schema::kId, base::Value::Type::STRING },
+ { schema::kMaxItems, base::Value::Type::INTEGER },
+ { schema::kMaxLength, base::Value::Type::INTEGER },
+ { schema::kMaximum, base::Value::Type::DOUBLE },
+ { schema::kMinItems, base::Value::Type::INTEGER },
+ { schema::kMinLength, base::Value::Type::INTEGER },
+ { schema::kMinimum, base::Value::Type::DOUBLE },
+ { schema::kOptional, base::Value::Type::BOOLEAN },
+ { schema::kPattern, base::Value::Type::STRING },
+ { schema::kPatternProperties, base::Value::Type::DICTIONARY },
+ { schema::kProperties, base::Value::Type::DICTIONARY },
+ { schema::kTitle, base::Value::Type::STRING },
};
bool has_type_or_ref = false;
@@ -109,14 +109,14 @@ bool IsValidSchema(const base::DictionaryValue* dict,
// Validate the "type" attribute, which may be a string or a list.
if (it.key() == schema::kType) {
switch (it.value().GetType()) {
- case base::Value::TYPE_STRING:
+ case base::Value::Type::STRING:
it.value().GetAsString(&string_value);
if (!IsValidType(string_value)) {
*error = "Invalid value for type attribute";
return false;
}
break;
- case base::Value::TYPE_LIST:
+ case base::Value::Type::LIST:
it.value().GetAsList(&list_value);
for (size_t i = 0; i < list_value->GetSize(); ++i) {
if (!list_value->GetString(i, &string_value) ||
@@ -174,16 +174,16 @@ bool IsValidSchema(const base::DictionaryValue* dict,
// Integer can be converted to double.
if (!(it.value().IsType(entry->type) ||
- (it.value().IsType(base::Value::TYPE_INTEGER) &&
- entry->type == base::Value::TYPE_DOUBLE))) {
+ (it.value().IsType(base::Value::Type::INTEGER) &&
+ entry->type == base::Value::Type::DOUBLE))) {
*error = base::StringPrintf("Invalid value for %s attribute",
it.key().c_str());
return false;
}
- // base::Value::TYPE_INTEGER attributes must be >= 0.
+ // base::Value::Type::INTEGER attributes must be >= 0.
// This applies to "minItems", "maxItems", "minLength" and "maxLength".
- if (it.value().IsType(base::Value::TYPE_INTEGER)) {
+ if (it.value().IsType(base::Value::Type::INTEGER)) {
int integer_value;
it.value().GetAsInteger(&integer_value);
if (integer_value < 0) {
@@ -251,11 +251,11 @@ bool IsValidSchema(const base::DictionaryValue* dict,
return false;
}
switch (value->GetType()) {
- case base::Value::TYPE_NULL:
- case base::Value::TYPE_BOOLEAN:
- case base::Value::TYPE_INTEGER:
- case base::Value::TYPE_DOUBLE:
- case base::Value::TYPE_STRING:
+ case base::Value::Type::NONE:
+ case base::Value::Type::BOOLEAN:
+ case base::Value::Type::INTEGER:
+ case base::Value::Type::DOUBLE:
+ case base::Value::Type::STRING:
break;
default:
*error = "Invalid value in enum attribute";
@@ -344,13 +344,13 @@ const char JSONSchemaValidator::kInvalidRegex[] =
// static
std::string JSONSchemaValidator::GetJSONSchemaType(const base::Value* value) {
switch (value->GetType()) {
- case base::Value::TYPE_NULL:
+ case base::Value::Type::NONE:
return schema::kNull;
- case base::Value::TYPE_BOOLEAN:
+ case base::Value::Type::BOOLEAN:
return schema::kBoolean;
- case base::Value::TYPE_INTEGER:
+ case base::Value::Type::INTEGER:
return schema::kInteger;
- case base::Value::TYPE_DOUBLE: {
+ case base::Value::Type::DOUBLE: {
double double_value = 0;
value->GetAsDouble(&double_value);
if (std::abs(double_value) <= std::pow(2.0, DBL_MANT_DIG) &&
@@ -360,11 +360,11 @@ std::string JSONSchemaValidator::GetJSONSchemaType(const base::Value* value) {
return schema::kNumber;
}
}
- case base::Value::TYPE_STRING:
+ case base::Value::Type::STRING:
return schema::kString;
- case base::Value::TYPE_DICTIONARY:
+ case base::Value::Type::DICTIONARY:
return schema::kObject;
- case base::Value::TYPE_LIST:
+ case base::Value::Type::LIST:
return schema::kArray;
default:
NOTREACHED() << "Unexpected value type: " << value->GetType();
@@ -507,8 +507,9 @@ void JSONSchemaValidator::Validate(const base::Value* instance,
ValidateArray(static_cast<const base::ListValue*>(instance),
schema, path);
} else if (type == schema::kString) {
- // Intentionally NOT downcasting to StringValue*. TYPE_STRING only implies
- // GetAsString() can safely be carried out, not that it's a StringValue.
+ // Intentionally NOT downcasting to StringValue*. Type::STRING only
+ // implies GetAsString() can safely be carried out, not that it's a
+ // StringValue.
ValidateString(instance, schema, path);
} else if (type == schema::kNumber || type == schema::kInteger) {
ValidateNumber(instance, schema, path);
@@ -554,17 +555,17 @@ void JSONSchemaValidator::ValidateEnum(const base::Value* instance,
NOTREACHED();
}
switch (choice->GetType()) {
- case base::Value::TYPE_NULL:
- case base::Value::TYPE_BOOLEAN:
- case base::Value::TYPE_STRING:
+ case base::Value::Type::NONE:
+ case base::Value::Type::BOOLEAN:
+ case base::Value::Type::STRING:
if (instance->Equals(choice))
return;
break;
- case base::Value::TYPE_INTEGER:
- case base::Value::TYPE_DOUBLE:
- if (instance->IsType(base::Value::TYPE_INTEGER) ||
- instance->IsType(base::Value::TYPE_DOUBLE)) {
+ case base::Value::Type::INTEGER:
+ case base::Value::Type::DOUBLE:
+ if (instance->IsType(base::Value::Type::INTEGER) ||
+ instance->IsType(base::Value::Type::DOUBLE)) {
if (GetNumberValue(choice) == GetNumberValue(instance))
return;
}
@@ -715,7 +716,7 @@ void JSONSchemaValidator::ValidateTuple(const base::ListValue* instance,
CHECK(tuple_type->GetDictionary(i, &item_schema));
const base::Value* item_value = NULL;
instance->Get(i, &item_value);
- if (item_value && item_value->GetType() != base::Value::TYPE_NULL) {
+ if (item_value && item_value->GetType() != base::Value::Type::NONE) {
Validate(item_value, item_schema, item_path);
} else {
bool is_optional = false;
« no previous file with comments | « components/history/core/browser/web_history_service.cc ('k') | components/json_schema/json_schema_validator_unittest_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698