diff options
author | kalman <kalman@chromium.org> | 2014-12-18 01:40:38 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-18 09:41:05 +0000 |
commit | 38ec48860b67cc8574a0b69cedbd8a0b89acd990 (patch) | |
tree | d009af4ddf2709a4d6506c9d008c7581e34b0e1e /extensions/common/features | |
parent | 1c2a4917f604903f092bb00afefbd0d5223bd2a8 (diff) | |
download | chromium_src-38ec48860b67cc8574a0b69cedbd8a0b89acd990.zip chromium_src-38ec48860b67cc8574a0b69cedbd8a0b89acd990.tar.gz chromium_src-38ec48860b67cc8574a0b69cedbd8a0b89acd990.tar.bz2 |
Add FeatureProvider::GetAPIFeature, FeatureProvider::GetBehaviorFeature, etc as
(further) syntactic sugar to fetching a specific Feature.
R=yoz@chromium.org, benwells@chromium.org
Review URL: https://codereview.chromium.org/806333003
Cr-Commit-Position: refs/heads/master@{#308977}
Diffstat (limited to 'extensions/common/features')
-rw-r--r-- | extensions/common/features/base_feature_provider_unittest.cc | 15 | ||||
-rw-r--r-- | extensions/common/features/feature.cc | 2 | ||||
-rw-r--r-- | extensions/common/features/feature.h | 2 | ||||
-rw-r--r-- | extensions/common/features/feature_provider.cc | 34 | ||||
-rw-r--r-- | extensions/common/features/feature_provider.h | 34 | ||||
-rw-r--r-- | extensions/common/features/simple_feature.h | 6 |
6 files changed, 72 insertions, 21 deletions
diff --git a/extensions/common/features/base_feature_provider_unittest.cc b/extensions/common/features/base_feature_provider_unittest.cc index 974ee76..8f4a3ba 100644 --- a/extensions/common/features/base_feature_provider_unittest.cc +++ b/extensions/common/features/base_feature_provider_unittest.cc @@ -19,13 +19,12 @@ namespace extensions { // Tests that a real manifest feature is available for the correct types of // extensions and apps. TEST(BaseFeatureProviderTest, ManifestFeatureTypes) { - const FeatureProvider* provider = BaseFeatureProvider::GetByName("manifest"); // NOTE: This feature cannot have multiple rules, otherwise it is not a // SimpleFeature. - SimpleFeature* feature = - static_cast<SimpleFeature*>(provider->GetFeature("description")); + const SimpleFeature* feature = static_cast<const SimpleFeature*>( + FeatureProvider::GetManifestFeature("description")); ASSERT_TRUE(feature); - std::set<Manifest::Type>* extension_types = feature->extension_types(); + const std::set<Manifest::Type>* extension_types = feature->extension_types(); EXPECT_EQ(6u, extension_types->size()); EXPECT_EQ(1u, extension_types->count(Manifest::TYPE_EXTENSION)); EXPECT_EQ(1u, extension_types->count(Manifest::TYPE_LEGACY_PACKAGED_APP)); @@ -75,14 +74,12 @@ TEST(BaseFeatureProviderTest, ManifestFeatureAvailability) { // Tests that a real permission feature is available for the correct types of // extensions and apps. TEST(BaseFeatureProviderTest, PermissionFeatureTypes) { - const FeatureProvider* provider = - BaseFeatureProvider::GetByName("permission"); // NOTE: This feature cannot have multiple rules, otherwise it is not a // SimpleFeature. - SimpleFeature* feature = - static_cast<SimpleFeature*>(provider->GetFeature("power")); + const SimpleFeature* feature = static_cast<const SimpleFeature*>( + BaseFeatureProvider::GetPermissionFeature("power")); ASSERT_TRUE(feature); - std::set<Manifest::Type>* extension_types = feature->extension_types(); + const std::set<Manifest::Type>* extension_types = feature->extension_types(); EXPECT_EQ(3u, extension_types->size()); EXPECT_EQ(1u, extension_types->count(Manifest::TYPE_EXTENSION)); EXPECT_EQ(1u, extension_types->count(Manifest::TYPE_LEGACY_PACKAGED_APP)); diff --git a/extensions/common/features/feature.cc b/extensions/common/features/feature.cc index 48d384a..8fadf4f 100644 --- a/extensions/common/features/feature.cc +++ b/extensions/common/features/feature.cc @@ -37,7 +37,7 @@ Feature::Availability Feature::CreateAvailability(AvailabilityResult result, } Feature::Availability Feature::IsAvailableToExtension( - const Extension* extension) { + const Extension* extension) const { return IsAvailableToManifest(extension->id(), extension->GetType(), extension->location(), diff --git a/extensions/common/features/feature.h b/extensions/common/features/feature.h index 6d3c8c5..1e476c8 100644 --- a/extensions/common/features/feature.h +++ b/extensions/common/features/feature.h @@ -131,7 +131,7 @@ class Feature { Platform platform) const = 0; // Returns true if the feature is available to |extension|. - Availability IsAvailableToExtension(const Extension* extension); + Availability IsAvailableToExtension(const Extension* extension) const; // Returns true if the feature is available to be used in the specified // extension and context. diff --git a/extensions/common/features/feature_provider.cc b/extensions/common/features/feature_provider.cc index ba8794f7..90e7924 100644 --- a/extensions/common/features/feature_provider.cc +++ b/extensions/common/features/feature_provider.cc @@ -46,11 +46,22 @@ class Static { base::LazyInstance<Static> g_static = LAZY_INSTANCE_INITIALIZER; +const Feature* GetFeatureFromProviderByName(const std::string& provider_name, + const std::string& feature_name) { + const Feature* feature = + FeatureProvider::GetByName(provider_name)->GetFeature(feature_name); + CHECK(feature) << "FeatureProvider '" << provider_name + << "' does not contain Feature '" << feature_name << "'"; + return feature; +} + } // namespace // static const FeatureProvider* FeatureProvider::GetByName(const std::string& name) { - return g_static.Get().GetFeatures(name); + const FeatureProvider* feature_provider = g_static.Get().GetFeatures(name); + CHECK(feature_provider) << "FeatureProvider '" << name << "' not found"; + return feature_provider; } // static @@ -68,8 +79,29 @@ const FeatureProvider* FeatureProvider::GetPermissionFeatures() { return GetByName("permission"); } +// static const FeatureProvider* FeatureProvider::GetBehaviorFeatures() { return GetByName("behavior"); } +// static +const Feature* FeatureProvider::GetAPIFeature(const std::string& name) { + return GetFeatureFromProviderByName("api", name); +} + +// static +const Feature* FeatureProvider::GetManifestFeature(const std::string& name) { + return GetFeatureFromProviderByName("manifest", name); +} + +// static +const Feature* FeatureProvider::GetPermissionFeature(const std::string& name) { + return GetFeatureFromProviderByName("permission", name); +} + +// static +const Feature* FeatureProvider::GetBehaviorFeature(const std::string& name) { + return GetFeatureFromProviderByName("behavior", name); +} + } // namespace extensions diff --git a/extensions/common/features/feature_provider.h b/extensions/common/features/feature_provider.h index a45326f..40d8ab8 100644 --- a/extensions/common/features/feature_provider.h +++ b/extensions/common/features/feature_provider.h @@ -18,6 +18,31 @@ class FeatureProvider { FeatureProvider() {} virtual ~FeatureProvider() {} + // + // Static helpers. + // + + // Gets a FeatureProvider for a specific type, like "permission". + static const FeatureProvider* GetByName(const std::string& name); + + // Directly access the common FeatureProvider types. + // Each is equivalent to GetByName('featuretype'). + static const FeatureProvider* GetAPIFeatures(); + static const FeatureProvider* GetManifestFeatures(); + static const FeatureProvider* GetPermissionFeatures(); + static const FeatureProvider* GetBehaviorFeatures(); + + // Directly get Features from the common FeatureProvider types. + // Each is equivalent to GetByName('featuretype')->GetFeature(name). + static const Feature* GetAPIFeature(const std::string& name); + static const Feature* GetManifestFeature(const std::string& name); + static const Feature* GetPermissionFeature(const std::string& name); + static const Feature* GetBehaviorFeature(const std::string& name); + + // + // Instance methods. + // + // Returns the feature with the specified name. virtual Feature* GetFeature(const std::string& name) const = 0; @@ -29,15 +54,6 @@ class FeatureProvider { // Returns all features described by this instance, in asciibetical order. virtual const std::vector<std::string>& GetAllFeatureNames() const = 0; - - // Gets a feature provider for a specific feature type, like "permission". - static const FeatureProvider* GetByName(const std::string& name); - - // Directly access the common feature types. - static const FeatureProvider* GetAPIFeatures(); - static const FeatureProvider* GetManifestFeatures(); - static const FeatureProvider* GetPermissionFeatures(); - static const FeatureProvider* GetBehaviorFeatures(); }; } // namespace extensions diff --git a/extensions/common/features/simple_feature.h b/extensions/common/features/simple_feature.h index dadf7a6..bdf9b75 100644 --- a/extensions/common/features/simple_feature.h +++ b/extensions/common/features/simple_feature.h @@ -42,9 +42,15 @@ class SimpleFeature : public Feature { // Accessors defined for testing. See comment above about not directly using // SimpleFeature in production code. std::set<std::string>* blacklist() { return &blacklist_; } + const std::set<std::string>* blacklist() const { return &blacklist_; } std::set<std::string>* whitelist() { return &whitelist_; } + const std::set<std::string>* whitelist() const { return &whitelist_; } std::set<Manifest::Type>* extension_types() { return &extension_types_; } + const std::set<Manifest::Type>* extension_types() const { + return &extension_types_; + } std::set<Context>* contexts() { return &contexts_; } + const std::set<Context>* contexts() const { return &contexts_; } Location location() const { return location_; } void set_location(Location location) { location_ = location; } int min_manifest_version() const { return min_manifest_version_; } |