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

Side by Side 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 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 import code 5 import code
6 import cpp_util 6 import cpp_util
7 from model import Platforms 7 from model import Platforms
8 from schema_util import CapitalizeFirstLetter 8 from schema_util import CapitalizeFirstLetter
9 from schema_util import JsFunctionNameToClassName 9 from schema_util import JsFunctionNameToClassName
10 10
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 201
202 class _SchemasHGenerator(object): 202 class _SchemasHGenerator(object):
203 """Generates a code.Code object for the generated schemas .h file""" 203 """Generates a code.Code object for the generated schemas .h file"""
204 def __init__(self, cpp_bundle): 204 def __init__(self, cpp_bundle):
205 self._bundle = cpp_bundle 205 self._bundle = cpp_bundle
206 206
207 def Generate(self, namespace): 207 def Generate(self, namespace):
208 c = code.Code() 208 c = code.Code()
209 c.Append('#include <map>') 209 c.Append('#include <map>')
210 c.Append('#include <string>') 210 c.Append('#include <string>')
211 c.Append('#include <vector>')
211 c.Append(); 212 c.Append();
212 c.Append('#include "base/strings/string_piece.h"') 213 c.Append('#include "base/strings/string_piece.h"')
213 c.Append() 214 c.Append()
214 c.Concat(cpp_util.OpenNamespace(self._bundle._cpp_namespace)) 215 c.Concat(cpp_util.OpenNamespace(self._bundle._cpp_namespace))
215 c.Append() 216 c.Append()
216 c.Append('class GeneratedSchemas {') 217 c.Append('class GeneratedSchemas {')
217 c.Sblock(' public:') 218 c.Sblock(' public:')
219 c.Append('// Puts names for all the schemas in |schemas|.')
220 c.Append('static void GetNames('
221 'std::vector<std::string>* names);')
218 c.Append('// Puts all API schemas in |schemas|.') 222 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.
219 c.Append('static void Get(' 223 c.Append('static base::StringPiece Get(const std::string& name);')
220 'std::map<std::string, base::StringPiece>* schemas);')
221 c.Eblock('};'); 224 c.Eblock('};');
222 c.Append() 225 c.Append()
223 c.Concat(cpp_util.CloseNamespace(self._bundle._cpp_namespace)) 226 c.Concat(cpp_util.CloseNamespace(self._bundle._cpp_namespace))
224 return self._bundle._GenerateHeader('generated_schemas', c) 227 return self._bundle._GenerateHeader('generated_schemas', c)
225 228
226 class _SchemasCCGenerator(object): 229 class _SchemasCCGenerator(object):
227 """Generates a code.Code object for the generated schemas .cc file""" 230 """Generates a code.Code object for the generated schemas .cc file"""
228 231
229 def __init__(self, cpp_bundle): 232 def __init__(self, cpp_bundle):
230 self._bundle = cpp_bundle 233 self._bundle = cpp_bundle
231 234
232 def Generate(self, namespace): 235 def Generate(self, namespace):
233 c = code.Code() 236 c = code.Code()
234 c.Append(cpp_util.CHROMIUM_LICENSE) 237 c.Append(cpp_util.CHROMIUM_LICENSE)
235 c.Append() 238 c.Append()
236 c.Append('#include "%s"' % (os.path.join(SOURCE_BASE_PATH, 239 c.Append('#include "%s"' % (os.path.join(SOURCE_BASE_PATH,
237 'generated_schemas.h'))) 240 'generated_schemas.h')))
238 c.Append() 241 c.Append()
239 c.Concat(cpp_util.OpenNamespace(self._bundle._cpp_namespace)) 242 c.Concat(cpp_util.OpenNamespace(self._bundle._cpp_namespace))
240 c.Append() 243 c.Append()
241 c.Append('// static') 244 c.Append('// static')
242 c.Sblock('void GeneratedSchemas::Get(' 245 c.Sblock('void GeneratedSchemas::GetNames('
243 'std::map<std::string, base::StringPiece>* schemas) {') 246 'std::vector<std::string>* names) {')
247 for api in self._bundle._api_defs:
248 namespace = self._bundle._model.namespaces[api.get('namespace')]
249 c.Append('names->push_back("%s");' % namespace.name)
250 c.Eblock('}')
251 c.Append()
252 c.Append('// static')
253 c.Sblock('base::StringPiece GeneratedSchemas::Get('
254 'const std::string& name) {')
244 for api in self._bundle._api_defs: 255 for api in self._bundle._api_defs:
245 namespace = self._bundle._model.namespaces[api.get('namespace')] 256 namespace = self._bundle._model.namespaces[api.get('namespace')]
246 # JSON parsing code expects lists of schemas, so dump a singleton list. 257 # JSON parsing code expects lists of schemas, so dump a singleton list.
247 json_content = json.dumps([_RemoveDescriptions(api)], 258 json_content = json.dumps([_RemoveDescriptions(api)],
248 separators=(',', ':')) 259 separators=(',', ':'))
249 # Escape all double-quotes and backslashes. For this to output a valid 260 # Escape all double-quotes and backslashes. For this to output a valid
250 # JSON C string, we need to escape \ and ". 261 # JSON C string, we need to escape \ and ".
251 json_content = json_content.replace('\\', '\\\\').replace('"', '\\"') 262 json_content = json_content.replace('\\', '\\\\').replace('"', '\\"')
252 c.Append('(*schemas)["%s"] = "%s";' % (namespace.name, json_content)) 263 c.Sblock('if (name == "%s") {' % namespace.name)
264 c.Append('return "%s";' % json_content)
265 c.Eblock('}')
266 c.Append('return "";');
253 c.Eblock('}') 267 c.Eblock('}')
254 c.Append() 268 c.Append()
255 c.Concat(cpp_util.CloseNamespace(self._bundle._cpp_namespace)) 269 c.Concat(cpp_util.CloseNamespace(self._bundle._cpp_namespace))
256 c.Append() 270 c.Append()
257 return c 271 return c
OLDNEW
« 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