Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_EXTENSION_API_H_ | 5 #ifndef EXTENSIONS_COMMON_EXTENSION_API_H_ |
| 6 #define EXTENSIONS_COMMON_EXTENSION_API_H_ | 6 #define EXTENSIONS_COMMON_EXTENSION_API_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 | 58 |
| 59 class OverrideSharedInstanceForTest { | 59 class OverrideSharedInstanceForTest { |
| 60 public: | 60 public: |
| 61 explicit OverrideSharedInstanceForTest(ExtensionAPI* testing_api); | 61 explicit OverrideSharedInstanceForTest(ExtensionAPI* testing_api); |
| 62 ~OverrideSharedInstanceForTest(); | 62 ~OverrideSharedInstanceForTest(); |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 ExtensionAPI* original_api_; | 65 ExtensionAPI* original_api_; |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 // Creates a completely clean instance. Configure using RegisterSchema() and | 68 // Creates a completely clean instance. Configure using |
| 69 // RegisterDependencyProvider before use. | 69 // RegisterDependencyProvider before use. |
| 70 ExtensionAPI(); | 70 ExtensionAPI(); |
| 71 virtual ~ExtensionAPI(); | 71 virtual ~ExtensionAPI(); |
| 72 | 72 |
| 73 // Add a (non-generated) API schema resource. | |
| 74 void RegisterSchemaResource(const std::string& api_name, int resource_id); | |
| 75 | |
| 76 // Add a FeatureProvider for APIs. The features are used to specify | 73 // Add a FeatureProvider for APIs. The features are used to specify |
| 77 // dependencies and constraints on the availability of APIs. | 74 // dependencies and constraints on the availability of APIs. |
| 78 void RegisterDependencyProvider(const std::string& name, | 75 void RegisterDependencyProvider(const std::string& name, |
| 79 const FeatureProvider* provider); | 76 const FeatureProvider* provider); |
| 80 | 77 |
| 81 // Returns true if the API item called |api_full_name| and all of its | 78 // Returns true if the API item called |api_full_name| and all of its |
| 82 // dependencies are available in |context|. | 79 // dependencies are available in |context|. |
| 83 // | 80 // |
| 84 // |api_full_name| can be either a namespace name (like "bookmarks") or a | 81 // |api_full_name| can be either a namespace name (like "bookmarks") or a |
| 85 // member name (like "bookmarks.create"). | 82 // member name (like "bookmarks.create"). |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 // "<unknown-api>.monkey" -> ("", "") | 116 // "<unknown-api>.monkey" -> ("", "") |
| 120 // | 117 // |
| 121 // The |child_name| parameter can be be NULL if you don't need that part. | 118 // The |child_name| parameter can be be NULL if you don't need that part. |
| 122 std::string GetAPINameFromFullName(const std::string& full_name, | 119 std::string GetAPINameFromFullName(const std::string& full_name, |
| 123 std::string* child_name); | 120 std::string* child_name); |
| 124 | 121 |
| 125 // Gets a feature from any dependency provider registered with ExtensionAPI. | 122 // Gets a feature from any dependency provider registered with ExtensionAPI. |
| 126 // Returns NULL if the feature could not be found. | 123 // Returns NULL if the feature could not be found. |
| 127 Feature* GetFeatureDependency(const std::string& dependency_name); | 124 Feature* GetFeatureDependency(const std::string& dependency_name); |
| 128 | 125 |
| 126 // Adds a fake schema that the ExtensionAPI should know about. | |
| 127 void RegisterFakeSchemaForTesting(const std::string& schema); | |
| 128 | |
| 129 private: | 129 private: |
| 130 FRIEND_TEST_ALL_PREFIXES(ExtensionAPITest, DefaultConfigurationFeatures); | 130 FRIEND_TEST_ALL_PREFIXES(ExtensionAPITest, DefaultConfigurationFeatures); |
| 131 FRIEND_TEST_ALL_PREFIXES(ExtensionAPITest, TypesHaveNamespace); | 131 FRIEND_TEST_ALL_PREFIXES(ExtensionAPITest, TypesHaveNamespace); |
| 132 friend struct base::DefaultSingletonTraits<ExtensionAPI>; | 132 friend struct base::DefaultSingletonTraits<ExtensionAPI>; |
| 133 | 133 |
| 134 void InitDefaultConfiguration(); | 134 void InitDefaultConfiguration(); |
| 135 | 135 |
| 136 bool default_configuration_initialized_; | 136 bool default_configuration_initialized_; |
| 137 | 137 |
| 138 // Loads a schema. | 138 // Loads a schema. |
| 139 void LoadSchema(const std::string& name, const base::StringPiece& schema); | 139 void LoadSchema(const std::string& name, const base::StringPiece& schema); |
| 140 | 140 |
| 141 // Map from each API that hasn't been loaded yet to the schema which defines | 141 // A set of fake schema resources that we should treat as knowing for testing. |
| 142 // it. Note that there may be multiple APIs per schema. | 142 // TODO(devlin): This is rather silly. |
| 143 typedef std::map<std::string, int> UnloadedSchemaMap; | 143 std::set<std::string> fake_schemas_; |
|
Devlin
2016/08/22 18:30:45
I don't love this, but I also don't have a better
lazyboy
2016/08/22 22:51:31
I would put them in TestExtensionAPI (extending fr
Devlin
2016/08/23 00:13:08
Works for me. Still not my favorite, but I think
| |
| 144 UnloadedSchemaMap unloaded_schemas_; | |
| 145 | 144 |
| 146 // Schemas for each namespace. | 145 // Schemas for each namespace. |
| 147 using SchemaMap = | 146 using SchemaMap = |
| 148 std::map<std::string, std::unique_ptr<const base::DictionaryValue>>; | 147 std::map<std::string, std::unique_ptr<const base::DictionaryValue>>; |
| 149 SchemaMap schemas_; | 148 SchemaMap schemas_; |
| 150 | 149 |
| 151 // FeatureProviders used for resolving dependencies. | 150 // FeatureProviders used for resolving dependencies. |
| 152 typedef std::map<std::string, const FeatureProvider*> FeatureProviderMap; | 151 typedef std::map<std::string, const FeatureProvider*> FeatureProviderMap; |
| 153 FeatureProviderMap dependency_providers_; | 152 FeatureProviderMap dependency_providers_; |
| 154 | 153 |
| 155 DISALLOW_COPY_AND_ASSIGN(ExtensionAPI); | 154 DISALLOW_COPY_AND_ASSIGN(ExtensionAPI); |
| 156 }; | 155 }; |
| 157 | 156 |
| 158 } // namespace extensions | 157 } // namespace extensions |
| 159 | 158 |
| 160 #endif // EXTENSIONS_COMMON_EXTENSION_API_H_ | 159 #endif // EXTENSIONS_COMMON_EXTENSION_API_H_ |
| OLD | NEW |