1 // Copyright 2014 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.
5 #include "extensions/browser/extension_function_registry.h"
7 #include "base/memory/singleton.h"
8 #include "extensions/browser/extension_function.h"
9 #include "extensions/browser/extensions_browser_client.h"
12 ExtensionFunctionRegistry
* ExtensionFunctionRegistry::GetInstance() {
13 return base::Singleton
<ExtensionFunctionRegistry
>::get();
16 ExtensionFunctionRegistry::ExtensionFunctionRegistry() {
17 extensions::ExtensionsBrowserClient
* client
=
18 extensions::ExtensionsBrowserClient::Get();
20 client
->RegisterExtensionFunctions(this);
24 ExtensionFunctionRegistry::~ExtensionFunctionRegistry() {}
26 bool ExtensionFunctionRegistry::OverrideFunction(
27 const std::string
& name
,
28 ExtensionFunctionFactory factory
) {
29 FactoryMap::iterator iter
= factories_
.find(name
);
30 if (iter
== factories_
.end()) {
33 iter
->second
.factory_
= factory
;
38 ExtensionFunction
* ExtensionFunctionRegistry::NewFunction(
39 const std::string
& name
) {
40 FactoryMap::iterator iter
= factories_
.find(name
);
41 if (iter
== factories_
.end()) {
44 ExtensionFunction
* function
= iter
->second
.factory_();
45 function
->set_name(iter
->second
.function_name_
);
46 function
->set_histogram_value(iter
->second
.histogram_value_
);
50 ExtensionFunctionRegistry::FactoryEntry::FactoryEntry()
52 function_name_(nullptr),
53 histogram_value_(extensions::functions::UNKNOWN
) {
56 ExtensionFunctionRegistry::FactoryEntry::FactoryEntry(
57 ExtensionFunctionFactory factory
,
58 const char* function_name
,
59 extensions::functions::HistogramValue histogram_value
)
61 function_name_(function_name
),
62 histogram_value_(histogram_value
) {