Chromium Code Reviews| Index: extensions/common/extension_api.cc |
| diff --git a/extensions/common/extension_api.cc b/extensions/common/extension_api.cc |
| index 4b49a83f8e5f70492f0aee34901739c1b85f1ce7..3425463d0f4ccbe538580db5832d21bd376bee21 100644 |
| --- a/extensions/common/extension_api.cc |
| +++ b/extensions/common/extension_api.cc |
| @@ -55,15 +55,24 @@ std::unique_ptr<base::ListValue> LoadSchemaList( |
| NULL, // error code |
| &error_message)); |
| - // Tracking down http://crbug.com/121424 |
| - char buf[128]; |
| - base::snprintf(buf, arraysize(buf), "%s: (%d) '%s'", |
| - name.c_str(), |
| - result.get() ? result->GetType() : -1, |
| - error_message.c_str()); |
| - |
| - CHECK(result.get()) << error_message << " for schema " << schema; |
| - CHECK(result->IsType(base::Value::TYPE_LIST)) << " for schema " << schema; |
| +#if DCHECK_IS_ON() |
| + // |schema| comes from JSON hard-coded to the Chrome binary, so in principle |
| + // failure to parse indicates we generated corrupted JSON, but in practice |
| + // corruption of the Chrome binary (e.g. disk errors) can also break it. |
| + // See http://crbug.com/121424. |
| + if (!result || !result->IsType(base::Value::TYPE_LIST)) { |
| + char buf[128]; |
| + base::snprintf(buf, arraysize(buf), "%s: (%d) '%s'", |
| + name.c_str(), |
| + result.get() ? result->GetType() : -1, |
| + error_message.c_str()); |
| + |
| + DCHECK(result); |
| + DCHECK(result->IsType(base::Value::TYPE_LIST)); |
| + } |
| +#endif // DCHECK_IS_ON() |
| + |
| + // From() returns null if pass a null or non-list value. |
|
Devlin
2016/08/19 15:02:32
nit: "passed"
Wez
2016/08/19 18:22:15
Done.
|
| return base::ListValue::From(std::move(result)); |
| } |
| @@ -214,6 +223,9 @@ ExtensionAPI::OverrideSharedInstanceForTest::~OverrideSharedInstanceForTest() { |
| void ExtensionAPI::LoadSchema(const std::string& name, |
| const base::StringPiece& schema) { |
| std::unique_ptr<base::ListValue> schema_list(LoadSchemaList(name, schema)); |
| + if (!schema_list) |
| + return; |
| + |
| std::string schema_namespace; |
| extensions::ExtensionsClient* extensions_client = |
| extensions::ExtensionsClient::Get(); |
| @@ -331,7 +343,12 @@ const base::DictionaryValue* ExtensionAPI::GetSchema( |
| } |
| maybe_schema = schemas_.find(api_name); |
| - CHECK(schemas_.end() != maybe_schema); |
| + // If the schema failed to load then return null for it, rather than |
| + // crashing, so that the browser can be notified of the problem. |
| + // See http://crbug.com/121424. |
| + if (schemas_.end() == maybe_schema) |
| + return NULL; |
| + |
| result = maybe_schema->second.get(); |
| } |
| @@ -341,6 +358,17 @@ const base::DictionaryValue* ExtensionAPI::GetSchema( |
| return result; |
| } |
| +void ExtensionAPI::LoadSchemaListOrDie(const std::string& api) { |
| + std::string api_name = GetAPINameFromFullName(api, NULL); |
|
Devlin
2016/08/19 15:02:32
nullptr
Wez
2016/08/19 18:22:15
Sticking with NULL for consistency with the rest o
Devlin
2016/08/19 18:40:57
(Not blocking this change - feel free to ignore) I
|
| + extensions::ExtensionsClient* extensions_client = |
| + extensions::ExtensionsClient::Get(); |
| + // IsAPISchemaGenerated() will return false for invalid |api| names. |
| + if (!extensions_client->IsAPISchemaGenerated(api)) |
|
Devlin
2016/08/19 15:02:32
We aren't checking the unloaded schemas here. Tha
Wez
2016/08/19 18:22:15
Ah, OK, so we need to check for un-generated (why
Devlin
2016/08/19 18:40:57
re unloaded, no idea - the whole concept doesn't m
|
| + return; |
| + |
| + CHECK(LoadSchemaList(api_name, extensions_client->GetAPISchema(api_name))); |
| +} |
| + |
| Feature* ExtensionAPI::GetFeatureDependency(const std::string& full_name) { |
| std::string feature_type; |
| std::string feature_name; |
| @@ -390,7 +418,9 @@ std::string ExtensionAPI::GetAPINameFromFullName(const std::string& full_name, |
| api_name_candidate = api_name_candidate.substr(0, last_dot_index); |
| } |
| - *child_name = ""; |
| + if (child_name) |
| + *child_name = ""; |
| + |
| return std::string(); |
| } |