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

Unified Diff: chrome/common/extensions/simple_feature_provider.cc

Issue 9950046: Implement FeatureProvider for ExtensionAPI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: hate hate hate Created 8 years, 9 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/simple_feature_provider.cc
diff --git a/chrome/common/extensions/simple_feature_provider.cc b/chrome/common/extensions/simple_feature_provider.cc
index 71be30ca90a70d8e587e76455576de800585aa3f..e5acf3652a73dcf5cbb5dc11f27a3a505ef8ec0e 100644
--- a/chrome/common/extensions/simple_feature_provider.cc
+++ b/chrome/common/extensions/simple_feature_provider.cc
@@ -6,27 +6,42 @@
#include "base/json/json_reader.h"
#include "base/lazy_instance.h"
+#include "chrome/common/extensions/manifest_feature.h"
+#include "chrome/common/extensions/permission_feature.h"
#include "grit/common_resources.h"
#include "ui/base/resource/resource_bundle.h"
+namespace extensions {
+
namespace {
const bool kAllowTrailingComma = false;
+template<class FeatureClass>
+Feature* CreateFeature() {
+ return new FeatureClass();
+}
+
struct Static {
Static()
: manifest_features(
- LoadProvider("manifest", IDR_EXTENSION_MANIFEST_FEATURES)),
+ LoadProvider("manifest",
+ &CreateFeature<ManifestFeature>,
+ IDR_EXTENSION_MANIFEST_FEATURES)),
permission_features(
- LoadProvider("permissions", IDR_EXTENSION_PERMISSION_FEATURES)) {
+ LoadProvider("permissions",
+ &CreateFeature<PermissionFeature>,
+ IDR_EXTENSION_PERMISSION_FEATURES)) {
}
- scoped_ptr<extensions::SimpleFeatureProvider> manifest_features;
- scoped_ptr<extensions::SimpleFeatureProvider> permission_features;
+ scoped_ptr<SimpleFeatureProvider> manifest_features;
+ scoped_ptr<SimpleFeatureProvider> permission_features;
private:
- scoped_ptr<extensions::SimpleFeatureProvider> LoadProvider(
- const std::string& debug_string, int resource_id) {
+ scoped_ptr<SimpleFeatureProvider> LoadProvider(
+ const std::string& debug_string,
+ SimpleFeatureProvider::FeatureFactory factory,
+ int resource_id) {
std::string manifest_features =
ResourceBundle::GetSharedInstance().GetRawDataResource(
resource_id).as_string();
@@ -39,8 +54,8 @@ struct Static {
CHECK(value->IsType(Value::TYPE_DICTIONARY)) << debug_string;
scoped_ptr<DictionaryValue> dictionary_value(
static_cast<DictionaryValue*>(value));
- return scoped_ptr<extensions::SimpleFeatureProvider>(
- new extensions::SimpleFeatureProvider(dictionary_value.Pass()));
+ return scoped_ptr<SimpleFeatureProvider>(
+ new SimpleFeatureProvider(dictionary_value.Pass(), factory));
}
};
@@ -48,11 +63,11 @@ base::LazyInstance<Static> g_static = LAZY_INSTANCE_INITIALIZER;
} // namespace
-namespace extensions {
-
-SimpleFeatureProvider::SimpleFeatureProvider(
- scoped_ptr<DictionaryValue> root)
- : root_(root.release()) {
+SimpleFeatureProvider::SimpleFeatureProvider(scoped_ptr<DictionaryValue> root,
+ FeatureFactory factory)
+ : root_(root.release()),
+ factory_(factory ? factory :
+ static_cast<FeatureFactory>(&CreateFeature<Feature>)) {
}
SimpleFeatureProvider::~SimpleFeatureProvider() {
@@ -77,21 +92,18 @@ std::set<std::string> SimpleFeatureProvider::GetAllFeatureNames() const {
return result;
}
-scoped_ptr<Feature> SimpleFeatureProvider::GetFeature(
- const std::string& name) const {
- scoped_ptr<Feature> feature;
-
+scoped_ptr<Feature> SimpleFeatureProvider::GetFeature(const std::string& name) {
DictionaryValue* description = NULL;
- if (root_->GetDictionary(name, &description))
- feature = Feature::Parse(description);
-
- if (!feature.get()) {
- // Have to use DLOG here because this happens in a lot of unit tests that
- // use ancient compiled crx files with unknown keys.
- DLOG(ERROR) << name;
+ if (!root_->GetDictionary(name, &description)) {
+ LOG(ERROR) << name << ": Definition not found.";
return scoped_ptr<Feature>();
}
+ scoped_ptr<Feature> feature(new Feature());
+ feature.reset((*factory_)());
+ feature->set_name(name);
+ feature->Parse(description);
+
if (feature->extension_types()->empty()) {
LOG(ERROR) << name << ": Simple features must specify atleast one value "
<< "for extension_types.";
« no previous file with comments | « chrome/common/extensions/simple_feature_provider.h ('k') | chrome/common/extensions/simple_feature_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698