Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef EXTENSIONS_COMMON_FEATURES_FEATURE_PROVIDER_H_ | 5 #ifndef EXTENSIONS_COMMON_FEATURES_FEATURE_PROVIDER_H_ |
| 6 #define EXTENSIONS_COMMON_FEATURES_FEATURE_PROVIDER_H_ | 6 #define EXTENSIONS_COMMON_FEATURES_FEATURE_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 | 13 |
| 14 namespace extensions { | 14 namespace extensions { |
| 15 | 15 |
| 16 class Extension; | |
|
benwells
2016/04/14 06:36:15
It's nice that this file doesn't depend on Extensi
| |
| 16 class Feature; | 17 class Feature; |
| 17 | 18 |
| 18 using FeatureMap = std::map<std::string, scoped_ptr<Feature>>; | 19 using FeatureMap = std::map<std::string, scoped_ptr<Feature>>; |
| 19 | 20 |
| 20 // Implemented by classes that can vend features. | 21 // Implemented by classes that can vend features. |
| 21 class FeatureProvider { | 22 class FeatureProvider { |
| 22 public: | 23 public: |
| 23 FeatureProvider() {} | 24 FeatureProvider() {} |
| 24 virtual ~FeatureProvider() {} | 25 virtual ~FeatureProvider() {} |
| 25 | 26 |
| 26 // | 27 // |
| 27 // Static helpers. | 28 // Static helpers. |
| 28 // | 29 // |
| 29 | 30 |
| 30 // Gets a FeatureProvider for a specific type, like "permission". | 31 // Gets a FeatureProvider for a specific type, like "permission". |
| 31 static const FeatureProvider* GetByName(const std::string& name); | 32 static const FeatureProvider* GetByName(const std::string& name); |
| 32 | 33 |
| 33 // Directly access the common FeatureProvider types. | 34 // Directly access the common FeatureProvider types. |
| 34 // Each is equivalent to GetByName('featuretype'). | 35 // Each is equivalent to GetByName('featuretype'). |
| 35 static const FeatureProvider* GetAPIFeatures(); | 36 static const FeatureProvider* GetAPIFeatures(); |
| 36 static const FeatureProvider* GetManifestFeatures(); | 37 static const FeatureProvider* GetManifestFeatures(); |
| 37 static const FeatureProvider* GetPermissionFeatures(); | 38 static const FeatureProvider* GetPermissionFeatures(); |
| 38 static const FeatureProvider* GetBehaviorFeatures(); | 39 static const FeatureProvider* GetBehaviorFeatures(); |
| 39 | 40 |
| 40 // Directly get Features from the common FeatureProvider types. | 41 // Directly get Features from the common FeatureProvider types. |
| 41 // Each is equivalent to GetByName('featuretype')->GetFeature(name). | 42 // Each is equivalent to GetByName('featuretype')->GetFeature(name). |
| 42 static const Feature* GetAPIFeature(const std::string& name); | 43 static const Feature* GetAPIFeature(const std::string& name); |
| 43 static const Feature* GetManifestFeature(const std::string& name); | 44 static const Feature* GetManifestFeature(const std::string& name); |
| 44 static const Feature* GetPermissionFeature(const std::string& name); | 45 static const Feature* GetPermissionFeature(const std::string& name); |
| 45 static const Feature* GetBehaviorFeature(const std::string& name); | 46 |
| 47 // Check if behavior feature exists and is available for extension. | |
| 48 // Feature existence should be checked as sometimes JSONReader fails to read | |
| 49 // resource file correctly. See http://crbug.com/176381 | |
| 50 static bool BehaviorFeatureIsAvailable(const std::string& name, | |
| 51 const Extension* extension); | |
| 46 | 52 |
| 47 // | 53 // |
| 48 // Instance methods. | 54 // Instance methods. |
| 49 // | 55 // |
| 50 | 56 |
| 51 // Returns the feature with the specified name. | 57 // Returns the feature with the specified name. |
| 52 virtual Feature* GetFeature(const std::string& name) const = 0; | 58 virtual Feature* GetFeature(const std::string& name) const = 0; |
| 53 | 59 |
| 54 // Returns the parent feature of |feature|, or NULL if there isn't one. | 60 // Returns the parent feature of |feature|, or NULL if there isn't one. |
| 55 virtual Feature* GetParent(Feature* feature) const = 0; | 61 virtual Feature* GetParent(Feature* feature) const = 0; |
| 56 | 62 |
| 57 // Returns the features inside the |parent| namespace, recursively. | 63 // Returns the features inside the |parent| namespace, recursively. |
| 58 virtual std::vector<Feature*> GetChildren(const Feature& parent) const = 0; | 64 virtual std::vector<Feature*> GetChildren(const Feature& parent) const = 0; |
| 59 | 65 |
| 60 // Returns a map containing all features described by this instance. | 66 // Returns a map containing all features described by this instance. |
| 61 virtual const FeatureMap& GetAllFeatures() const = 0; | 67 virtual const FeatureMap& GetAllFeatures() const = 0; |
| 62 }; | 68 }; |
| 63 | 69 |
| 64 } // namespace extensions | 70 } // namespace extensions |
| 65 | 71 |
| 66 #endif // EXTENSIONS_COMMON_FEATURES_FEATURE_PROVIDER_H_ | 72 #endif // EXTENSIONS_COMMON_FEATURES_FEATURE_PROVIDER_H_ |
| OLD | NEW |