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

Side by Side Diff: extensions/browser/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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_function_registry.h" 5 #include "extensions/browser/extension_function_registry.h"
6 6
7 #include "chrome/browser/extensions/api/preference/chrome_direct_setting.h" 7 #include "base/memory/singleton.h"
8 #include "chrome/browser/extensions/api/preference/preference_api.h" 8 #include "extensions/browser/extension_function.h"
9 #include "chrome/browser/extensions/api/runtime/runtime_api.h" 9 #include "extensions/browser/extensions_browser_client.h"
10 #include "chrome/browser/extensions/api/web_request/web_request_api.h" 10 #include "extensions/common/api/generated_api.h"
11 #include "chrome/common/extensions/api/generated_api.h"
12 11
13 // static 12 // static
14 ExtensionFunctionRegistry* ExtensionFunctionRegistry::GetInstance() { 13 ExtensionFunctionRegistry* ExtensionFunctionRegistry::GetInstance() {
15 return Singleton<ExtensionFunctionRegistry>::get(); 14 return Singleton<ExtensionFunctionRegistry>::get();
16 } 15 }
17 16
18 ExtensionFunctionRegistry::ExtensionFunctionRegistry() { 17 ExtensionFunctionRegistry::ExtensionFunctionRegistry() {
19 ResetFunctions(); 18 #if defined(ENABLE_EXTENSIONS)
Jeffrey Yasskin 2014/03/04 23:30:16 It's odd to have to #if this. Would extensions::Ex
James Cook 2014/03/04 23:55:06 Drive-by: I'm pretty sure ENABLE_EXTENSIONS is alw
Ken Rockot(use gerrit already) 2014/03/05 00:18:44 Oh, yeah, this sounds right to me. Done.
19 // TODO(rockot): Possibly also register generated API functions from
20 // src/extension/common/api here once they exist.
21 extensions::ExtensionsBrowserClient::Get()
22 ->RegisterAdditionalExtensionFunctions(this);
23 #endif
20 } 24 }
21 25
22 ExtensionFunctionRegistry::~ExtensionFunctionRegistry() { 26 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 27
57 void ExtensionFunctionRegistry::GetAllNames(std::vector<std::string>* names) { 28 void ExtensionFunctionRegistry::GetAllNames(std::vector<std::string>* names) {
58 for (FactoryMap::iterator iter = factories_.begin(); 29 for (FactoryMap::iterator iter = factories_.begin(); iter != factories_.end();
59 iter != factories_.end(); ++iter) { 30 ++iter) {
60 names->push_back(iter->first); 31 names->push_back(iter->first);
61 } 32 }
62 } 33 }
63 34
64 bool ExtensionFunctionRegistry::OverrideFunction( 35 bool ExtensionFunctionRegistry::OverrideFunction(
65 const std::string& name, 36 const std::string& name,
66 ExtensionFunctionFactory factory) { 37 ExtensionFunctionFactory factory) {
67 FactoryMap::iterator iter = factories_.find(name); 38 FactoryMap::iterator iter = factories_.find(name);
68 if (iter == factories_.end()) { 39 if (iter == factories_.end()) {
69 return false; 40 return false;
70 } else { 41 } else {
71 iter->second.factory_ = factory; 42 iter->second.factory_ = factory;
72 return true; 43 return true;
73 } 44 }
74 } 45 }
75 46
76 ExtensionFunction* ExtensionFunctionRegistry::NewFunction( 47 ExtensionFunction* ExtensionFunctionRegistry::NewFunction(
77 const std::string& name) { 48 const std::string& name) {
78 FactoryMap::iterator iter = factories_.find(name); 49 FactoryMap::iterator iter = factories_.find(name);
79 if (iter == factories_.end()) { 50 if (iter == factories_.end()) {
80 return NULL; 51 return NULL;
81 } 52 }
82 ExtensionFunction* function = iter->second.factory_(); 53 ExtensionFunction* function = iter->second.factory_();
83 function->set_name(name); 54 function->set_name(name);
84 function->set_histogram_value(iter->second.histogram_value_); 55 function->set_histogram_value(iter->second.histogram_value_);
85 return function; 56 return function;
86 } 57 }
87 58
88 ExtensionFunctionRegistry::FactoryEntry::FactoryEntry() 59 ExtensionFunctionRegistry::FactoryEntry::FactoryEntry()
89 : factory_(0), histogram_value_(extensions::functions::UNKNOWN) { 60 : factory_(0), histogram_value_(extensions::functions::UNKNOWN) {}
90 }
91 61
92 ExtensionFunctionRegistry::FactoryEntry::FactoryEntry( 62 ExtensionFunctionRegistry::FactoryEntry::FactoryEntry(
93 ExtensionFunctionFactory factory, 63 ExtensionFunctionFactory factory,
94 extensions::functions::HistogramValue histogram_value) 64 extensions::functions::HistogramValue histogram_value)
95 : factory_(factory), histogram_value_(histogram_value) { 65 : factory_(factory), histogram_value_(histogram_value) {}
96 }
OLDNEW
« no previous file with comments | « extensions/browser/extension_function_registry.h ('k') | extensions/browser/extensions_browser_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698