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 Unicode | 7 from compiled_file_system import SingleFile, Unicode |
8 from extensions_paths import ( | 8 from extensions_paths import ( |
9 API_FEATURES, JSON_TEMPLATES, MANIFEST_FEATURES, PERMISSION_FEATURES) | 9 API_FEATURES, JSON_TEMPLATES, MANIFEST_FEATURES, PERMISSION_FEATURES) |
10 import features_utility | 10 import features_utility |
11 from file_system import FileNotFoundError | 11 from file_system import FileNotFoundError |
12 from future import Future | 12 from future import Future |
13 from third_party.json_schema_compiler.json_parse import Parse | 13 from third_party.json_schema_compiler.json_parse import Parse |
14 | 14 |
15 | 15 |
16 def _AddPlatformsFromDependencies(feature, | 16 def _AddPlatformsFromDependencies(feature, |
17 api_features, | 17 api_features, |
(...skipping 15 matching lines...) Expand all Loading... | |
33 # If the dependency can't be resolved, it is inaccessible and therefore | 33 # If the dependency can't be resolved, it is inaccessible and therefore |
34 # so is this feature. | 34 # so is this feature. |
35 if dependency_feature is None: | 35 if dependency_feature is None: |
36 return [] | 36 return [] |
37 platforms = platforms.union(dependency_feature['platforms']) | 37 platforms = platforms.union(dependency_feature['platforms']) |
38 feature['platforms'] = list(platforms) | 38 feature['platforms'] = list(platforms) |
39 | 39 |
40 | 40 |
41 class _FeaturesCache(object): | 41 class _FeaturesCache(object): |
42 def __init__(self, file_system, compiled_fs_factory, *json_paths): | 42 def __init__(self, file_system, compiled_fs_factory, *json_paths): |
43 self._cache = compiled_fs_factory.Create( | 43 populate = self._CreateCache |
44 file_system, self._CreateCache, type(self)) | 44 if len(json_paths) == 1: |
45 populate = SingleFile(populate) | |
not at google - send to devlin
2014/03/28 17:20:36
and this is a minor optimisation to stop us from r
| |
46 | |
47 self._cache = compiled_fs_factory.Create(file_system, populate, type(self)) | |
45 self._text_cache = compiled_fs_factory.ForUnicode(file_system) | 48 self._text_cache = compiled_fs_factory.ForUnicode(file_system) |
46 self._json_path = json_paths[0] | 49 self._json_path = json_paths[0] |
47 self._extra_paths = json_paths[1:] | 50 self._extra_paths = json_paths[1:] |
48 | 51 |
49 @Unicode | 52 @Unicode |
50 def _CreateCache(self, _, features_json): | 53 def _CreateCache(self, _, features_json): |
51 extra_path_futures = [self._text_cache.GetFromFile(path) | 54 extra_path_futures = [self._text_cache.GetFromFile(path) |
52 for path in self._extra_paths] | 55 for path in self._extra_paths] |
53 features = features_utility.Parse(Parse(features_json)) | 56 features = features_utility.Parse(Parse(features_json)) |
54 for path_future in extra_path_futures: | 57 for path_future in extra_path_futures: |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 # TODO(rockot): Handle inter-API dependencies more gracefully. | 115 # TODO(rockot): Handle inter-API dependencies more gracefully. |
113 # Not yet a problem because there is only one such case (windows -> tabs). | 116 # Not yet a problem because there is only one such case (windows -> tabs). |
114 # If we don't store this value before annotating platforms, inter-API | 117 # If we don't store this value before annotating platforms, inter-API |
115 # dependencies will lead to infinite recursion. | 118 # dependencies will lead to infinite recursion. |
116 for feature in api_features.itervalues(): | 119 for feature in api_features.itervalues(): |
117 _AddPlatformsFromDependencies( | 120 _AddPlatformsFromDependencies( |
118 feature, api_features, manifest_features, permission_features) | 121 feature, api_features, manifest_features, permission_features) |
119 self._object_store.Set('api_features', api_features) | 122 self._object_store.Set('api_features', api_features) |
120 return api_features | 123 return api_features |
121 return Future(callback=resolve) | 124 return Future(callback=resolve) |
OLD | NEW |