Chromium Code Reviews| 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 "base/macros.h" |
| 14 #include "base/strings/string_piece.h" | |
| 14 #include "extensions/common/features/feature_provider.h" | 15 #include "extensions/common/features/feature_provider.h" |
| 15 | 16 |
| 16 namespace extensions { | 17 namespace extensions { |
| 17 class Feature; | 18 class Feature; |
| 18 | 19 |
| 19 // A FeatureProvider contains the mapping of all feature names specified in the | 20 // 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 // _*_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 // 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 // Subclasses implement the specific logic for how the features are populated; |
| 23 // this class handles vending the features given the query. | 24 // this class handles vending the features given the query. |
| 24 // TODO(devlin): We could probably combine this and FeatureProvider, since both | 25 // TODO(devlin): We could probably combine this and FeatureProvider, since both |
| 25 // contain common functionality and neither are designed to be full | 26 // contain common functionality and neither are designed to be full |
| 26 // implementations. | 27 // implementations. |
| 27 class BaseFeatureProvider : public FeatureProvider { | 28 class BaseFeatureProvider : public FeatureProvider { |
| 28 public: | 29 public: |
| 29 ~BaseFeatureProvider() override; | 30 ~BaseFeatureProvider() override; |
| 30 | 31 |
| 31 // Gets the feature |feature_name|, if it exists. | 32 // Gets the feature |feature_name|, if it exists. |
| 32 Feature* GetFeature(const std::string& feature_name) const override; | 33 Feature* GetFeature(const std::string& feature_name) const override; |
| 33 Feature* GetParent(Feature* feature) const override; | 34 Feature* GetParent(Feature* feature) const override; |
| 34 std::vector<Feature*> GetChildren(const Feature& parent) const override; | 35 std::vector<Feature*> GetChildren(const Feature& parent) const override; |
| 35 | 36 |
| 36 const FeatureMap& GetAllFeatures() const override; | 37 const FeatureMap& GetAllFeatures() const override; |
| 37 | 38 |
| 38 protected: | 39 protected: |
| 39 BaseFeatureProvider(); | 40 BaseFeatureProvider(); |
| 41 | |
| 42 void AddFeature(base::StringPiece name, std::unique_ptr<Feature> feature); | |
|
Devlin
2016/07/27 16:46:23
For my own edification, what's the motivation behi
dcheng
2016/07/27 17:02:36
1. map::operator[] generates a bunch of inline cod
Devlin
2016/07/27 17:04:59
Ah, makes sense. Thanks!
| |
| 43 | |
| 44 private: | |
| 40 std::map<std::string, std::unique_ptr<Feature>> features_; | 45 std::map<std::string, std::unique_ptr<Feature>> features_; |
| 41 | 46 |
| 42 private: | |
| 43 DISALLOW_COPY_AND_ASSIGN(BaseFeatureProvider); | 47 DISALLOW_COPY_AND_ASSIGN(BaseFeatureProvider); |
| 44 }; | 48 }; |
| 45 | 49 |
| 46 } // namespace extensions | 50 } // namespace extensions |
| 47 | 51 |
| 48 #endif // EXTENSIONS_COMMON_FEATURES_BASE_FEATURE_PROVIDER_H_ | 52 #endif // EXTENSIONS_COMMON_FEATURES_BASE_FEATURE_PROVIDER_H_ |
| OLD | NEW |