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

Side by Side Diff: extensions/common/extension_api.cc

Issue 2275063002: [Extensions] Don't generate a list for each generated schema (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: woot Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | tools/json_schema_compiler/cpp_bundle_generator.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/common/extension_api.h" 5 #include "extensions/common/extension_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
(...skipping 20 matching lines...) Expand all
31 31
32 namespace extensions { 32 namespace extensions {
33 33
34 namespace { 34 namespace {
35 35
36 const char* kChildKinds[] = { 36 const char* kChildKinds[] = {
37 "functions", 37 "functions",
38 "events" 38 "events"
39 }; 39 };
40 40
41 std::unique_ptr<base::ListValue> LoadSchemaList( 41 std::unique_ptr<base::DictionaryValue> LoadSchemaDictionary(
42 const std::string& name, 42 const std::string& name,
43 const base::StringPiece& schema) { 43 const base::StringPiece& schema) {
44 std::string error_message; 44 std::string error_message;
45 std::unique_ptr<base::Value> result(base::JSONReader::ReadAndReturnError( 45 std::unique_ptr<base::Value> result(base::JSONReader::ReadAndReturnError(
46 schema, 46 schema,
47 base::JSON_PARSE_RFC | base::JSON_DETACHABLE_CHILDREN, // options 47 base::JSON_PARSE_RFC | base::JSON_DETACHABLE_CHILDREN, // options
48 NULL, // error code 48 NULL, // error code
49 &error_message)); 49 &error_message));
50 50
51 // Tracking down http://crbug.com/121424 51 // Tracking down http://crbug.com/121424
52 char buf[128]; 52 char buf[128];
53 base::snprintf(buf, arraysize(buf), "%s: (%d) '%s'", 53 base::snprintf(buf, arraysize(buf), "%s: (%d) '%s'",
54 name.c_str(), 54 name.c_str(),
55 result.get() ? result->GetType() : -1, 55 result.get() ? result->GetType() : -1,
56 error_message.c_str()); 56 error_message.c_str());
57 57
58 CHECK(result.get()) << error_message << " for schema " << schema; 58 CHECK(result.get()) << error_message << " for schema " << schema;
59 CHECK(result->IsType(base::Value::TYPE_LIST)) << " for schema " << schema; 59 CHECK(result->IsType(base::Value::TYPE_DICTIONARY)) << " for schema "
60 return base::ListValue::From(std::move(result)); 60 << schema;
61 return base::DictionaryValue::From(std::move(result));
61 } 62 }
62 63
63 const base::DictionaryValue* FindListItem(const base::ListValue* list, 64 const base::DictionaryValue* FindListItem(const base::ListValue* list,
64 const std::string& property_name, 65 const std::string& property_name,
65 const std::string& property_value) { 66 const std::string& property_value) {
66 for (size_t i = 0; i < list->GetSize(); ++i) { 67 for (size_t i = 0; i < list->GetSize(); ++i) {
67 const base::DictionaryValue* item = NULL; 68 const base::DictionaryValue* item = NULL;
68 CHECK(list->GetDictionary(i, &item)) 69 CHECK(list->GetDictionary(i, &item))
69 << property_value << "/" << property_name; 70 << property_value << "/" << property_name;
70 std::string value; 71 std::string value;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 : original_api_(g_shared_instance_for_test) { 140 : original_api_(g_shared_instance_for_test) {
140 g_shared_instance_for_test = testing_api; 141 g_shared_instance_for_test = testing_api;
141 } 142 }
142 143
143 ExtensionAPI::OverrideSharedInstanceForTest::~OverrideSharedInstanceForTest() { 144 ExtensionAPI::OverrideSharedInstanceForTest::~OverrideSharedInstanceForTest() {
144 g_shared_instance_for_test = original_api_; 145 g_shared_instance_for_test = original_api_;
145 } 146 }
146 147
147 void ExtensionAPI::LoadSchema(const std::string& name, 148 void ExtensionAPI::LoadSchema(const std::string& name,
148 const base::StringPiece& schema) { 149 const base::StringPiece& schema) {
149 std::unique_ptr<base::ListValue> schema_list(LoadSchemaList(name, schema)); 150 std::unique_ptr<base::DictionaryValue> schema_dict(
151 LoadSchemaDictionary(name, schema));
150 std::string schema_namespace; 152 std::string schema_namespace;
151 extensions::ExtensionsClient* extensions_client = 153 CHECK(schema_dict->GetString("namespace", &schema_namespace));
152 extensions::ExtensionsClient::Get(); 154 schemas_[schema_namespace] = std::move(schema_dict);
153 DCHECK(extensions_client);
154 while (!schema_list->empty()) {
155 std::unique_ptr<base::DictionaryValue> schema;
156 {
157 std::unique_ptr<base::Value> val;
158 schema_list->Erase(schema_list->begin(), &val);
159 schema = base::DictionaryValue::From(std::move(val));
160 CHECK(schema);
161 }
162 CHECK(schema->GetString("namespace", &schema_namespace));
163 schemas_[schema_namespace] = std::move(schema);
164 }
165 } 155 }
166 156
167 ExtensionAPI::ExtensionAPI() : default_configuration_initialized_(false) { 157 ExtensionAPI::ExtensionAPI() : default_configuration_initialized_(false) {
168 } 158 }
169 159
170 ExtensionAPI::~ExtensionAPI() { 160 ExtensionAPI::~ExtensionAPI() {
171 } 161 }
172 162
173 void ExtensionAPI::InitDefaultConfiguration() { 163 void ExtensionAPI::InitDefaultConfiguration() {
174 const char* names[] = {"api", "manifest", "permission"}; 164 const char* names[] = {"api", "manifest", "permission"};
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 return std::string(); 291 return std::string();
302 } 292 }
303 293
304 bool ExtensionAPI::IsKnownAPI(const std::string& name, 294 bool ExtensionAPI::IsKnownAPI(const std::string& name,
305 ExtensionsClient* client) { 295 ExtensionsClient* client) {
306 return schemas_.find(name) != schemas_.end() || 296 return schemas_.find(name) != schemas_.end() ||
307 client->IsAPISchemaGenerated(name); 297 client->IsAPISchemaGenerated(name);
308 } 298 }
309 299
310 } // namespace extensions 300 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | tools/json_schema_compiler/cpp_bundle_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698