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

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

Issue 9666059: Extract ExtensionFunctionRegistry from ExtensionFunctionDispatcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch Set 1 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_FACTORY_REGISTRY_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FACTORY_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 FactoryRegistry {
27 public:
28 static FactoryRegistry* GetInstance();
29 FactoryRegistry() { ResetFunctions(); }
30
31 // Resets all functions to their default values.
32 void ResetFunctions();
33
34 // Adds all function names to 'names'.
35 void GetAllNames(std::vector<std::string>* names);
36
37 // Allows overriding of specific functions (e.g. for testing). Functions
38 // must be previously registered. Returns true if successful.
39 bool OverrideFunction(const std::string& name,
40 ExtensionFunctionFactory factory);
41
42 // Factory method for the ExtensionFunction registered as 'name'.
43 ExtensionFunction* NewFunction(const std::string& name);
44
45 template<class T>
46 void RegisterFunction() {
47 factories_[T::function_name()] = &NewExtensionFunction<T>;
48 }
49
50 private:
51 typedef std::map<std::string, ExtensionFunctionFactory> FactoryMap;
52 FactoryMap factories_;
53 };
54
55 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FACTORY_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698