| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_COMMON_EXTENSIONS_SIMPLE_FEATURE_PROVIDER_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_SIMPLE_FEATURE_PROVIDER_H_ |
| 6 #define CHROME_COMMON_EXTENSIONS_SIMPLE_FEATURE_PROVIDER_H_ | 6 #define CHROME_COMMON_EXTENSIONS_SIMPLE_FEATURE_PROVIDER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/common/extensions/feature.h" | 14 #include "chrome/common/extensions/feature.h" |
| 15 #include "chrome/common/extensions/feature_provider.h" | |
| 16 | 15 |
| 17 namespace extensions { | 16 namespace extensions { |
| 18 | 17 |
| 19 // Reads Features out of a simple JSON file description. | 18 // Reads Features out of a simple JSON file description. |
| 20 class SimpleFeatureProvider : public FeatureProvider { | 19 class SimpleFeatureProvider { |
| 21 public: | 20 public: |
| 22 typedef Feature*(*FeatureFactory)(); | 21 // Create an instance for an arbitrary hunk of JSON. This is typically used |
| 23 | 22 // during tests. |
| 24 // Creates a new SimpleFeatureProvider. Pass null to |factory| to have the | 23 explicit SimpleFeatureProvider(scoped_ptr<DictionaryValue> root); |
| 25 // provider create plain old Feature instances. | 24 ~SimpleFeatureProvider(); |
| 26 SimpleFeatureProvider(scoped_ptr<DictionaryValue> root, | |
| 27 FeatureFactory factory); | |
| 28 virtual ~SimpleFeatureProvider(); | |
| 29 | 25 |
| 30 // Gets an instance for the _manifest_features.json file that is baked into | 26 // Gets an instance for the _manifest_features.json file that is baked into |
| 31 // Chrome as a resource. | 27 // Chrome as a resource. |
| 32 static SimpleFeatureProvider* GetManifestFeatures(); | 28 static SimpleFeatureProvider* GetManifestFeatures(); |
| 33 | 29 |
| 34 // Gets an instance for the _permission_features.json file that is baked into | 30 // Gets an instance for the _permission_features.json file that is baked into |
| 35 // Chrome as a resource. | 31 // Chrome as a resource. |
| 36 static SimpleFeatureProvider* GetPermissionFeatures(); | 32 static SimpleFeatureProvider* GetPermissionFeatures(); |
| 37 | 33 |
| 38 // Returns all features described by this instance. | 34 // Returns all features described by this instance. |
| 39 std::set<std::string> GetAllFeatureNames() const; | 35 std::set<std::string> GetAllFeatureNames() const; |
| 40 | 36 |
| 41 // Gets the feature |feature_name|, if it exists. | 37 // Gets the feature |feature_name|, if it exists. |
| 42 virtual scoped_ptr<Feature> GetFeature( | 38 scoped_ptr<Feature> GetFeature(const std::string& feature_name) const; |
| 43 const std::string& feature_name) OVERRIDE; | |
| 44 | 39 |
| 45 private: | 40 private: |
| 46 scoped_ptr<DictionaryValue> root_; | 41 scoped_ptr<DictionaryValue> root_; |
| 47 FeatureFactory factory_; | |
| 48 }; | 42 }; |
| 49 | 43 |
| 50 } // namespace extensions | 44 } // namespace extensions |
| 51 | 45 |
| 52 #endif // CHROME_COMMON_EXTENSIONS_SIMPLE_FEATURE_PROVIDER_H_ | 46 #endif // CHROME_COMMON_EXTENSIONS_SIMPLE_FEATURE_PROVIDER_H_ |
| OLD | NEW |