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/identity/experimental_identity_api.h"
8 #include "chrome/browser/extensions/api/preference/chrome_direct_setting.h"
9 #include "chrome/browser/extensions/api/preference/preference_api.h"
10 #include "chrome/browser/extensions/api/runtime/runtime_api.h"
11 #include "chrome/browser/extensions/api/web_request/web_request_api.h"
12 #include "chrome/common/extensions/api/generated_api.h"
15 ExtensionFunctionRegistry
* ExtensionFunctionRegistry::GetInstance() {
16 return Singleton
<ExtensionFunctionRegistry
>::get();
19 ExtensionFunctionRegistry::ExtensionFunctionRegistry() {
23 ExtensionFunctionRegistry::~ExtensionFunctionRegistry() {
26 void ExtensionFunctionRegistry::ResetFunctions() {
27 #if defined(ENABLE_EXTENSIONS)
29 // Register all functions here.
32 RegisterFunction
<WebRequestAddEventListener
>();
33 RegisterFunction
<WebRequestEventHandled
>();
36 RegisterFunction
<extensions::GetPreferenceFunction
>();
37 RegisterFunction
<extensions::SetPreferenceFunction
>();
38 RegisterFunction
<extensions::ClearPreferenceFunction
>();
40 // Direct Preference Access for Component Extensions.
41 RegisterFunction
<extensions::chromedirectsetting::GetDirectSettingFunction
>();
42 RegisterFunction
<extensions::chromedirectsetting::SetDirectSettingFunction
>();
44 extensions::chromedirectsetting::ClearDirectSettingFunction
>();
47 RegisterFunction
<extensions::RuntimeGetBackgroundPageFunction
>();
48 RegisterFunction
<extensions::RuntimeSetUninstallUrlFunction
>();
49 RegisterFunction
<extensions::RuntimeReloadFunction
>();
50 RegisterFunction
<extensions::RuntimeRequestUpdateCheckFunction
>();
51 RegisterFunction
<extensions::RuntimeRestartFunction
>();
53 // ExperimentalIdentity.
54 RegisterFunction
<extensions::ExperimentalIdentityGetAuthTokenFunction
>();
55 RegisterFunction
<extensions::ExperimentalIdentityLaunchWebAuthFlowFunction
>();
58 extensions::api::GeneratedFunctionRegistry::RegisterAll(this);
59 #endif // defined(ENABLE_EXTENSIONS)
62 void ExtensionFunctionRegistry::GetAllNames(std::vector
<std::string
>* names
) {
63 for (FactoryMap::iterator iter
= factories_
.begin();
64 iter
!= factories_
.end(); ++iter
) {
65 names
->push_back(iter
->first
);
69 bool ExtensionFunctionRegistry::OverrideFunction(
70 const std::string
& name
,
71 ExtensionFunctionFactory factory
) {
72 FactoryMap::iterator iter
= factories_
.find(name
);
73 if (iter
== factories_
.end()) {
76 iter
->second
.factory_
= factory
;
81 ExtensionFunction
* ExtensionFunctionRegistry::NewFunction(
82 const std::string
& name
) {
83 FactoryMap::iterator iter
= factories_
.find(name
);
84 if (iter
== factories_
.end()) {
87 ExtensionFunction
* function
= iter
->second
.factory_();
88 function
->set_name(name
);
89 function
->set_histogram_value(iter
->second
.histogram_value_
);
93 ExtensionFunctionRegistry::FactoryEntry::FactoryEntry()
94 : factory_(0), histogram_value_(extensions::functions::UNKNOWN
) {
97 ExtensionFunctionRegistry::FactoryEntry::FactoryEntry(
98 ExtensionFunctionFactory factory
,
99 extensions::functions::HistogramValue histogram_value
)
100 : factory_(factory
), histogram_value_(histogram_value
) {