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(name
);
53 function
->set_histogram_value(iter
->second
.histogram_value_
);
57 ExtensionFunctionRegistry::FactoryEntry::FactoryEntry()
58 : factory_(0), histogram_value_(extensions::functions::UNKNOWN
) {}
60 ExtensionFunctionRegistry::FactoryEntry::FactoryEntry(
61 ExtensionFunctionFactory factory
,
62 extensions::functions::HistogramValue histogram_value
)
63 : factory_(factory
), histogram_value_(histogram_value
) {}