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

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

Issue 15091002: Lazily load API schemas from resource files and convert all APIs to features (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more comments and fixed tests Created 7 years, 7 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
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 285426d147d108f684711b6ef13a51a177ddc7e8..d522b8cb7926adbc35a14e7778056089d3a7319f 100644
--- a/chrome/common/extensions/features/base_feature_provider.cc
+++ b/chrome/common/extensions/features/base_feature_provider.cc
@@ -36,7 +36,7 @@ class LazyFeatureProvider : public FeatureProvider {
return GetBaseFeatureProvider()->GetFeature(name);
}
- virtual std::set<std::string> GetAllFeatureNames() OVERRIDE {
+ virtual const std::vector<std::string>& GetAllFeatureNames() OVERRIDE {
return GetBaseFeatureProvider()->GetAllFeatureNames();
}
@@ -105,11 +105,22 @@ struct Static {
base::LazyInstance<Static> g_static = LAZY_INSTANCE_INITIALIZER;
-bool ParseFeature(const DictionaryValue* value,
+bool ParseFeature(const DictionaryValue& root,
+ const DictionaryValue* value,
const std::string& name,
SimpleFeature* feature) {
+ std::string error;
+ std::string parent_name;
+ if (value->GetString("parent", &parent_name)) {
+ const DictionaryValue* parent = NULL;
not at google - send to devlin 2013/05/30 16:38:52 bleh so sorry about that :(
cduvall 2013/06/12 01:22:19 np, it wasn't that big of a change.
+ CHECK(root.GetDictionaryWithoutPathExpansion(parent_name, &parent));
+ scoped_ptr<DictionaryValue> value_with_parent(parent->DeepCopy());
+ value_with_parent->MergeDictionary(value);
+ error = feature->Parse(value_with_parent.get());
+ } else {
+ error = feature->Parse(value);
+ }
feature->set_name(name);
- std::string error = feature->Parse(value);
if (!error.empty())
LOG(ERROR) << error;
return error.empty();
@@ -125,10 +136,12 @@ BaseFeatureProvider::BaseFeatureProvider(const DictionaryValue& root,
if (iter.value().GetType() == Value::TYPE_DICTIONARY) {
linked_ptr<SimpleFeature> feature((*factory_)());
- if (!ParseFeature(static_cast<const DictionaryValue*>(&iter.value()),
+ if (!ParseFeature(root,
+ static_cast<const DictionaryValue*>(&iter.value()),
iter.key(),
- feature.get()))
+ feature.get())) {
continue;
+ }
features_[iter.key()] = feature;
} else if (iter.value().GetType() == Value::TYPE_LIST) {
@@ -148,10 +161,12 @@ BaseFeatureProvider::BaseFeatureProvider(const DictionaryValue& root,
}
scoped_ptr<SimpleFeature> feature((*factory_)());
- if (!ParseFeature(static_cast<const DictionaryValue*>(*list_iter),
+ if (!ParseFeature(root,
+ static_cast<const DictionaryValue*>(*list_iter),
iter.key(),
- feature.get()))
+ feature.get())) {
continue;
+ }
features->push_back(feature.release());
}
@@ -176,13 +191,14 @@ FeatureProvider* BaseFeatureProvider::GetByName(
return g_static.Get().LazyGetFeatures(name);
}
-std::set<std::string> BaseFeatureProvider::GetAllFeatureNames() {
- std::set<std::string> result;
- for (FeatureMap::const_iterator iter = features_.begin();
- iter != features_.end(); ++iter) {
- result.insert(iter->first);
+const std::vector<std::string>& BaseFeatureProvider::GetAllFeatureNames() {
+ if (feature_names_.empty()) {
+ for (FeatureMap::const_iterator iter = features_.begin();
+ iter != features_.end(); ++iter) {
+ feature_names_.push_back(iter->first);
+ }
}
- return result;
+ return feature_names_;
}
Feature* BaseFeatureProvider::GetFeature(const std::string& name) {

Powered by Google App Engine
This is Rietveld 408576698