Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: extensions/common/features/feature_provider.h

Issue 2669463002: [Extensions] Remove BaseFeatureProvider (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/strings/string_piece.h"
13 14
14 namespace extensions { 15 namespace extensions {
15 16
16 class Feature; 17 class Feature;
17 18
18 using FeatureMap = std::map<std::string, std::unique_ptr<Feature>>; 19 using FeatureMap = std::map<std::string, std::unique_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 //
27 // Static helpers.
28 //
29 26
30 // Gets a FeatureProvider for a specific type, like "permission". 27 // Gets a FeatureProvider for a specific type, like "permission".
31 static const FeatureProvider* GetByName(const std::string& name); 28 static const FeatureProvider* GetByName(const std::string& name);
32 29
33 // Directly access the common FeatureProvider types. 30 // Directly access the common FeatureProvider types.
34 // Each is equivalent to GetByName('featuretype'). 31 // Each is equivalent to GetByName('featuretype').
35 static const FeatureProvider* GetAPIFeatures(); 32 static const FeatureProvider* GetAPIFeatures();
36 static const FeatureProvider* GetManifestFeatures(); 33 static const FeatureProvider* GetManifestFeatures();
37 static const FeatureProvider* GetPermissionFeatures(); 34 static const FeatureProvider* GetPermissionFeatures();
38 static const FeatureProvider* GetBehaviorFeatures(); 35 static const FeatureProvider* GetBehaviorFeatures();
39 36
40 // Directly get Features from the common FeatureProvider types. 37 // Directly get Features from the common FeatureProvider types.
41 // Each is equivalent to GetByName('featuretype')->GetFeature(name). 38 // Each is equivalent to GetByName('featuretype')->GetFeature(name).
42 // NOTE: These functions may return |nullptr| in case corresponding JSON file 39 // NOTE: These functions may return |nullptr| in case corresponding JSON file
43 // got corrupted. 40 // got corrupted.
44 static const Feature* GetAPIFeature(const std::string& name); 41 static const Feature* GetAPIFeature(const std::string& name);
45 static const Feature* GetManifestFeature(const std::string& name); 42 static const Feature* GetManifestFeature(const std::string& name);
46 static const Feature* GetPermissionFeature(const std::string& name); 43 static const Feature* GetPermissionFeature(const std::string& name);
47 static const Feature* GetBehaviorFeature(const std::string& name); 44 static const Feature* GetBehaviorFeature(const std::string& name);
48 45
49 //
50 // Instance methods.
51 //
52
53 // Returns the feature with the specified name. 46 // Returns the feature with the specified name.
54 virtual Feature* GetFeature(const std::string& name) const = 0; 47 Feature* GetFeature(const std::string& name) const;
55 48
56 // Returns the parent feature of |feature|, or NULL if there isn't one. 49 // Returns the parent feature of |feature|, or NULL if there isn't one.
57 virtual Feature* GetParent(Feature* feature) const = 0; 50 Feature* GetParent(Feature* feature) const;
58 51
59 // Returns the features inside the |parent| namespace, recursively. 52 // Returns the features inside the |parent| namespace, recursively.
60 virtual std::vector<Feature*> GetChildren(const Feature& parent) const = 0; 53 std::vector<Feature*> GetChildren(const Feature& parent) const;
61 54
62 // Returns a map containing all features described by this instance. 55 // Returns a map containing all features described by this instance.
63 virtual const FeatureMap& GetAllFeatures() const = 0; 56 // TODO(devlin): Rename this to be features().
57 const FeatureMap& GetAllFeatures() const;
58
59 void AddFeature(base::StringPiece name, std::unique_ptr<Feature> feature);
60
61 // Takes ownership. Used in preference to unique_ptr variant to reduce size
62 // of generated code.
63 void AddFeature(base::StringPiece name, Feature* feature);
64
65 private:
66 FeatureMap features_;
67
68 DISALLOW_COPY_AND_ASSIGN(FeatureProvider);
64 }; 69 };
65 70
66 } // namespace extensions 71 } // namespace extensions
67 72
68 #endif // EXTENSIONS_COMMON_FEATURES_FEATURE_PROVIDER_H_ 73 #endif // EXTENSIONS_COMMON_FEATURES_FEATURE_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698