OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 posixpath | 5 import posixpath |
6 | 6 |
7 from compiled_file_system import Cache, SingleFile, Unicode | 7 from compiled_file_system import Cache, SingleFile, Unicode |
8 from extensions_paths import API_PATHS | 8 from extensions_paths import API_PATHS |
9 from features_bundle import HasParent, GetParentName | 9 from features_bundle import HasParent, GetParentName |
10 from file_system import FileNotFoundError | 10 from file_system import FileNotFoundError |
11 from future import All, Future, Race | 11 from future import All, Future, Race |
12 from operator import itemgetter | 12 from operator import itemgetter |
13 from path_util import Join | 13 from path_util import Join |
14 from platform_util import PlatformToExtensionType | 14 from platform_util import PlatformToExtensionType |
15 from schema_util import ProcessSchema | 15 from process_schema import ProcessSchema, ProcessSchemaFactory |
16 from third_party.json_schema_compiler.json_schema import DeleteNodes | 16 from third_party.json_schema_compiler.json_schema import DeleteNodes |
17 from third_party.json_schema_compiler.model import Namespace, UnixName | 17 from third_party.json_schema_compiler.model import Namespace, UnixName |
18 | 18 |
19 | 19 |
20 def GetNodeCategories(): | 20 def GetNodeCategories(): |
21 '''Returns a tuple of the possible categories a node may belong to. | 21 '''Returns a tuple of the possible categories a node may belong to. |
22 ''' | 22 ''' |
23 return ('types', 'functions', 'events', 'properties') | 23 return ('types', 'functions', 'events', 'properties') |
24 | 24 |
25 | 25 |
(...skipping 24 matching lines...) Expand all Loading... |
50 | 50 |
51 class APIModels(object): | 51 class APIModels(object): |
52 '''Tracks APIs and their Models. | 52 '''Tracks APIs and their Models. |
53 ''' | 53 ''' |
54 | 54 |
55 def __init__(self, | 55 def __init__(self, |
56 features_bundle, | 56 features_bundle, |
57 compiled_fs_factory, | 57 compiled_fs_factory, |
58 file_system, | 58 file_system, |
59 object_store_creator, | 59 object_store_creator, |
60 platform): | 60 platform, |
| 61 process_schema_factory): |
61 self._features_bundle = features_bundle | 62 self._features_bundle = features_bundle |
62 self._platform = PlatformToExtensionType(platform) | 63 self._platform = PlatformToExtensionType(platform) |
63 self._model_cache = compiled_fs_factory.Create( | 64 self._model_cache = compiled_fs_factory.Create( |
64 file_system, self._CreateAPIModel, APIModels, category=self._platform) | 65 file_system, self._CreateAPIModel, APIModels, category=self._platform) |
65 self._object_store = object_store_creator.Create(APIModels) | 66 self._object_store = object_store_creator.Create(APIModels) |
| 67 self._process_schema = Future(callback=lambda: |
| 68 process_schema_factory.Create(False)) |
66 | 69 |
67 @Cache | 70 @Cache |
68 @SingleFile | 71 @SingleFile |
69 @Unicode | 72 @Unicode |
70 def _CreateAPIModel(self, path, data): | 73 def _CreateAPIModel(self, path, data): |
71 def does_not_include_platform(node): | 74 def does_not_include_platform(node): |
72 return ('extension_types' in node and | 75 return ('extension_types' in node and |
73 node['extension_types'] != 'all' and | 76 node['extension_types'] != 'all' and |
74 self._platform not in node['extension_types']) | 77 self._platform not in node['extension_types']) |
75 | 78 |
76 schema = ProcessSchema(path, data)[0] | 79 schema = self._process_schema.Get().Process(path, data)[0] |
77 if not schema: | 80 if not schema: |
78 raise ValueError('No schema for %s' % path) | 81 raise ValueError('No schema for %s' % path) |
79 return Namespace(DeleteNodes( | 82 return Namespace(DeleteNodes( |
80 schema, matcher=does_not_include_platform), schema['namespace']) | 83 schema, matcher=does_not_include_platform), path) |
81 | 84 |
82 def GetNames(self): | 85 def GetNames(self): |
83 # API names appear alongside some of their methods/events/etc in the | 86 # API names appear alongside some of their methods/events/etc in the |
84 # features file. APIs are those which either implicitly or explicitly have | 87 # features file. APIs are those which either implicitly or explicitly have |
85 # no parent feature (e.g. app, app.window, and devtools.inspectedWindow are | 88 # no parent feature (e.g. app, app.window, and devtools.inspectedWindow are |
86 # APIs; runtime.onConnectNative is not). | 89 # APIs; runtime.onConnectNative is not). |
87 api_features = self._features_bundle.GetAPIFeatures().Get() | 90 api_features = self._features_bundle.GetAPIFeatures().Get() |
88 return [name for name, feature in api_features.iteritems() | 91 return [name for name, feature in api_features.iteritems() |
89 if not HasParent(name, feature, api_features)] | 92 if not HasParent(name, feature, api_features)] |
90 | 93 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 177 |
175 def IterModels(self): | 178 def IterModels(self): |
176 future_models = [(name, self.GetModel(name)) for name in self.GetNames()] | 179 future_models = [(name, self.GetModel(name)) for name in self.GetNames()] |
177 for name, future_model in future_models: | 180 for name, future_model in future_models: |
178 try: | 181 try: |
179 model = future_model.Get() | 182 model = future_model.Get() |
180 except FileNotFoundError: | 183 except FileNotFoundError: |
181 continue | 184 continue |
182 if model: | 185 if model: |
183 yield name, model | 186 yield name, model |
OLD | NEW |