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

Unified Diff: chrome/common/extensions/features/base_feature_provider.cc

Issue 12255041: Extension BaseFeatureProvider minor cleanups. Don't crash in release mode if we failed to parse a p… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: kalman@ comments Created 7 years, 10 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 | « chrome/common/extensions/extension.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/features/base_feature_provider.cc
diff --git a/chrome/common/extensions/features/base_feature_provider.cc b/chrome/common/extensions/features/base_feature_provider.cc
index d42cb50acc90375e67930af3aeeb64b086de1bd1..44cc4544a9388b45f275856a9c533fba8820bc06 100644
--- a/chrome/common/extensions/features/base_feature_provider.cc
+++ b/chrome/common/extensions/features/base_feature_provider.cc
@@ -41,42 +41,46 @@ struct Static {
const std::string& debug_string,
BaseFeatureProvider::FeatureFactory factory,
int resource_id) {
- std::string manifest_features =
+ const std::string& features_file =
ResourceBundle::GetSharedInstance().GetRawDataResource(
resource_id).as_string();
int error_code = 0;
std::string error_message;
- Value* value = base::JSONReader::ReadAndReturnError(
- manifest_features, base::JSON_PARSE_RFC,
- &error_code, &error_message);
- CHECK(value) << "Could not load features: " << debug_string << " "
- << error_message;
- CHECK(value->IsType(Value::TYPE_DICTIONARY)) << debug_string;
- scoped_ptr<DictionaryValue> dictionary_value(
- static_cast<DictionaryValue*>(value));
- return scoped_ptr<BaseFeatureProvider>(
- new BaseFeatureProvider(*dictionary_value, factory));
+ scoped_ptr<Value> value(base::JSONReader::ReadAndReturnError(
+ features_file, base::JSON_PARSE_RFC,
+ &error_code, &error_message));
+ DCHECK(value) << "Could not load features: " << debug_string << " "
+ << error_message;
+ scoped_ptr<DictionaryValue> value_as_dict;
+ if (value) {
+ CHECK(value->IsType(Value::TYPE_DICTIONARY)) << debug_string;
+ value_as_dict.reset(static_cast<DictionaryValue*>(value.release()));
+ } else {
+ // http://crbug.com/176381
+ value_as_dict.reset(new DictionaryValue());
+ }
+ return make_scoped_ptr(new BaseFeatureProvider(*value_as_dict, factory));
}
};
bool ParseFeature(const DictionaryValue* value,
const std::string& name,
SimpleFeature* feature) {
- feature->set_name(name);
- feature->Parse(value);
+ feature->set_name(name);
+ feature->Parse(value);
- if (feature->extension_types()->empty()) {
- LOG(ERROR) << name << ": Simple features must specify at least one "
- << "value for extension_types.";
- return false;
- }
+ if (feature->extension_types()->empty()) {
+ LOG(ERROR) << name << ": Simple features must specify at least one "
+ << "value for extension_types.";
+ return false;
+ }
- if (!feature->GetContexts()->empty()) {
- LOG(ERROR) << name << ": Simple features do not support contexts.";
- return false;
- }
+ if (!feature->GetContexts()->empty()) {
+ LOG(ERROR) << name << ": Simple features do not support contexts.";
+ return false;
+ }
- return true;
+ return true;
}
base::LazyInstance<Static> g_static = LAZY_INSTANCE_INITIALIZER;
@@ -84,7 +88,7 @@ base::LazyInstance<Static> g_static = LAZY_INSTANCE_INITIALIZER;
} // namespace
BaseFeatureProvider::BaseFeatureProvider(const DictionaryValue& root,
- FeatureFactory factory)
+ FeatureFactory factory)
: factory_(factory ? factory :
static_cast<FeatureFactory>(&CreateFeature<SimpleFeature>)) {
for (DictionaryValue::Iterator iter(root); iter.HasNext(); iter.Advance()) {
« no previous file with comments | « chrome/common/extensions/extension.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698