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

Side by Side Diff: chrome/browser/extensions/extension_function_registry.h

Issue 9716003: Extract ExtensionFunctionRegistry from ExtensionFunctionDispatcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits; fix Windows build (thanks Brad Nelson!). Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_REGISTRY_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_REGISTRY_H_
7 #pragma once
8
9 #include <map>
10 #include <string>
11 #include <vector>
12
13 class ExtensionFunction;
14
15 // A factory function for creating new ExtensionFunction instances.
16 typedef ExtensionFunction* (*ExtensionFunctionFactory)();
17
18 // Template for defining ExtensionFunctionFactory.
19 template<class T>
20 ExtensionFunction* NewExtensionFunction() {
21 return new T();
22 }
23
24 // Contains a list of all known extension functions and allows clients to
25 // create instances of them.
26 class ExtensionFunctionRegistry {
27 public:
28 static ExtensionFunctionRegistry* GetInstance();
29 explicit ExtensionFunctionRegistry();
30 virtual ~ExtensionFunctionRegistry();
31
32 // Resets all functions to their default values.
33 void ResetFunctions();
34
35 // Adds all function names to 'names'.
36 void GetAllNames(std::vector<std::string>* names);
37
38 // Allows overriding of specific functions (e.g. for testing). Functions
39 // must be previously registered. Returns true if successful.
40 bool OverrideFunction(const std::string& name,
41 ExtensionFunctionFactory factory);
42
43 // Factory method for the ExtensionFunction registered as 'name'.
44 ExtensionFunction* NewFunction(const std::string& name);
45
46 template<class T>
47 void RegisterFunction() {
48 factories_[T::function_name()] = &NewExtensionFunction<T>;
49 }
50
51 private:
52 typedef std::map<std::string, ExtensionFunctionFactory> FactoryMap;
53 FactoryMap factories_;
54 };
55
56 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_REGISTRY_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_function_dispatcher.cc ('k') | chrome/browser/extensions/extension_function_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698