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

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: win build 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
« no previous file with comments | « components/policy/core/browser/configuration_policy_handler.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..13bfdcc56f11a5344a8e48c5f6b1be55650a4d46 100644
--- a/extensions/common/api/declarative/declarative_manifest_data.cc
+++ b/extensions/common/api/declarative/declarative_manifest_data.cc
@@ -7,49 +7,33 @@
#include <stddef.h>
#include "base/macros.h"
+#include "base/strings/string_piece.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "extensions/common/manifest_constants.h"
-using base::UTF8ToUTF16;
-using base::StringPrintf;
-
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) {}
// Appends a literal string |error|.
- void Append(const char* error) {
- if (error_->length())
- error_->append(UTF8ToUTF16("; "));
- error_->append(UTF8ToUTF16(error));
+ void Append(base::StringPiece error) {
+ if (!error_->empty())
+ error_->append(base::ASCIIToUTF16("; "));
+ error_->append(base::UTF8ToUTF16(error));
}
// Appends a string |error| with the first %s replaced by |sub|.
- void Append(const char* error, const char* sub) {
- Append(base::StringPrintf(error, sub).c_str());
+ void Append(base::StringPiece error, base::StringPiece sub) {
+ Append(base::StringPrintf(error.data(), sub.data()));
}
private:
- base::string16* error_;
+ base::string16* const error_;
DISALLOW_COPY_AND_ASSIGN(ErrorBuilder);
};
@@ -61,12 +45,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 +123,15 @@ 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) {
+ for (const auto& element : *list) {
const base::DictionaryValue* dict = nullptr;
- if (!list->GetDictionary(i, &dict)) {
- const base::Value* value = nullptr;
- if (list->Get(i, &value))
- error_builder.Append("expected dictionary, got %s",
- ValueTypeToString(value));
- else
- error_builder.Append("expected dictionary");
+ if (!element->GetAsDictionary(&dict)) {
+ error_builder.Append("expected dictionary, got %s",
+ base::Value::GetTypeName(element->GetType()));
return std::unique_ptr<DeclarativeManifestData>();
}
std::string event;
« no previous file with comments | « components/policy/core/browser/configuration_policy_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698