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

Unified Diff: chrome/common/json_schema_validator.cc

Issue 6901084: Use new APIs in base/values.h: Value::GetAsNumber and DictionaryValue::GetNumber. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years, 8 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: chrome/common/json_schema_validator.cc
diff --git a/chrome/common/json_schema_validator.cc b/chrome/common/json_schema_validator.cc
index 7da218f825ed68519ccdab7a44c3eb4426d371b3..7b25d45aa1c0f5f0762756d422a96ee41ad6ea65 100644
--- a/chrome/common/json_schema_validator.cc
+++ b/chrome/common/json_schema_validator.cc
@@ -16,30 +16,9 @@ namespace {
double GetNumberValue(Value* value) {
double result = 0;
- if (value->GetAsDouble(&result))
- return result;
-
- int int_result = 0;
- if (value->GetAsInteger(&int_result)) {
- return int_result;
- }
-
- CHECK(false) << "Unexpected value type: " << value->GetType();
- return 0;
-}
-
-bool GetNumberFromDictionary(DictionaryValue* value, const std::string& key,
- double* number) {
- if (value->GetDouble(key, number))
- return true;
-
- int int_value = 0;
- if (value->GetInteger(key, &int_value)) {
- *number = int_value;
- return true;
- }
-
- return false;
+ CHECK(value->GetAsDouble(&result))
+ << "Unexpected value type: " << value->GetType();
+ return result;
}
} // namespace
@@ -459,14 +438,14 @@ void JSONSchemaValidator::ValidateNumber(Value* instance,
// but isnan and isinf aren't defined on Windows.
double minimum = 0;
- if (GetNumberFromDictionary(schema, "minimum", &minimum)) {
+ if (schema->GetDouble("minimum", &minimum)) {
if (value < minimum)
errors_.push_back(Error(path, FormatErrorMessage(
kNumberMinimum, base::DoubleToString(minimum))));
}
double maximum = 0;
- if (GetNumberFromDictionary(schema, "maximum", &maximum)) {
+ if (schema->GetDouble("maximum", &maximum)) {
if (value > maximum)
errors_.push_back(Error(path, FormatErrorMessage(
kNumberMaximum, base::DoubleToString(maximum))));

Powered by Google App Engine
This is Rietveld 408576698