| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef EXTENSIONS_COMMON_FEATURES_BASE_FEATURE_PROVIDER_H_ | |
| 6 #define EXTENSIONS_COMMON_FEATURES_BASE_FEATURE_PROVIDER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <memory> | |
| 10 #include <string> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/macros.h" | |
| 14 #include "base/strings/string_piece.h" | |
| 15 #include "extensions/common/features/feature_provider.h" | |
| 16 | |
| 17 namespace extensions { | |
| 18 class Feature; | |
| 19 | |
| 20 // A FeatureProvider contains the mapping of all feature names specified in the | |
| 21 // _*_features.json files to the Feature classes. Look up a Feature by its name | |
| 22 // to determine whether or not it is available in a certain context. | |
| 23 // Subclasses implement the specific logic for how the features are populated; | |
| 24 // this class handles vending the features given the query. | |
| 25 // TODO(devlin): We could probably combine this and FeatureProvider, since both | |
| 26 // contain common functionality and neither are designed to be full | |
| 27 // implementations. | |
| 28 class BaseFeatureProvider : public FeatureProvider { | |
| 29 public: | |
| 30 ~BaseFeatureProvider() override; | |
| 31 | |
| 32 // Gets the feature |feature_name|, if it exists. | |
| 33 Feature* GetFeature(const std::string& feature_name) const override; | |
| 34 Feature* GetParent(Feature* feature) const override; | |
| 35 std::vector<Feature*> GetChildren(const Feature& parent) const override; | |
| 36 | |
| 37 const FeatureMap& GetAllFeatures() const override; | |
| 38 | |
| 39 protected: | |
| 40 BaseFeatureProvider(); | |
| 41 | |
| 42 void AddFeature(base::StringPiece name, std::unique_ptr<Feature> feature); | |
| 43 | |
| 44 // Takes ownership. Used in preference to unique_ptr variant to reduce size | |
| 45 // of generated code. | |
| 46 void AddFeature(base::StringPiece name, Feature* feature); | |
| 47 | |
| 48 private: | |
| 49 std::map<std::string, std::unique_ptr<Feature>> features_; | |
| 50 | |
| 51 DISALLOW_COPY_AND_ASSIGN(BaseFeatureProvider); | |
| 52 }; | |
| 53 | |
| 54 } // namespace extensions | |
| 55 | |
| 56 #endif // EXTENSIONS_COMMON_FEATURES_BASE_FEATURE_PROVIDER_H_ | |
| OLD | NEW |