Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: chrome/browser/extensions/extension_function_registry.cc

Issue 185293017: Move ExtensionFunctionRegistry out of src/chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/extensions/extension_function_registry.h"
6
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"
12
13 // static
14 ExtensionFunctionRegistry* ExtensionFunctionRegistry::GetInstance() {
15 return Singleton<ExtensionFunctionRegistry>::get();
16 }
17
18 ExtensionFunctionRegistry::ExtensionFunctionRegistry() {
19 ResetFunctions();
20 }
21
22 ExtensionFunctionRegistry::~ExtensionFunctionRegistry() {
23 }
24
25 void ExtensionFunctionRegistry::ResetFunctions() {
26 #if defined(ENABLE_EXTENSIONS)
27
28 // Register all functions here.
29
30 // WebRequest.
31 RegisterFunction<WebRequestAddEventListener>();
32 RegisterFunction<WebRequestEventHandled>();
33
34 // Preferences.
35 RegisterFunction<extensions::GetPreferenceFunction>();
36 RegisterFunction<extensions::SetPreferenceFunction>();
37 RegisterFunction<extensions::ClearPreferenceFunction>();
38
39 // Direct Preference Access for Component Extensions.
40 RegisterFunction<extensions::chromedirectsetting::GetDirectSettingFunction>();
41 RegisterFunction<extensions::chromedirectsetting::SetDirectSettingFunction>();
42 RegisterFunction<
43 extensions::chromedirectsetting::ClearDirectSettingFunction>();
44
45 // Runtime
46 RegisterFunction<extensions::RuntimeGetBackgroundPageFunction>();
47 RegisterFunction<extensions::RuntimeSetUninstallURLFunction>();
48 RegisterFunction<extensions::RuntimeReloadFunction>();
49 RegisterFunction<extensions::RuntimeRequestUpdateCheckFunction>();
50 RegisterFunction<extensions::RuntimeRestartFunction>();
51
52 // Generated APIs
53 extensions::api::GeneratedFunctionRegistry::RegisterAll(this);
54 #endif // defined(ENABLE_EXTENSIONS)
55 }
56
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);
61 }
62 }
63
64 bool ExtensionFunctionRegistry::OverrideFunction(
65 const std::string& name,
66 ExtensionFunctionFactory factory) {
67 FactoryMap::iterator iter = factories_.find(name);
68 if (iter == factories_.end()) {
69 return false;
70 } else {
71 iter->second.factory_ = factory;
72 return true;
73 }
74 }
75
76 ExtensionFunction* ExtensionFunctionRegistry::NewFunction(
77 const std::string& name) {
78 FactoryMap::iterator iter = factories_.find(name);
79 if (iter == factories_.end()) {
80 return NULL;
81 }
82 ExtensionFunction* function = iter->second.factory_();
83 function->set_name(name);
84 function->set_histogram_value(iter->second.histogram_value_);
85 return function;
86 }
87
88 ExtensionFunctionRegistry::FactoryEntry::FactoryEntry()
89 : factory_(0), histogram_value_(extensions::functions::UNKNOWN) {
90 }
91
92 ExtensionFunctionRegistry::FactoryEntry::FactoryEntry(
93 ExtensionFunctionFactory factory,
94 extensions::functions::HistogramValue histogram_value)
95 : factory_(factory), histogram_value_(histogram_value) {
96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698