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 SingleFile, 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, CHROME_API, EXTENSIONS_API, JSON_TEMPLATES, MANIFEST_FEATURES, |
10 PERMISSION_FEATURES) | |
10 import features_utility | 11 import features_utility |
11 from file_system import FileNotFoundError | 12 from file_system import FileNotFoundError |
12 from future import Future | 13 from future import Future |
13 from third_party.json_schema_compiler.json_parse import Parse | 14 from third_party.json_schema_compiler.json_parse import Parse |
14 | 15 |
15 | 16 |
17 def _GetFeaturePaths(feature_file, *extra_paths): | |
18 paths = [posixpath.join(CHROME_API, feature_file), | |
19 posixpath.join(EXTENSIONS_API, feature_file)] | |
Ken Rockot(use gerrit already)
2014/04/22 23:23:17
nit: It would be nice if this could just map from
| |
20 paths.extend(extra_paths) | |
21 return paths | |
22 | |
23 | |
16 def _AddPlatformsFromDependencies(feature, | 24 def _AddPlatformsFromDependencies(feature, |
17 api_features, | 25 api_features, |
18 manifest_features, | 26 manifest_features, |
19 permission_features): | 27 permission_features): |
20 features_map = { | 28 features_map = { |
21 'api': api_features, | 29 'api': api_features, |
22 'manifest': manifest_features, | 30 'manifest': manifest_features, |
23 'permission': permission_features, | 31 'permission': permission_features, |
24 } | 32 } |
25 dependencies = feature.get('dependencies') | 33 dependencies = feature.get('dependencies') |
26 if dependencies is None: | 34 if dependencies is None: |
27 return ['apps', 'extensions'] | 35 return ['apps', 'extensions'] |
28 platforms = set() | 36 platforms = set() |
29 for dependency in dependencies: | 37 for dependency in dependencies: |
30 dep_type, dep_name = dependency.split(':') | 38 dep_type, dep_name = dependency.split(':') |
31 dependency_features = features_map[dep_type] | 39 dependency_features = features_map[dep_type] |
32 dependency_feature = dependency_features.get(dep_name) | 40 dependency_feature = dependency_features.get(dep_name) |
33 # If the dependency can't be resolved, it is inaccessible and therefore | 41 # If the dependency can't be resolved, it is inaccessible and therefore |
34 # so is this feature. | 42 # so is this feature. |
35 if dependency_feature is None: | 43 if dependency_feature is None: |
36 return [] | 44 return [] |
37 platforms = platforms.union(dependency_feature['platforms']) | 45 platforms = platforms.union(dependency_feature['platforms']) |
38 feature['platforms'] = list(platforms) | 46 feature['platforms'] = list(platforms) |
39 | 47 |
40 | 48 |
41 class _FeaturesCache(object): | 49 class _FeaturesCache(object): |
42 def __init__(self, file_system, compiled_fs_factory, *json_paths): | 50 def __init__(self, file_system, compiled_fs_factory, json_paths): |
43 populate = self._CreateCache | 51 populate = self._CreateCache |
44 if len(json_paths) == 1: | 52 if len(json_paths) == 1: |
45 populate = SingleFile(populate) | 53 populate = SingleFile(populate) |
46 | 54 |
47 self._cache = compiled_fs_factory.Create(file_system, populate, type(self)) | 55 self._cache = compiled_fs_factory.Create(file_system, populate, type(self)) |
48 self._text_cache = compiled_fs_factory.ForUnicode(file_system) | 56 self._text_cache = compiled_fs_factory.ForUnicode(file_system) |
49 self._json_path = json_paths[0] | 57 self._json_path = json_paths[0] |
50 self._extra_paths = json_paths[1:] | 58 self._extra_paths = json_paths[1:] |
51 | 59 |
52 @Unicode | 60 @Unicode |
(...skipping 17 matching lines...) Expand all Loading... | |
70 return self._cache.GetFromFile(self._json_path) | 78 return self._cache.GetFromFile(self._json_path) |
71 | 79 |
72 | 80 |
73 class FeaturesBundle(object): | 81 class FeaturesBundle(object): |
74 '''Provides access to properties of API, Manifest, and Permission features. | 82 '''Provides access to properties of API, Manifest, and Permission features. |
75 ''' | 83 ''' |
76 def __init__(self, file_system, compiled_fs_factory, object_store_creator): | 84 def __init__(self, file_system, compiled_fs_factory, object_store_creator): |
77 self._api_cache = _FeaturesCache( | 85 self._api_cache = _FeaturesCache( |
78 file_system, | 86 file_system, |
79 compiled_fs_factory, | 87 compiled_fs_factory, |
80 API_FEATURES) | 88 _GetFeaturePaths(API_FEATURES)) |
81 self._manifest_cache = _FeaturesCache( | 89 self._manifest_cache = _FeaturesCache( |
82 file_system, | 90 file_system, |
83 compiled_fs_factory, | 91 compiled_fs_factory, |
84 MANIFEST_FEATURES, | 92 _GetFeaturePaths(MANIFEST_FEATURES, |
85 posixpath.join(JSON_TEMPLATES, 'manifest.json')) | 93 posixpath.join(JSON_TEMPLATES, 'manifest.json'))) |
86 self._permission_cache = _FeaturesCache( | 94 self._permission_cache = _FeaturesCache( |
87 file_system, | 95 file_system, |
88 compiled_fs_factory, | 96 compiled_fs_factory, |
89 PERMISSION_FEATURES, | 97 _GetFeaturePaths(PERMISSION_FEATURES, |
90 posixpath.join(JSON_TEMPLATES, 'permissions.json')) | 98 posixpath.join(JSON_TEMPLATES, 'permissions.json'))) |
91 # Namespace the object store by the file system ID because this class is | 99 # Namespace the object store by the file system ID because this class is |
92 # used by the availability finder cross-channel. | 100 # used by the availability finder cross-channel. |
93 # TODO(kalman): Configure this at the ObjectStore level. | 101 # TODO(kalman): Configure this at the ObjectStore level. |
94 self._object_store = object_store_creator.Create( | 102 self._object_store = object_store_creator.Create( |
95 _FeaturesCache, category=file_system.GetIdentity()) | 103 _FeaturesCache, category=file_system.GetIdentity()) |
96 | 104 |
97 def GetPermissionFeatures(self): | 105 def GetPermissionFeatures(self): |
98 return self._permission_cache.GetFeatures() | 106 return self._permission_cache.GetFeatures() |
99 | 107 |
100 def GetManifestFeatures(self): | 108 def GetManifestFeatures(self): |
(...skipping 14 matching lines...) Expand all Loading... | |
115 # TODO(rockot): Handle inter-API dependencies more gracefully. | 123 # TODO(rockot): Handle inter-API dependencies more gracefully. |
116 # Not yet a problem because there is only one such case (windows -> tabs). | 124 # Not yet a problem because there is only one such case (windows -> tabs). |
117 # If we don't store this value before annotating platforms, inter-API | 125 # If we don't store this value before annotating platforms, inter-API |
118 # dependencies will lead to infinite recursion. | 126 # dependencies will lead to infinite recursion. |
119 for feature in api_features.itervalues(): | 127 for feature in api_features.itervalues(): |
120 _AddPlatformsFromDependencies( | 128 _AddPlatformsFromDependencies( |
121 feature, api_features, manifest_features, permission_features) | 129 feature, api_features, manifest_features, permission_features) |
122 self._object_store.Set('api_features', api_features) | 130 self._object_store.Set('api_features', api_features) |
123 return api_features | 131 return api_features |
124 return Future(callback=resolve) | 132 return Future(callback=resolve) |
OLD | NEW |