| OLD | NEW |
| 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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 c.Sblock('Static() {') | 353 c.Sblock('Static() {') |
| 354 for api in self._bundle._api_defs: | 354 for api in self._bundle._api_defs: |
| 355 namespace = self._bundle._model.namespaces[api.get('namespace')] | 355 namespace = self._bundle._model.namespaces[api.get('namespace')] |
| 356 c.Append('schemas["%s"] = %s;' % (namespace.name, | 356 c.Append('schemas["%s"] = %s;' % (namespace.name, |
| 357 _FormatNameAsConstant(namespace.name))) | 357 _FormatNameAsConstant(namespace.name))) |
| 358 c.Eblock('}') | 358 c.Eblock('}') |
| 359 c.Append() | 359 c.Append() |
| 360 c.Append('std::map<std::string, const char*> schemas;') | 360 c.Append('std::map<std::string, const char*> schemas;') |
| 361 c.Eblock('};') | 361 c.Eblock('};') |
| 362 c.Append() | 362 c.Append() |
| 363 c.Append('base::LazyInstance<Static> g_lazy_instance;') | 363 c.Append('base::LazyInstance<Static>::DestructorAtExit g_lazy_instance;') |
| 364 c.Append() | 364 c.Append() |
| 365 c.Append('} // namespace') | 365 c.Append('} // namespace') |
| 366 c.Append() | 366 c.Append() |
| 367 c.Concat(cpp_util.OpenNamespace(self._bundle._cpp_namespace)) | 367 c.Concat(cpp_util.OpenNamespace(self._bundle._cpp_namespace)) |
| 368 c.Append() | 368 c.Append() |
| 369 c.Append('// static') | 369 c.Append('// static') |
| 370 c.Sblock('base::StringPiece %s::Get(const std::string& name) {' % | 370 c.Sblock('base::StringPiece %s::Get(const std::string& name) {' % |
| 371 self._bundle._GenerateBundleClass('GeneratedSchemas')) | 371 self._bundle._GenerateBundleClass('GeneratedSchemas')) |
| 372 c.Append('return IsGenerated(name) ? ' | 372 c.Append('return IsGenerated(name) ? ' |
| 373 'g_lazy_instance.Get().schemas[name] : "";') | 373 'g_lazy_instance.Get().schemas[name] : "";') |
| 374 c.Eblock('}') | 374 c.Eblock('}') |
| 375 c.Append() | 375 c.Append() |
| 376 c.Append('// static') | 376 c.Append('// static') |
| 377 c.Sblock('bool %s::IsGenerated(std::string name) {' % | 377 c.Sblock('bool %s::IsGenerated(std::string name) {' % |
| 378 self._bundle._GenerateBundleClass('GeneratedSchemas')) | 378 self._bundle._GenerateBundleClass('GeneratedSchemas')) |
| 379 c.Append('return g_lazy_instance.Get().schemas.count(name) > 0;') | 379 c.Append('return g_lazy_instance.Get().schemas.count(name) > 0;') |
| 380 c.Eblock('}') | 380 c.Eblock('}') |
| 381 c.Append() | 381 c.Append() |
| 382 c.Concat(cpp_util.CloseNamespace(self._bundle._cpp_namespace)) | 382 c.Concat(cpp_util.CloseNamespace(self._bundle._cpp_namespace)) |
| 383 c.Append() | 383 c.Append() |
| 384 return c | 384 return c |
| OLD | NEW |