Roll src/third_party/WebKit a3b4a2e:7441784 (svn 202551:202552)
[chromium-blink-merge.git] / extensions / browser / extension_function_registry.cc
bloba5b6b6b6e37045f1a717c848ce85d33e4a6cff16
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 base::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 bool 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;
38 ExtensionFunction* ExtensionFunctionRegistry::NewFunction(
39 const std::string& name) {
40 FactoryMap::iterator iter = factories_.find(name);
41 if (iter == factories_.end()) {
42 return NULL;
44 ExtensionFunction* function = iter->second.factory_();
45 function->set_name(iter->second.function_name_);
46 function->set_histogram_value(iter->second.histogram_value_);
47 return function;
50 ExtensionFunctionRegistry::FactoryEntry::FactoryEntry()
51 : factory_(0),
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)
60 : factory_(factory),
61 function_name_(function_name),
62 histogram_value_(histogram_value) {