diff options
author | ncj674@motorola.com <ncj674@motorola.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-27 01:10:08 +0000 |
---|---|---|
committer | ncj674@motorola.com <ncj674@motorola.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-27 01:10:08 +0000 |
commit | 1392bb685601fc56abafa7db7f937e937dc86bcd (patch) | |
tree | b207137259f9c23067e52301aaad1a18b5ca0b6c | |
parent | 2647f6096c4f639415df15d1f7aa4760ac53fa7c (diff) | |
download | chromium_src-1392bb685601fc56abafa7db7f937e937dc86bcd.zip chromium_src-1392bb685601fc56abafa7db7f937e937dc86bcd.tar.gz chromium_src-1392bb685601fc56abafa7db7f937e937dc86bcd.tar.bz2 |
JSON compiler to prefix the function classes by their type's names.
BUG=159265
Review URL: https://chromiumcodereview.appspot.com/12330089
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@184813 0039d316-1c4b-4281-b951-d872f2087c98
11 files changed, 76 insertions, 70 deletions
diff --git a/chrome/browser/extensions/api/content_settings/content_settings_api.cc b/chrome/browser/extensions/api/content_settings/content_settings_api.cc index 0a82bcc..3f993a7 100644 --- a/chrome/browser/extensions/api/content_settings/content_settings_api.cc +++ b/chrome/browser/extensions/api/content_settings/content_settings_api.cc @@ -62,7 +62,7 @@ namespace extensions { namespace helpers = content_settings_helpers; namespace keys = content_settings_api_constants; -bool ContentSettingsClearFunction::RunImpl() { +bool ContentSettingsContentSettingClearFunction::RunImpl() { ContentSettingsType content_type; EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); @@ -96,7 +96,7 @@ bool ContentSettingsClearFunction::RunImpl() { return true; } -bool ContentSettingsGetFunction::RunImpl() { +bool ContentSettingsContentSettingGetFunction::RunImpl() { ContentSettingsType content_type; EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); @@ -169,7 +169,7 @@ bool ContentSettingsGetFunction::RunImpl() { return true; } -bool ContentSettingsSetFunction::RunImpl() { +bool ContentSettingsContentSettingSetFunction::RunImpl() { ContentSettingsType content_type; EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); @@ -250,7 +250,7 @@ bool ContentSettingsSetFunction::RunImpl() { return true; } -bool ContentSettingsGetResourceIdentifiersFunction::RunImpl() { +bool ContentSettingsContentSettingGetResourceIdentifiersFunction::RunImpl() { ContentSettingsType content_type; EXTENSION_FUNCTION_VALIDATE(RemoveContentType(args_.get(), &content_type)); @@ -261,7 +261,8 @@ bool ContentSettingsGetResourceIdentifiersFunction::RunImpl() { if (!g_testing_plugins_) { PluginService::GetInstance()->GetPlugins( - base::Bind(&ContentSettingsGetResourceIdentifiersFunction::OnGotPlugins, + base::Bind(&ContentSettingsContentSettingGetResourceIdentifiersFunction:: + OnGotPlugins, this)); } else { OnGotPlugins(*g_testing_plugins_); @@ -269,7 +270,7 @@ bool ContentSettingsGetResourceIdentifiersFunction::RunImpl() { return true; } -void ContentSettingsGetResourceIdentifiersFunction::OnGotPlugins( +void ContentSettingsContentSettingGetResourceIdentifiersFunction::OnGotPlugins( const std::vector<webkit::WebPluginInfo>& plugins) { PluginFinder* finder = PluginFinder::GetInstance(); std::set<std::string> group_identifiers; @@ -290,14 +291,15 @@ void ContentSettingsGetResourceIdentifiersFunction::OnGotPlugins( SetResult(list); BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, base::Bind( - &ContentSettingsGetResourceIdentifiersFunction::SendResponse, + &ContentSettingsContentSettingGetResourceIdentifiersFunction:: + SendResponse, this, true)); } // static -void ContentSettingsGetResourceIdentifiersFunction::SetPluginsForTesting( - const std::vector<webkit::WebPluginInfo>* plugins) { +void ContentSettingsContentSettingGetResourceIdentifiersFunction:: + SetPluginsForTesting(const std::vector<webkit::WebPluginInfo>* plugins) { g_testing_plugins_ = plugins; } diff --git a/chrome/browser/extensions/api/content_settings/content_settings_api.h b/chrome/browser/extensions/api/content_settings/content_settings_api.h index 8eacea3..dbd8ac1 100644 --- a/chrome/browser/extensions/api/content_settings/content_settings_api.h +++ b/chrome/browser/extensions/api/content_settings/content_settings_api.h @@ -15,47 +15,48 @@ struct WebPluginInfo; namespace extensions { -class ContentSettingsClearFunction : public SyncExtensionFunction { +class ContentSettingsContentSettingClearFunction + : public SyncExtensionFunction { public: DECLARE_EXTENSION_FUNCTION("contentSettings.clear", CONTENTSETTINGS_CLEAR) protected: - virtual ~ContentSettingsClearFunction() {} + virtual ~ContentSettingsContentSettingClearFunction() {} // ExtensionFunction: virtual bool RunImpl() OVERRIDE; }; -class ContentSettingsGetFunction : public SyncExtensionFunction { +class ContentSettingsContentSettingGetFunction : public SyncExtensionFunction { public: DECLARE_EXTENSION_FUNCTION("contentSettings.get", CONTENTSETTINGS_GET) protected: - virtual ~ContentSettingsGetFunction() {} + virtual ~ContentSettingsContentSettingGetFunction() {} // ExtensionFunction: virtual bool RunImpl() OVERRIDE; }; -class ContentSettingsSetFunction : public SyncExtensionFunction { +class ContentSettingsContentSettingSetFunction : public SyncExtensionFunction { public: DECLARE_EXTENSION_FUNCTION("contentSettings.set", CONTENTSETTINGS_SET) protected: - virtual ~ContentSettingsSetFunction() {} + virtual ~ContentSettingsContentSettingSetFunction() {} // ExtensionFunction: virtual bool RunImpl() OVERRIDE; }; -class ContentSettingsGetResourceIdentifiersFunction +class ContentSettingsContentSettingGetResourceIdentifiersFunction : public AsyncExtensionFunction { public: DECLARE_EXTENSION_FUNCTION("contentSettings.getResourceIdentifiers", CONTENTSETTINGS_GETRESOURCEIDENTIFIERS) protected: - virtual ~ContentSettingsGetResourceIdentifiersFunction() {} + virtual ~ContentSettingsContentSettingGetResourceIdentifiersFunction() {} // ExtensionFunction: virtual bool RunImpl() OVERRIDE; diff --git a/chrome/browser/extensions/api/content_settings/content_settings_apitest.cc b/chrome/browser/extensions/api/content_settings/content_settings_apitest.cc index f5a317d..a424f83 100644 --- a/chrome/browser/extensions/api/content_settings/content_settings_apitest.cc +++ b/chrome/browser/extensions/api/content_settings/content_settings_apitest.cc @@ -122,12 +122,14 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, std::vector<webkit::WebPluginInfo> plugins; plugin_list.GetPlugins(&plugins); - ContentSettingsGetResourceIdentifiersFunction::SetPluginsForTesting(&plugins); + ContentSettingsContentSettingGetResourceIdentifiersFunction:: + SetPluginsForTesting(&plugins); EXPECT_TRUE(RunExtensionTest("content_settings/getresourceidentifiers")) << message_; - ContentSettingsGetResourceIdentifiersFunction::SetPluginsForTesting(NULL); + ContentSettingsContentSettingGetResourceIdentifiersFunction:: + SetPluginsForTesting(NULL); } } // namespace extensions diff --git a/chrome/browser/extensions/api/declarative/declarative_api.cc b/chrome/browser/extensions/api/declarative/declarative_api.cc index 8c57352..3963823 100644 --- a/chrome/browser/extensions/api/declarative/declarative_api.cc +++ b/chrome/browser/extensions/api/declarative/declarative_api.cc @@ -61,7 +61,7 @@ bool RulesFunction::RunImpl() { return true; } -bool EventsAddRulesFunction::RunImplOnCorrectThread() { +bool EventsEventAddRulesFunction::RunImplOnCorrectThread() { scoped_ptr<AddRules::Params> params(AddRules::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); @@ -73,7 +73,7 @@ bool EventsAddRulesFunction::RunImplOnCorrectThread() { return error_.empty(); } -bool EventsRemoveRulesFunction::RunImplOnCorrectThread() { +bool EventsEventRemoveRulesFunction::RunImplOnCorrectThread() { scoped_ptr<RemoveRules::Params> params(RemoveRules::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); @@ -87,7 +87,7 @@ bool EventsRemoveRulesFunction::RunImplOnCorrectThread() { return error_.empty(); } -bool EventsGetRulesFunction::RunImplOnCorrectThread() { +bool EventsEventGetRulesFunction::RunImplOnCorrectThread() { scoped_ptr<GetRules::Params> params(GetRules::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); diff --git a/chrome/browser/extensions/api/declarative/declarative_api.h b/chrome/browser/extensions/api/declarative/declarative_api.h index df3c1c3..90e0e99 100644 --- a/chrome/browser/extensions/api/declarative/declarative_api.h +++ b/chrome/browser/extensions/api/declarative/declarative_api.h @@ -31,34 +31,34 @@ class RulesFunction : public AsyncExtensionFunction { scoped_refptr<RulesRegistry> rules_registry_; }; -class EventsAddRulesFunction : public RulesFunction { +class EventsEventAddRulesFunction : public RulesFunction { public: DECLARE_EXTENSION_FUNCTION("events.addRules", EVENTS_ADDRULES) protected: - virtual ~EventsAddRulesFunction() {} + virtual ~EventsEventAddRulesFunction() {} // RulesFunction: virtual bool RunImplOnCorrectThread() OVERRIDE; }; -class EventsRemoveRulesFunction : public RulesFunction { +class EventsEventRemoveRulesFunction : public RulesFunction { public: DECLARE_EXTENSION_FUNCTION("events.removeRules", EVENTS_REMOVERULES) protected: - virtual ~EventsRemoveRulesFunction() {} + virtual ~EventsEventRemoveRulesFunction() {} // RulesFunction: virtual bool RunImplOnCorrectThread() OVERRIDE; }; -class EventsGetRulesFunction : public RulesFunction { +class EventsEventGetRulesFunction : public RulesFunction { public: DECLARE_EXTENSION_FUNCTION("events.getRules", EVENTS_GETRULES) protected: - virtual ~EventsGetRulesFunction() {} + virtual ~EventsEventGetRulesFunction() {} // RulesFunction: virtual bool RunImplOnCorrectThread() OVERRIDE; diff --git a/chrome/browser/extensions/api/storage/storage_api.cc b/chrome/browser/extensions/api/storage/storage_api.cc index 8be3087..3cecd6b 100644 --- a/chrome/browser/extensions/api/storage/storage_api.cc +++ b/chrome/browser/extensions/api/storage/storage_api.cc @@ -162,7 +162,7 @@ void GetModificationQuotaLimitHeuristics(QuotaLimitHeuristics* heuristics) { } // namespace -bool StorageGetFunction::RunWithStorage(ValueStore* storage) { +bool StorageStorageAreaGetFunction::RunWithStorage(ValueStore* storage) { Value* input = NULL; EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &input)); @@ -201,7 +201,8 @@ bool StorageGetFunction::RunWithStorage(ValueStore* storage) { } } -bool StorageGetBytesInUseFunction::RunWithStorage(ValueStore* storage) { +bool StorageStorageAreaGetBytesInUseFunction::RunWithStorage( + ValueStore* storage) { Value* input = NULL; EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &input)); @@ -235,18 +236,18 @@ bool StorageGetBytesInUseFunction::RunWithStorage(ValueStore* storage) { return true; } -bool StorageSetFunction::RunWithStorage(ValueStore* storage) { +bool StorageStorageAreaSetFunction::RunWithStorage(ValueStore* storage) { DictionaryValue* input = NULL; EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &input)); return UseWriteResult(storage->Set(ValueStore::DEFAULTS, *input)); } -void StorageSetFunction::GetQuotaLimitHeuristics( +void StorageStorageAreaSetFunction::GetQuotaLimitHeuristics( QuotaLimitHeuristics* heuristics) const { GetModificationQuotaLimitHeuristics(heuristics); } -bool StorageRemoveFunction::RunWithStorage(ValueStore* storage) { +bool StorageStorageAreaRemoveFunction::RunWithStorage(ValueStore* storage) { Value* input = NULL; EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &input)); @@ -269,16 +270,16 @@ bool StorageRemoveFunction::RunWithStorage(ValueStore* storage) { }; } -void StorageRemoveFunction::GetQuotaLimitHeuristics( +void StorageStorageAreaRemoveFunction::GetQuotaLimitHeuristics( QuotaLimitHeuristics* heuristics) const { GetModificationQuotaLimitHeuristics(heuristics); } -bool StorageClearFunction::RunWithStorage(ValueStore* storage) { +bool StorageStorageAreaClearFunction::RunWithStorage(ValueStore* storage) { return UseWriteResult(storage->Clear()); } -void StorageClearFunction::GetQuotaLimitHeuristics( +void StorageStorageAreaClearFunction::GetQuotaLimitHeuristics( QuotaLimitHeuristics* heuristics) const { GetModificationQuotaLimitHeuristics(heuristics); } diff --git a/chrome/browser/extensions/api/storage/storage_api.h b/chrome/browser/extensions/api/storage/storage_api.h index 113d580..b3a5b4e 100644 --- a/chrome/browser/extensions/api/storage/storage_api.h +++ b/chrome/browser/extensions/api/storage/storage_api.h @@ -52,23 +52,23 @@ class SettingsFunction : public AsyncExtensionFunction { scoped_refptr<SettingsObserverList> observers_; }; -class StorageGetFunction : public SettingsFunction { +class StorageStorageAreaGetFunction : public SettingsFunction { public: DECLARE_EXTENSION_FUNCTION("storage.get", STORAGE_GET) protected: - virtual ~StorageGetFunction() {} + virtual ~StorageStorageAreaGetFunction() {} // SettingsFunction: virtual bool RunWithStorage(ValueStore* storage) OVERRIDE; }; -class StorageSetFunction : public SettingsFunction { +class StorageStorageAreaSetFunction : public SettingsFunction { public: DECLARE_EXTENSION_FUNCTION("storage.set", STORAGE_SET) protected: - virtual ~StorageSetFunction() {} + virtual ~StorageStorageAreaSetFunction() {} // SettingsFunction: virtual bool RunWithStorage(ValueStore* storage) OVERRIDE; @@ -78,12 +78,12 @@ class StorageSetFunction : public SettingsFunction { QuotaLimitHeuristics* heuristics) const OVERRIDE; }; -class StorageRemoveFunction : public SettingsFunction { +class StorageStorageAreaRemoveFunction : public SettingsFunction { public: DECLARE_EXTENSION_FUNCTION("storage.remove", STORAGE_REMOVE) protected: - virtual ~StorageRemoveFunction() {} + virtual ~StorageStorageAreaRemoveFunction() {} // SettingsFunction: virtual bool RunWithStorage(ValueStore* storage) OVERRIDE; @@ -93,12 +93,12 @@ class StorageRemoveFunction : public SettingsFunction { QuotaLimitHeuristics* heuristics) const OVERRIDE; }; -class StorageClearFunction : public SettingsFunction { +class StorageStorageAreaClearFunction : public SettingsFunction { public: DECLARE_EXTENSION_FUNCTION("storage.clear", STORAGE_CLEAR) protected: - virtual ~StorageClearFunction() {} + virtual ~StorageStorageAreaClearFunction() {} // SettingsFunction: virtual bool RunWithStorage(ValueStore* storage) OVERRIDE; @@ -108,12 +108,12 @@ class StorageClearFunction : public SettingsFunction { QuotaLimitHeuristics* heuristics) const OVERRIDE; }; -class StorageGetBytesInUseFunction : public SettingsFunction { +class StorageStorageAreaGetBytesInUseFunction : public SettingsFunction { public: DECLARE_EXTENSION_FUNCTION("storage.getBytesInUse", STORAGE_GETBYTESINUSE) protected: - virtual ~StorageGetBytesInUseFunction() {} + virtual ~StorageStorageAreaGetBytesInUseFunction() {} // SettingsFunction: virtual bool RunWithStorage(ValueStore* storage) OVERRIDE; diff --git a/chrome/common/extensions/api/content_settings.json b/chrome/common/extensions/api/content_settings.json index 0189560..5cb6935 100644 --- a/chrome/common/extensions/api/content_settings.json +++ b/chrome/common/extensions/api/content_settings.json @@ -5,9 +5,6 @@ [ { "namespace": "contentSettings", - "compiler_options": { - "generate_type_functions": true - }, "types": [ { "id": "ResourceIdentifier", diff --git a/chrome/common/extensions/api/events.json b/chrome/common/extensions/api/events.json index cb7d2b4..37ab89c 100644 --- a/chrome/common/extensions/api/events.json +++ b/chrome/common/extensions/api/events.json @@ -6,8 +6,7 @@ { "namespace": "events", "compiler_options": { - "implemented_in": "chrome/browser/extensions/api/declarative/declarative_api.h", - "generate_type_functions": true + "implemented_in": "chrome/browser/extensions/api/declarative/declarative_api.h" }, "internal": true, "unprivileged": true, diff --git a/chrome/common/extensions/api/storage.json b/chrome/common/extensions/api/storage.json index d3e56a2..47bfe10 100644 --- a/chrome/common/extensions/api/storage.json +++ b/chrome/common/extensions/api/storage.json @@ -6,9 +6,6 @@ { "namespace": "storage", "unprivileged": true, - "compiler_options": { - "generate_type_functions": true - }, "types": [ { "id": "StorageChange", diff --git a/tools/json_schema_compiler/cpp_bundle_generator.py b/tools/json_schema_compiler/cpp_bundle_generator.py index 8b153e8..e98f0c3 100644 --- a/tools/json_schema_compiler/cpp_bundle_generator.py +++ b/tools/json_schema_compiler/cpp_bundle_generator.py @@ -82,12 +82,19 @@ class CppBundleGenerator(object): raise ValueError("Unsupported platform ifdef: %s" % platform.name) return ' and '.join(ifdefs) - def _GetNamespaceFunctions(self, namespace): - functions = list(namespace.functions.values()) - if namespace.compiler_options.get("generate_type_functions", False): - for type_ in namespace.types.values(): - functions += list(type_.functions.values()) - return functions + def _GenerateRegisterFunctions(self, namespace_name, function): + c = code.Code() + function_ifdefs = self._GetPlatformIfdefs(function) + if function_ifdefs is not None: + c.Append("#if %s" % function_ifdefs, indent_level=0) + + function_name = JsFunctionNameToClassName(namespace_name, function.name) + c.Append("registry->RegisterFunction<%sFunction>();" % ( + function_name)) + + if function_ifdefs is not None: + c.Append("#endif // %s" % function_ifdefs, indent_level=0) + return c def _GenerateFunctionRegistryRegisterAll(self): c = code.Code() @@ -101,19 +108,19 @@ class CppBundleGenerator(object): namespace_name = CapitalizeFirstLetter(namespace.name.replace( "experimental.", "")) - for function in self._GetNamespaceFunctions(namespace): + for function in namespace.functions.values(): if function.nocompile: continue - function_ifdefs = self._GetPlatformIfdefs(function) - if function_ifdefs is not None: - c.Append("#if %s" % function_ifdefs, indent_level=0) - - function_name = JsFunctionNameToClassName(namespace.name, function.name) - c.Append("registry->RegisterFunction<%sFunction>();" % ( - function_name)) + c.Concat(self._GenerateRegisterFunctions(namespace.name, function)) - if function_ifdefs is not None: - c.Append("#endif // %s" % function_ifdefs, indent_level=0) + for type_ in namespace.types.values(): + for function in type_.functions.values(): + if function.nocompile: + continue + namespace_types_name = JsFunctionNameToClassName( + namespace.name, type_.name) + c.Concat(self._GenerateRegisterFunctions(namespace_types_name, + function)) if namespace_ifdefs is not None: c.Append("#endif // %s" % namespace_ifdefs, indent_level=0) |