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 Singleton
<ExtensionFunctionRegistry
>::get();
16 ExtensionFunctionRegistry::ExtensionFunctionRegistry() {
17 extensions::ExtensionsBrowserClient
* client
=
18 extensions::ExtensionsBrowserClient::Get();
20 client
->RegisterExtensionFunctions(this);
24 ExtensionFunctionRegistry::~ExtensionFunctionRegistry() {}
26 void ExtensionFunctionRegistry::GetAllNames(std::vector
<std::string
>* names
) {
27 for (FactoryMap::iterator iter
= factories_
.begin(); iter
!= factories_
.end();
29 names
->push_back(iter
->first
);
33 bool ExtensionFunctionRegistry::OverrideFunction(
34 const std::string
& name
,
35 ExtensionFunctionFactory factory
) {
36 FactoryMap::iterator iter
= factories_
.find(name
);
37 if (iter
== factories_
.end()) {
40 iter
->second
.factory_
= factory
;
45 ExtensionFunction
* ExtensionFunctionRegistry::NewFunction(
46 const std::string
& name
) {
47 FactoryMap::iterator iter
= factories_
.find(name
);
48 if (iter
== factories_
.end()) {
51 ExtensionFunction
* function
= iter
->second
.factory_();
52 function
->set_name(iter
->second
.function_name_
);
53 function
->set_histogram_value(iter
->second
.histogram_value_
);
57 ExtensionFunctionRegistry::FactoryEntry::FactoryEntry()
59 function_name_(nullptr),
60 histogram_value_(extensions::functions::UNKNOWN
) {
63 ExtensionFunctionRegistry::FactoryEntry::FactoryEntry(
64 ExtensionFunctionFactory factory
,
65 const char* function_name
,
66 extensions::functions::HistogramValue histogram_value
)
68 function_name_(function_name
),
69 histogram_value_(histogram_value
) {