1 // Copyright (c) 2012 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 "chrome/browser/extensions/extension_function_registry.h"
7 #include "chrome/browser/extensions/api/preference/chrome_direct_setting.h"
8 #include "chrome/browser/extensions/api/preference/preference_api.h"
9 #include "chrome/browser/extensions/api/runtime/runtime_api.h"
10 #include "chrome/browser/extensions/api/web_request/web_request_api.h"
11 #include "chrome/common/extensions/api/generated_api.h"
14 ExtensionFunctionRegistry
* ExtensionFunctionRegistry::GetInstance() {
15 return Singleton
<ExtensionFunctionRegistry
>::get();
18 ExtensionFunctionRegistry::ExtensionFunctionRegistry() {
22 ExtensionFunctionRegistry::~ExtensionFunctionRegistry() {
25 void ExtensionFunctionRegistry::ResetFunctions() {
26 #if defined(ENABLE_EXTENSIONS)
28 // Register all functions here.
31 RegisterFunction
<WebRequestAddEventListener
>();
32 RegisterFunction
<WebRequestEventHandled
>();
35 RegisterFunction
<extensions::GetPreferenceFunction
>();
36 RegisterFunction
<extensions::SetPreferenceFunction
>();
37 RegisterFunction
<extensions::ClearPreferenceFunction
>();
39 // Direct Preference Access for Component Extensions.
40 RegisterFunction
<extensions::chromedirectsetting::GetDirectSettingFunction
>();
41 RegisterFunction
<extensions::chromedirectsetting::SetDirectSettingFunction
>();
43 extensions::chromedirectsetting::ClearDirectSettingFunction
>();
46 RegisterFunction
<extensions::RuntimeGetBackgroundPageFunction
>();
47 RegisterFunction
<extensions::RuntimeSetUninstallURLFunction
>();
48 RegisterFunction
<extensions::RuntimeReloadFunction
>();
49 RegisterFunction
<extensions::RuntimeRequestUpdateCheckFunction
>();
50 RegisterFunction
<extensions::RuntimeRestartFunction
>();
53 extensions::api::GeneratedFunctionRegistry::RegisterAll(this);
54 #endif // defined(ENABLE_EXTENSIONS)
57 void ExtensionFunctionRegistry::GetAllNames(std::vector
<std::string
>* names
) {
58 for (FactoryMap::iterator iter
= factories_
.begin();
59 iter
!= factories_
.end(); ++iter
) {
60 names
->push_back(iter
->first
);
64 bool ExtensionFunctionRegistry::OverrideFunction(
65 const std::string
& name
,
66 ExtensionFunctionFactory factory
) {
67 FactoryMap::iterator iter
= factories_
.find(name
);
68 if (iter
== factories_
.end()) {
71 iter
->second
.factory_
= factory
;
76 ExtensionFunction
* ExtensionFunctionRegistry::NewFunction(
77 const std::string
& name
) {
78 FactoryMap::iterator iter
= factories_
.find(name
);
79 if (iter
== factories_
.end()) {
82 ExtensionFunction
* function
= iter
->second
.factory_();
83 function
->set_name(name
);
84 function
->set_histogram_value(iter
->second
.histogram_value_
);
88 ExtensionFunctionRegistry::FactoryEntry::FactoryEntry()
89 : factory_(0), histogram_value_(extensions::functions::UNKNOWN
) {
92 ExtensionFunctionRegistry::FactoryEntry::FactoryEntry(
93 ExtensionFunctionFactory factory
,
94 extensions::functions::HistogramValue histogram_value
)
95 : factory_(factory
), histogram_value_(histogram_value
) {