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