| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_BASE_FEATURE_PROVIDER_H_ | 5 #ifndef EXTENSIONS_COMMON_FEATURES_BASE_FEATURE_PROVIDER_H_ |
| 6 #define EXTENSIONS_COMMON_FEATURES_BASE_FEATURE_PROVIDER_H_ | 6 #define EXTENSIONS_COMMON_FEATURES_BASE_FEATURE_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/macros.h" |
| 13 #include "extensions/common/features/feature_provider.h" | 14 #include "extensions/common/features/feature_provider.h" |
| 14 #include "extensions/common/features/simple_feature.h" | |
| 15 | |
| 16 namespace Base { | |
| 17 class DictionaryValue; | |
| 18 } | |
| 19 | 15 |
| 20 namespace extensions { | 16 namespace extensions { |
| 17 class Feature; |
| 21 | 18 |
| 22 // Reads Features out of a simple JSON file description. | 19 // A FeatureProvider contains the mapping of all feature names specified in the |
| 20 // _*_features.json files to the Feature classes. Look up a Feature by its name |
| 21 // to determine whether or not it is available in a certain context. |
| 22 // Subclasses implement the specific logic for how the features are populated; |
| 23 // this class handles vending the features given the query. |
| 24 // TODO(devlin): We could probably combine this and FeatureProvider, since both |
| 25 // contain common functionality and neither are designed to be full |
| 26 // implementations. |
| 23 class BaseFeatureProvider : public FeatureProvider { | 27 class BaseFeatureProvider : public FeatureProvider { |
| 24 public: | 28 public: |
| 25 typedef SimpleFeature*(*FeatureFactory)(); | |
| 26 | |
| 27 // Creates a new BaseFeatureProvider. Pass null to |factory| to have the | |
| 28 // provider create plain old Feature instances. | |
| 29 BaseFeatureProvider(const base::DictionaryValue& root, | |
| 30 FeatureFactory factory); | |
| 31 ~BaseFeatureProvider() override; | 29 ~BaseFeatureProvider() override; |
| 32 | 30 |
| 33 // Gets the feature |feature_name|, if it exists. | 31 // Gets the feature |feature_name|, if it exists. |
| 34 Feature* GetFeature(const std::string& feature_name) const override; | 32 Feature* GetFeature(const std::string& feature_name) const override; |
| 35 Feature* GetParent(Feature* feature) const override; | 33 Feature* GetParent(Feature* feature) const override; |
| 36 std::vector<Feature*> GetChildren(const Feature& parent) const override; | 34 std::vector<Feature*> GetChildren(const Feature& parent) const override; |
| 37 | 35 |
| 38 const FeatureMap& GetAllFeatures() const override; | 36 const FeatureMap& GetAllFeatures() const override; |
| 39 | 37 |
| 40 private: | 38 protected: |
| 39 BaseFeatureProvider(); |
| 41 std::map<std::string, std::unique_ptr<Feature>> features_; | 40 std::map<std::string, std::unique_ptr<Feature>> features_; |
| 42 | 41 |
| 43 // Populated on first use. | 42 private: |
| 44 mutable std::vector<std::string> feature_names_; | 43 DISALLOW_COPY_AND_ASSIGN(BaseFeatureProvider); |
| 45 | |
| 46 FeatureFactory factory_; | |
| 47 }; | 44 }; |
| 48 | 45 |
| 49 } // namespace extensions | 46 } // namespace extensions |
| 50 | 47 |
| 51 #endif // EXTENSIONS_COMMON_FEATURES_BASE_FEATURE_PROVIDER_H_ | 48 #endif // EXTENSIONS_COMMON_FEATURES_BASE_FEATURE_PROVIDER_H_ |
| OLD | NEW |