Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / extensions / browser / extension_function_registry.cc
blob1e1640a4c4d813d57efda997280298b3a94bf316
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"
11 // static
12 ExtensionFunctionRegistry* ExtensionFunctionRegistry::GetInstance() {
13 return Singleton<ExtensionFunctionRegistry>::get();
16 ExtensionFunctionRegistry::ExtensionFunctionRegistry() {
17 extensions::ExtensionsBrowserClient* client =
18 extensions::ExtensionsBrowserClient::Get();
19 if (client) {
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();
28 ++iter) {
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()) {
38 return false;
39 } else {
40 iter->second.factory_ = factory;
41 return true;
45 ExtensionFunction* ExtensionFunctionRegistry::NewFunction(
46 const std::string& name) {
47 FactoryMap::iterator iter = factories_.find(name);
48 if (iter == factories_.end()) {
49 return NULL;
51 ExtensionFunction* function = iter->second.factory_();
52 function->set_name(name);
53 function->set_histogram_value(iter->second.histogram_value_);
54 return function;
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) {}