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

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: optimize and "parent" property 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..2e020294ede5722e41cf7716bfbba70a91a7c62c 100644
--- a/chrome/common/extensions/features/base_feature_provider.cc
+++ b/chrome/common/extensions/features/base_feature_provider.cc
@@ -36,10 +36,14 @@ class LazyFeatureProvider : public FeatureProvider {
return GetBaseFeatureProvider()->GetFeature(name);
}
- virtual std::set<std::string> GetAllFeatureNames() OVERRIDE {
+ virtual std::vector<std::string> GetAllFeatureNames() OVERRIDE {
return GetBaseFeatureProvider()->GetAllFeatureNames();
}
+ virtual std::vector<std::string> GetAllTopLevelFeatureNames() OVERRIDE {
+ return GetBaseFeatureProvider()->GetAllTopLevelFeatureNames();
+ }
+
private:
BaseFeatureProvider* GetBaseFeatureProvider() {
if (!features_)
@@ -115,6 +119,26 @@ bool ParseFeature(const DictionaryValue* value,
return error.empty();
}
+bool ParseFeature(const DictionaryValue* value,
+ SimpleFeature* feature) {
+ std::string error = feature->Parse(value);
+ if (!error.empty())
+ LOG(ERROR) << error;
+ return error.empty();
+}
+
+bool MaybeParseParentFeature(const DictionaryValue& root,
+ const DictionaryValue* feature_dict,
+ SimpleFeature* feature) {
+ std::string parent;
+ const DictionaryValue* value;
+ if (!feature_dict->GetString("parent", &parent))
+ return true;
+ if (!root.GetDictionary(parent, &value))
+ return false;
+ return ParseFeature(value, feature);
+}
+
} // namespace
BaseFeatureProvider::BaseFeatureProvider(const DictionaryValue& root,
@@ -125,9 +149,11 @@ 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()),
- iter.key(),
- feature.get()))
+ const DictionaryValue* feature_dict =
+ static_cast<const DictionaryValue*>(&iter.value());
not at google - send to devlin 2013/05/23 00:09:40 this could be a bit more straightforward by changi
cduvall 2013/05/24 03:13:49 Done.
+ if (!MaybeParseParentFeature(root, feature_dict, feature.get()))
+ continue;
+ if (!ParseFeature(feature_dict, iter.key(), feature.get()))
continue;
features_[iter.key()] = feature;
@@ -147,10 +173,12 @@ BaseFeatureProvider::BaseFeatureProvider(const DictionaryValue& root,
continue;
}
+ const DictionaryValue* feature_dict =
+ static_cast<const DictionaryValue*>(*list_iter);
scoped_ptr<SimpleFeature> feature((*factory_)());
- if (!ParseFeature(static_cast<const DictionaryValue*>(*list_iter),
- iter.key(),
- feature.get()))
+ if (!MaybeParseParentFeature(root, feature_dict, feature.get()))
+ continue;
+ if (!ParseFeature(feature_dict, iter.key(), feature.get()))
continue;
features->push_back(feature.release());
@@ -176,11 +204,21 @@ FeatureProvider* BaseFeatureProvider::GetByName(
return g_static.Get().LazyGetFeatures(name);
}
-std::set<std::string> BaseFeatureProvider::GetAllFeatureNames() {
- std::set<std::string> result;
+std::vector<std::string> BaseFeatureProvider::GetAllTopLevelFeatureNames() {
+ std::vector<std::string> result;
+ for (FeatureMap::const_iterator iter = features_.begin();
+ iter != features_.end(); ++iter) {
+ if (!iter->second->HasParent())
+ result.push_back(iter->first);
+ }
+ return result;
+}
+
+std::vector<std::string> BaseFeatureProvider::GetAllFeatureNames() {
+ std::vector<std::string> result;
for (FeatureMap::const_iterator iter = features_.begin();
iter != features_.end(); ++iter) {
- result.insert(iter->first);
+ result.push_back(iter->first);
}
return result;
}

Powered by Google App Engine
This is Rietveld 408576698