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

Unified Diff: tools/json_schema_compiler/cpp_bundle_generator.py

Issue 15091002: Lazily load API schemas from resource files and convert all APIs to features (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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
Index: tools/json_schema_compiler/cpp_bundle_generator.py
diff --git a/tools/json_schema_compiler/cpp_bundle_generator.py b/tools/json_schema_compiler/cpp_bundle_generator.py
index 453e4466cc03a240007ce3f26c959897c03770a8..2349fa3e6580ec02936213b81fd9265c6c1aae54 100644
--- a/tools/json_schema_compiler/cpp_bundle_generator.py
+++ b/tools/json_schema_compiler/cpp_bundle_generator.py
@@ -208,6 +208,7 @@ class _SchemasHGenerator(object):
c = code.Code()
c.Append('#include <map>')
c.Append('#include <string>')
+ c.Append('#include <vector>')
c.Append();
c.Append('#include "base/strings/string_piece.h"')
c.Append()
@@ -215,9 +216,11 @@ class _SchemasHGenerator(object):
c.Append()
c.Append('class GeneratedSchemas {')
c.Sblock(' public:')
+ c.Append('// Puts names for all the schemas in |schemas|.')
+ c.Append('static void GetNames('
+ 'std::vector<std::string>* names);')
c.Append('// Puts all API schemas in |schemas|.')
not at google - send to devlin 2013/05/10 02:46:45 comment is now wrong
cduvall 2013/05/10 03:31:07 Done.
- c.Append('static void Get('
- 'std::map<std::string, base::StringPiece>* schemas);')
+ c.Append('static base::StringPiece Get(const std::string& name);')
c.Eblock('};');
c.Append()
c.Concat(cpp_util.CloseNamespace(self._bundle._cpp_namespace))
@@ -239,8 +242,16 @@ class _SchemasCCGenerator(object):
c.Concat(cpp_util.OpenNamespace(self._bundle._cpp_namespace))
c.Append()
c.Append('// static')
- c.Sblock('void GeneratedSchemas::Get('
- 'std::map<std::string, base::StringPiece>* schemas) {')
+ c.Sblock('void GeneratedSchemas::GetNames('
+ 'std::vector<std::string>* names) {')
+ for api in self._bundle._api_defs:
+ namespace = self._bundle._model.namespaces[api.get('namespace')]
+ c.Append('names->push_back("%s");' % namespace.name)
+ c.Eblock('}')
+ c.Append()
+ c.Append('// static')
+ c.Sblock('base::StringPiece GeneratedSchemas::Get('
+ 'const std::string& name) {')
for api in self._bundle._api_defs:
namespace = self._bundle._model.namespaces[api.get('namespace')]
# JSON parsing code expects lists of schemas, so dump a singleton list.
@@ -249,7 +260,10 @@ class _SchemasCCGenerator(object):
# Escape all double-quotes and backslashes. For this to output a valid
# JSON C string, we need to escape \ and ".
json_content = json_content.replace('\\', '\\\\').replace('"', '\\"')
- c.Append('(*schemas)["%s"] = "%s";' % (namespace.name, json_content))
+ c.Sblock('if (name == "%s") {' % namespace.name)
+ c.Append('return "%s";' % json_content)
+ c.Eblock('}')
+ c.Append('return "";');
c.Eblock('}')
c.Append()
c.Concat(cpp_util.CloseNamespace(self._bundle._cpp_namespace))
« chrome/renderer/extensions/dispatcher.cc ('K') | « chrome/renderer/extensions/dispatcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698