summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorkalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-23 12:57:12 +0000
committerkalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-23 12:57:12 +0000
commit4dffaf29261a76ac6a560facc33d0bbe951629d9 (patch)
tree098cd9c4f1f0c43b9e46799748c52adb0210458d /tools
parent9ec39638198bf85a5f19e74c81a0feb4326d5e73 (diff)
downloadchromium_src-4dffaf29261a76ac6a560facc33d0bbe951629d9.zip
chromium_src-4dffaf29261a76ac6a560facc33d0bbe951629d9.tar.gz
chromium_src-4dffaf29261a76ac6a560facc33d0bbe951629d9.tar.bz2
Make ExtensionAPI load schemas lazily where possible.
BUG=118144 TEST=unit_tests --gtest_filter=ExtensionAPI.* Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=128434 Review URL: http://codereview.chromium.org/9677069 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128466 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
-rw-r--r--tools/json_schema_compiler/model.py1
-rw-r--r--tools/json_schema_compiler/schema_bundle_generator.py44
2 files changed, 20 insertions, 25 deletions
diff --git a/tools/json_schema_compiler/model.py b/tools/json_schema_compiler/model.py
index cb569c6..96b2a59 100644
--- a/tools/json_schema_compiler/model.py
+++ b/tools/json_schema_compiler/model.py
@@ -306,6 +306,7 @@ class PropertyType(object):
def UnixName(name):
"""Returns the unix_style name for a given lowerCamelCase string.
"""
+ name = name.replace('.', '_')
return '_'.join([x.lower()
for x in re.findall('[A-Z][a-z_]*', name[0].upper() + name[1:])])
diff --git a/tools/json_schema_compiler/schema_bundle_generator.py b/tools/json_schema_compiler/schema_bundle_generator.py
index f37dc6c..6a842fc7 100644
--- a/tools/json_schema_compiler/schema_bundle_generator.py
+++ b/tools/json_schema_compiler/schema_bundle_generator.py
@@ -93,16 +93,19 @@ class SchemaBundleGenerator(object):
def GenerateSchemasHeader(self):
"""Generates a code.Code object for the generated schemas .h file"""
c = code.Code()
- c.Append('namespace base {')
- c.Append('class ListValue;')
- c.Append('}')
+ c.Append('#include <map>')
+ c.Append('#include <string>')
+ c.Append();
+ c.Append('#include "base/string_piece.h"')
c.Append()
c.Concat(self._cpp_type_generator.GetRootNamespaceStart())
c.Append()
- c.Sblock("class GeneratedSchemas {")
- c.Append("public:")
- c.Append("static base::ListValue* Get();")
- c.Eblock("};");
+ c.Sblock('class GeneratedSchemas {')
+ c.Append('public:')
+ c.Append('// Puts all API schemas in |schemas|.')
+ c.Append('static void Get('
+ 'std::map<std::string, base::StringPiece>* schemas);')
+ c.Eblock('};');
c.Append()
c.Concat(self._cpp_type_generator.GetRootNamespaceEnd())
c.Append()
@@ -116,32 +119,23 @@ class SchemaBundleGenerator(object):
c.Append('#include "%s"' % (os.path.join(SOURCE_BASE_PATH,
'generated_schemas.h')))
c.Append()
- c.Append('#include "base/json/json_reader.h"')
- c.Append('#include "base/values.h"')
- c.Append()
- c.Append('using base::ListValue;')
- c.Append()
c.Concat(self._cpp_type_generator.GetRootNamespaceStart())
c.Append()
- c.Sblock('ListValue* GeneratedSchemas::Get() {')
- c.Append('ListValue* list = new ListValue();')
+ c.Append('// static')
+ c.Sblock('void GeneratedSchemas::Get('
+ 'std::map<std::string, base::StringPiece>* schemas) {')
for api in self._api_defs:
- c.Sblock('{')
- c.Sblock('const char tmp[] =')
- json_content = json.dumps(api, indent=2)
+ namespace = self._model.namespaces[api.get('namespace')]
+ # JSON parsing code expects lists of schemas, so dump a singleton list.
+ json_content = json.dumps([api], indent=2)
json_content = json_content.replace('"', '\\"')
lines = json_content.split('\n')
- for index,line in enumerate(lines):
- line = '"%s"' % line
+ c.Append('(*schemas)["%s"] = ' % namespace.name)
+ for index, line in enumerate(lines):
+ line = ' "%s"' % line
if index == len(lines) - 1:
line += ';'
c.Append(line)
- c.Eblock()
- c.Append('Value* val = base::JSONReader::Read(std::string(tmp), false);')
- c.Append('list->Append(val);')
- c.Eblock('}')
-
- c.Append('return list;')
c.Eblock('}')
c.Append()
c.Concat(self._cpp_type_generator.GetRootNamespaceEnd())