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

Side by Side Diff: chrome/common/extensions/docs/server2/features_bundle.py

Issue 302143003: Docserver: Make API features inherit 'channel' from their dependencies (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another test, cleanup Created 6 years, 6 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
OLDNEW
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 API_PATHS, JSON_TEMPLATES 8 from extensions_paths import API_PATHS, JSON_TEMPLATES
9 import features_utility 9 import features_utility
10 from file_system import FileNotFoundError 10 from file_system import FileNotFoundError
11 from future import Future 11 from future import Future
12 from third_party.json_schema_compiler.json_parse import Parse 12 from third_party.json_schema_compiler.json_parse import Parse
13 13
14 14
15 _API_FEATURES = '_api_features.json' 15 _API_FEATURES = '_api_features.json'
16 _MANIFEST_FEATURES = '_manifest_features.json' 16 _MANIFEST_FEATURES = '_manifest_features.json'
17 _PERMISSION_FEATURES = '_permission_features.json' 17 _PERMISSION_FEATURES = '_permission_features.json'
18 18
19 19
20 def _GetFeaturePaths(feature_file, *extra_paths): 20 def _GetFeaturePaths(feature_file, *extra_paths):
21 paths = [posixpath.join(api_path, feature_file) for api_path in API_PATHS] 21 paths = [posixpath.join(api_path, feature_file) for api_path in API_PATHS]
22 paths.extend(extra_paths) 22 paths.extend(extra_paths)
23 return paths 23 return paths
24 24
25 25
26 def _AddPlatformsFromDependencies(feature, 26 def _AddPlatformsAndChannelsFromDependencies(feature,
27 api_features, 27 api_features,
28 manifest_features, 28 manifest_features,
29 permission_features): 29 permission_features):
30 features_map = { 30 features_map = {
31 'api': api_features, 31 'api': api_features,
32 'manifest': manifest_features, 32 'manifest': manifest_features,
33 'permission': permission_features, 33 'permission': permission_features,
34 } 34 }
35 dependencies = feature.get('dependencies') 35 dependencies = feature.get('dependencies')
36 if dependencies is None: 36 if dependencies is None:
37 return ['apps', 'extensions'] 37 return
38 platforms = set() 38 platforms = set()
39 channel = None
39 for dependency in dependencies: 40 for dependency in dependencies:
40 dep_type, dep_name = dependency.split(':') 41 dep_type, dep_name = dependency.split(':')
41 dependency_features = features_map[dep_type] 42 dependency_features = features_map[dep_type]
42 dependency_feature = dependency_features.get(dep_name) 43 dependency_feature = dependency_features.get(dep_name)
43 # If the dependency can't be resolved, it is inaccessible and therefore 44 # If the dependency can't be resolved, it is inaccessible and therefore
44 # so is this feature. 45 # so is this feature.
45 if dependency_feature is None: 46 if dependency_feature is None:
46 return [] 47 return
47 platforms = platforms.union(dependency_feature['platforms']) 48 # Import the platforms from the dependency. The logic is a bit odd; if
48 feature['platforms'] = list(platforms) 49 # |feature| specifies platforms the it's considered an override. If not,
50 # we form the union of all dependency's platforms.
51 # TODO(kalman): Fix this (see http://crbug.com/322094).
52 platforms.update(dependency_feature.get('platforms', set()))
53 # Import the channel from the dependency.
54 channel = dependency_feature.get('channel', channel)
55 if platforms and not feature.get('platforms'):
56 feature['platforms'] = list(platforms)
57 if channel and not feature.get('channel'):
58 feature['channel'] = channel
49 59
50 60
51 class _FeaturesCache(object): 61 class _FeaturesCache(object):
52 def __init__(self, file_system, compiled_fs_factory, json_paths): 62 def __init__(self, file_system, compiled_fs_factory, json_paths):
53 populate = self._CreateCache 63 populate = self._CreateCache
54 if len(json_paths) == 1: 64 if len(json_paths) == 1:
55 populate = SingleFile(populate) 65 populate = SingleFile(populate)
56 66
57 self._cache = compiled_fs_factory.Create(file_system, populate, type(self)) 67 self._cache = compiled_fs_factory.Create(file_system, populate, type(self))
58 self._text_cache = compiled_fs_factory.ForUnicode(file_system) 68 self._text_cache = compiled_fs_factory.ForUnicode(file_system)
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 permission_features_future = self._permission_cache.GetFeatures() 129 permission_features_future = self._permission_cache.GetFeatures()
120 def resolve(): 130 def resolve():
121 api_features = api_features_future.Get() 131 api_features = api_features_future.Get()
122 manifest_features = manifest_features_future.Get() 132 manifest_features = manifest_features_future.Get()
123 permission_features = permission_features_future.Get() 133 permission_features = permission_features_future.Get()
124 # TODO(rockot): Handle inter-API dependencies more gracefully. 134 # TODO(rockot): Handle inter-API dependencies more gracefully.
125 # Not yet a problem because there is only one such case (windows -> tabs). 135 # Not yet a problem because there is only one such case (windows -> tabs).
126 # If we don't store this value before annotating platforms, inter-API 136 # If we don't store this value before annotating platforms, inter-API
127 # dependencies will lead to infinite recursion. 137 # dependencies will lead to infinite recursion.
128 for feature in api_features.itervalues(): 138 for feature in api_features.itervalues():
129 _AddPlatformsFromDependencies( 139 _AddPlatformsAndChannelsFromDependencies(
130 feature, api_features, manifest_features, permission_features) 140 feature, api_features, manifest_features, permission_features)
131 self._object_store.Set('api_features', api_features) 141 self._object_store.Set('api_features', api_features)
132 return api_features 142 return api_features
133 return Future(callback=resolve) 143 return Future(callback=resolve)
134 144
135 def GetIdentity(self): 145 def GetIdentity(self):
136 return self._identity 146 return self._identity
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/cron.yaml ('k') | chrome/common/extensions/docs/server2/features_bundle_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698