| OLD | NEW |
| 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 27 matching lines...) Expand all Loading... |
| 38 const char* kChildKinds[] = { | 38 const char* kChildKinds[] = { |
| 39 "functions", | 39 "functions", |
| 40 "events" | 40 "events" |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 base::StringPiece ReadFromResource(int resource_id) { | 43 base::StringPiece ReadFromResource(int resource_id) { |
| 44 return ResourceBundle::GetSharedInstance().GetRawDataResource( | 44 return ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 45 resource_id); | 45 resource_id); |
| 46 } | 46 } |
| 47 | 47 |
| 48 scoped_ptr<base::ListValue> LoadSchemaList(const std::string& name, | 48 std::unique_ptr<base::ListValue> LoadSchemaList( |
| 49 const base::StringPiece& schema) { | 49 const std::string& name, |
| 50 const base::StringPiece& schema) { |
| 50 std::string error_message; | 51 std::string error_message; |
| 51 scoped_ptr<base::Value> result( | 52 std::unique_ptr<base::Value> result(base::JSONReader::ReadAndReturnError( |
| 52 base::JSONReader::ReadAndReturnError( | 53 schema, |
| 53 schema, | 54 base::JSON_PARSE_RFC | base::JSON_DETACHABLE_CHILDREN, // options |
| 54 base::JSON_PARSE_RFC | base::JSON_DETACHABLE_CHILDREN, // options | 55 NULL, // error code |
| 55 NULL, // error code | 56 &error_message)); |
| 56 &error_message)); | |
| 57 | 57 |
| 58 // Tracking down http://crbug.com/121424 | 58 // Tracking down http://crbug.com/121424 |
| 59 char buf[128]; | 59 char buf[128]; |
| 60 base::snprintf(buf, arraysize(buf), "%s: (%d) '%s'", | 60 base::snprintf(buf, arraysize(buf), "%s: (%d) '%s'", |
| 61 name.c_str(), | 61 name.c_str(), |
| 62 result.get() ? result->GetType() : -1, | 62 result.get() ? result->GetType() : -1, |
| 63 error_message.c_str()); | 63 error_message.c_str()); |
| 64 | 64 |
| 65 CHECK(result.get()) << error_message << " for schema " << schema; | 65 CHECK(result.get()) << error_message << " for schema " << schema; |
| 66 CHECK(result->IsType(base::Value::TYPE_LIST)) << " for schema " << schema; | 66 CHECK(result->IsType(base::Value::TYPE_LIST)) << " for schema " << schema; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 95 return child_node; | 95 return child_node; |
| 96 } | 96 } |
| 97 | 97 |
| 98 return NULL; | 98 return NULL; |
| 99 } | 99 } |
| 100 | 100 |
| 101 struct Static { | 101 struct Static { |
| 102 Static() | 102 Static() |
| 103 : api(ExtensionAPI::CreateWithDefaultConfiguration()) { | 103 : api(ExtensionAPI::CreateWithDefaultConfiguration()) { |
| 104 } | 104 } |
| 105 scoped_ptr<ExtensionAPI> api; | 105 std::unique_ptr<ExtensionAPI> api; |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 base::LazyInstance<Static> g_lazy_instance = LAZY_INSTANCE_INITIALIZER; | 108 base::LazyInstance<Static> g_lazy_instance = LAZY_INSTANCE_INITIALIZER; |
| 109 | 109 |
| 110 // May override |g_lazy_instance| for a test. | 110 // May override |g_lazy_instance| for a test. |
| 111 ExtensionAPI* g_shared_instance_for_test = NULL; | 111 ExtensionAPI* g_shared_instance_for_test = NULL; |
| 112 | 112 |
| 113 // If it exists and does not already specify a namespace, then the value stored | 113 // If it exists and does not already specify a namespace, then the value stored |
| 114 // with key |key| in |schema| will be updated to |schema_namespace| + "." + | 114 // with key |key| in |schema| will be updated to |schema_namespace| + "." + |
| 115 // |schema[key]|. | 115 // |schema[key]|. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 : original_api_(g_shared_instance_for_test) { | 206 : original_api_(g_shared_instance_for_test) { |
| 207 g_shared_instance_for_test = testing_api; | 207 g_shared_instance_for_test = testing_api; |
| 208 } | 208 } |
| 209 | 209 |
| 210 ExtensionAPI::OverrideSharedInstanceForTest::~OverrideSharedInstanceForTest() { | 210 ExtensionAPI::OverrideSharedInstanceForTest::~OverrideSharedInstanceForTest() { |
| 211 g_shared_instance_for_test = original_api_; | 211 g_shared_instance_for_test = original_api_; |
| 212 } | 212 } |
| 213 | 213 |
| 214 void ExtensionAPI::LoadSchema(const std::string& name, | 214 void ExtensionAPI::LoadSchema(const std::string& name, |
| 215 const base::StringPiece& schema) { | 215 const base::StringPiece& schema) { |
| 216 scoped_ptr<base::ListValue> schema_list(LoadSchemaList(name, schema)); | 216 std::unique_ptr<base::ListValue> schema_list(LoadSchemaList(name, schema)); |
| 217 std::string schema_namespace; | 217 std::string schema_namespace; |
| 218 extensions::ExtensionsClient* extensions_client = | 218 extensions::ExtensionsClient* extensions_client = |
| 219 extensions::ExtensionsClient::Get(); | 219 extensions::ExtensionsClient::Get(); |
| 220 DCHECK(extensions_client); | 220 DCHECK(extensions_client); |
| 221 while (!schema_list->empty()) { | 221 while (!schema_list->empty()) { |
| 222 base::DictionaryValue* schema = NULL; | 222 base::DictionaryValue* schema = NULL; |
| 223 { | 223 { |
| 224 scoped_ptr<base::Value> value; | 224 std::unique_ptr<base::Value> value; |
| 225 schema_list->Remove(schema_list->GetSize() - 1, &value); | 225 schema_list->Remove(schema_list->GetSize() - 1, &value); |
| 226 CHECK(value.release()->GetAsDictionary(&schema)); | 226 CHECK(value.release()->GetAsDictionary(&schema)); |
| 227 } | 227 } |
| 228 | 228 |
| 229 CHECK(schema->GetString("namespace", &schema_namespace)); | 229 CHECK(schema->GetString("namespace", &schema_namespace)); |
| 230 PrefixWithNamespace(schema_namespace, schema); | 230 PrefixWithNamespace(schema_namespace, schema); |
| 231 schemas_[schema_namespace] = make_linked_ptr(schema); | 231 schemas_[schema_namespace] = make_linked_ptr(schema); |
| 232 if (!extensions_client->IsAPISchemaGenerated(schema_namespace)) | 232 if (!extensions_client->IsAPISchemaGenerated(schema_namespace)) |
| 233 CHECK_EQ(1u, unloaded_schemas_.erase(schema_namespace)); | 233 CHECK_EQ(1u, unloaded_schemas_.erase(schema_namespace)); |
| 234 } | 234 } |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 break; | 388 break; |
| 389 | 389 |
| 390 api_name_candidate = api_name_candidate.substr(0, last_dot_index); | 390 api_name_candidate = api_name_candidate.substr(0, last_dot_index); |
| 391 } | 391 } |
| 392 | 392 |
| 393 *child_name = ""; | 393 *child_name = ""; |
| 394 return std::string(); | 394 return std::string(); |
| 395 } | 395 } |
| 396 | 396 |
| 397 } // namespace extensions | 397 } // namespace extensions |
| OLD | NEW |