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

Unified Diff: extensions/common/api/declarative/declarative_manifest_data.cc

Issue 2151793002: Add base::Value::GetTypeName(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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: extensions/common/api/declarative/declarative_manifest_data.cc
diff --git a/extensions/common/api/declarative/declarative_manifest_data.cc b/extensions/common/api/declarative/declarative_manifest_data.cc
index 97bc5ebca369466171dc955444cddd31c4990215..cdea2f219d8760419ae7b68230034af51ec2f29e 100644
--- a/extensions/common/api/declarative/declarative_manifest_data.cc
+++ b/extensions/common/api/declarative/declarative_manifest_data.cc
@@ -18,20 +18,6 @@ namespace extensions {
namespace {
-const char* ValueTypeToString(const base::Value* value) {
- const base::Value::Type type = value->GetType();
- static const char* strings[] = {"null",
- "boolean",
- "integer",
- "double",
- "string",
- "binary",
- "dictionary",
- "list"};
- CHECK(static_cast<size_t>(type) < arraysize(strings));
- return strings[type];
-}
-
class ErrorBuilder {
public:
explicit ErrorBuilder(base::string16* error) : error_(error) {}
@@ -61,12 +47,12 @@ class ErrorBuilder {
bool ConvertManifestRule(const linked_ptr<DeclarativeManifestData::Rule>& rule,
ErrorBuilder* error_builder) {
auto convert_list =
- [error_builder](std::vector<std::unique_ptr<base::Value>>& list) {
+ [error_builder](const std::vector<std::unique_ptr<base::Value>>& list) {
for (const std::unique_ptr<base::Value>& value : list) {
base::DictionaryValue* dictionary = nullptr;
if (!value->GetAsDictionary(&dictionary)) {
error_builder->Append("expected dictionary, got %s",
- ValueTypeToString(value.get()));
+ base::Value::GetTypeName(value->GetType()));
return false;
}
std::string type;
@@ -139,19 +125,20 @@ std::unique_ptr<DeclarativeManifestData> DeclarativeManifestData::FromValue(
const base::ListValue* list = nullptr;
if (!value.GetAsList(&list)) {
error_builder.Append("'event_rules' expected list, got %s",
- ValueTypeToString(&value));
+ base::Value::GetTypeName(value.GetType()));
return std::unique_ptr<DeclarativeManifestData>();
}
for (size_t i = 0; i < list->GetSize(); ++i) {
const base::DictionaryValue* dict = nullptr;
if (!list->GetDictionary(i, &dict)) {
pneubeck (no reviews) 2016/07/14 18:51:37 this whole block is rather confusing. maybe change
Lei Zhang 2016/07/15 01:27:18 Sure. You are absolutely right, the else case can'
- const base::Value* value = nullptr;
- if (list->Get(i, &value))
+ const base::Value* dict_value = nullptr;
+ if (list->Get(i, &dict_value)) {
error_builder.Append("expected dictionary, got %s",
- ValueTypeToString(value));
- else
+ base::Value::GetTypeName(dict_value->GetType()));
+ } else {
error_builder.Append("expected dictionary");
+ }
return std::unique_ptr<DeclarativeManifestData>();
}
std::string event;

Powered by Google App Engine
This is Rietveld 408576698