[Android WebViewShell] Add inclusion test for webview exposed stable interfaces.
[chromium-blink-merge.git] / extensions / browser / extension_function_registry.cc
blobb8be3204b587a1fa1f0fa2297e118d837c55e576
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(iter->second.function_name_);
53 function->set_histogram_value(iter->second.histogram_value_);
54 return function;
57 ExtensionFunctionRegistry::FactoryEntry::FactoryEntry()
58 : factory_(0),
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)
67 : factory_(factory),
68 function_name_(function_name),
69 histogram_value_(histogram_value) {