blob: a5b6b6b6e37045f1a717c848ce85d33e4a6cff16 [file] [log] [blame]
[email protected]21c6c432014-03-05 18:47:311// 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.
4
5#include "extensions/browser/extension_function_registry.h"
6
7#include "base/memory/singleton.h"
8#include "extensions/browser/extension_function.h"
9#include "extensions/browser/extensions_browser_client.h"
10
11// static
12ExtensionFunctionRegistry* ExtensionFunctionRegistry::GetInstance() {
olli.raula36aa8be2015-09-10 11:14:2213 return base::Singleton<ExtensionFunctionRegistry>::get();
[email protected]21c6c432014-03-05 18:47:3114}
15
16ExtensionFunctionRegistry::ExtensionFunctionRegistry() {
17 extensions::ExtensionsBrowserClient* client =
18 extensions::ExtensionsBrowserClient::Get();
19 if (client) {
20 client->RegisterExtensionFunctions(this);
21 }
22}
23
24ExtensionFunctionRegistry::~ExtensionFunctionRegistry() {}
25
[email protected]21c6c432014-03-05 18:47:3126bool ExtensionFunctionRegistry::OverrideFunction(
27 const std::string& name,
28 ExtensionFunctionFactory factory) {
29 FactoryMap::iterator iter = factories_.find(name);
30 if (iter == factories_.end()) {
31 return false;
32 } else {
33 iter->second.factory_ = factory;
34 return true;
35 }
36}
37
38ExtensionFunction* ExtensionFunctionRegistry::NewFunction(
39 const std::string& name) {
40 FactoryMap::iterator iter = factories_.find(name);
41 if (iter == factories_.end()) {
42 return NULL;
43 }
44 ExtensionFunction* function = iter->second.factory_();
reillyg9c2528c2015-02-11 00:13:1145 function->set_name(iter->second.function_name_);
[email protected]21c6c432014-03-05 18:47:3146 function->set_histogram_value(iter->second.histogram_value_);
47 return function;
48}
49
50ExtensionFunctionRegistry::FactoryEntry::FactoryEntry()
reillyg9c2528c2015-02-11 00:13:1151 : factory_(0),
52 function_name_(nullptr),
53 histogram_value_(extensions::functions::UNKNOWN) {
54}
[email protected]21c6c432014-03-05 18:47:3155
56ExtensionFunctionRegistry::FactoryEntry::FactoryEntry(
57 ExtensionFunctionFactory factory,
reillyg9c2528c2015-02-11 00:13:1158 const char* function_name,
[email protected]21c6c432014-03-05 18:47:3159 extensions::functions::HistogramValue histogram_value)
reillyg9c2528c2015-02-11 00:13:1160 : factory_(factory),
61 function_name_(function_name),
62 histogram_value_(histogram_value) {
63}