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

Unified Diff: tools/json_schema_compiler/h_bundle_generator.py

Issue 9716003: Extract ExtensionFunctionRegistry from ExtensionFunctionDispatcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits; fix Windows build (thanks Brad Nelson!). Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/json_schema_compiler/cpp_util.py ('k') | tools/json_schema_compiler/h_generator.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/h_bundle_generator.py
diff --git a/tools/json_schema_compiler/h_bundle_generator.py b/tools/json_schema_compiler/h_bundle_generator.py
new file mode 100644
index 0000000000000000000000000000000000000000..5aa22d445f35ae25890420b10ffbcf4d009e4cd3
--- /dev/null
+++ b/tools/json_schema_compiler/h_bundle_generator.py
@@ -0,0 +1,79 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from model import PropertyType
+import code
+import cpp_util
+import model
+
+SOURCE_BASE_PATH = 'chrome/common/extensions/api'
+
+class HBundleGenerator(object):
+ """A .h generator for namespace bundle functionality.
+ """
+ def __init__(self, model, cpp_type_generator):
+ self._cpp_type_generator = cpp_type_generator
+ self._model = model
+
+ def Generate(self):
+ """Generates a code.Code object with the .h for a bundle.
+ """
+ c = code.Code()
+ (c.Append(cpp_util.CHROMIUM_LICENSE)
+ .Append()
+ .Append(cpp_util.GENERATED_BUNDLE_FILE_MESSAGE % SOURCE_BASE_PATH)
+ .Append()
+ )
+
+ ifndef_name = cpp_util.GenerateIfndefName(SOURCE_BASE_PATH,
+ 'generated_api')
+ (c.Append('#ifndef %s' % ifndef_name)
+ .Append('#define %s' % ifndef_name)
+ .Append('#pragma once')
+ .Append()
+ .Append('#include <string>')
+ .Append()
+ .Append('#include "base/basictypes.h"'))
+
+ for namespace in self._model.namespaces.values():
+ namespace_name = namespace.name.replace(
+ "experimental.", "")
+ c.Append('#include "chrome/browser/extensions/api/%s/%s_api.h"' % (
+ namespace_name, namespace_name))
+
+ (c.Append()
+ .Append("class ExtensionFunctionRegistry;")
+ .Append())
+
+ c.Concat(self._cpp_type_generator.GetRootNamespaceStart())
+
+ for namespace in self._model.namespaces.values():
+ c.Append("// TODO(miket): emit code for %s" % (namespace.unix_name))
+ c.Append()
+
+ c.Concat(self.GenerateFunctionRegistry())
+
+ (c.Concat(self._cpp_type_generator.GetRootNamespaceEnd())
+ .Append()
+ .Append('#endif // %s' % ifndef_name)
+ .Append()
+ )
+ return c
+
+ def GenerateFunctionRegistry(self):
+ c = code.Code()
+ c.Sblock("class GeneratedFunctionRegistry {")
+ c.Append("public:")
+ c.Sblock("static void RegisterAll(ExtensionFunctionRegistry* registry) {")
+ for namespace in self._model.namespaces.values():
+ for function in namespace.functions.values():
+ namespace_name = namespace.name.replace(
+ "experimental.", "").capitalize()
+ function_name = namespace_name + function.name.capitalize()
+ c.Append("registry->RegisterFunction<%sFunction>();" % (
+ function_name))
+ c.Eblock("}")
+ c.Eblock("};")
+ c.Append()
+ return c
« no previous file with comments | « tools/json_schema_compiler/cpp_util.py ('k') | tools/json_schema_compiler/h_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698