Rename desktop_cursor_loader_updater_aurax11.
[chromium-blink-merge.git] / chrome / browser / extensions / extension_function_registry.cc
blob48202d91f4e1a09ec2be5b337529211ecaaf6cd4
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"
14 // static
15 ExtensionFunctionRegistry* ExtensionFunctionRegistry::GetInstance() {
16 return Singleton<ExtensionFunctionRegistry>::get();
19 ExtensionFunctionRegistry::ExtensionFunctionRegistry() {
20 ResetFunctions();
23 ExtensionFunctionRegistry::~ExtensionFunctionRegistry() {
26 void ExtensionFunctionRegistry::ResetFunctions() {
27 #if defined(ENABLE_EXTENSIONS)
29 // Register all functions here.
31 // WebRequest.
32 RegisterFunction<WebRequestAddEventListener>();
33 RegisterFunction<WebRequestEventHandled>();
35 // Preferences.
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>();
43 RegisterFunction<
44 extensions::chromedirectsetting::ClearDirectSettingFunction>();
46 // Runtime
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>();
57 // Generated APIs
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()) {
74 return false;
75 } else {
76 iter->second.factory_ = factory;
77 return true;
81 ExtensionFunction* ExtensionFunctionRegistry::NewFunction(
82 const std::string& name) {
83 FactoryMap::iterator iter = factories_.find(name);
84 if (iter == factories_.end()) {
85 return NULL;
87 ExtensionFunction* function = iter->second.factory_();
88 function->set_name(name);
89 function->set_histogram_value(iter->second.histogram_value_);
90 return function;
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) {