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

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

Issue 246423002: Split feature definitions into extensions and chrome features. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: repack2 Created 6 years, 7 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 | Annotate | Revision Log
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 ( 8 from extensions_paths import API_PATHS, JSON_TEMPLATES
9 API_FEATURES, JSON_TEMPLATES, MANIFEST_FEATURES, PERMISSION_FEATURES)
10 import features_utility 9 import features_utility
11 from file_system import FileNotFoundError 10 from file_system import FileNotFoundError
12 from future import Future 11 from future import Future
13 from third_party.json_schema_compiler.json_parse import Parse 12 from third_party.json_schema_compiler.json_parse import Parse
14 13
15 14
15 _API_FEATURES = '_api_features.json'
16 _MANIFEST_FEATURES = '_manifest_features.json'
17 _PERMISSION_FEATURES = '_permission_features.json'
18
19
20 def _GetFeaturePaths(feature_file, *extra_paths):
21 paths = [posixpath.join(api_path, feature_file) for api_path in API_PATHS]
22 paths.extend(extra_paths)
23 return paths
24
25
16 def _AddPlatformsFromDependencies(feature, 26 def _AddPlatformsFromDependencies(feature,
17 api_features, 27 api_features,
18 manifest_features, 28 manifest_features,
19 permission_features): 29 permission_features):
20 features_map = { 30 features_map = {
21 'api': api_features, 31 'api': api_features,
22 'manifest': manifest_features, 32 'manifest': manifest_features,
23 'permission': permission_features, 33 'permission': permission_features,
24 } 34 }
25 dependencies = feature.get('dependencies') 35 dependencies = feature.get('dependencies')
26 if dependencies is None: 36 if dependencies is None:
27 return ['apps', 'extensions'] 37 return ['apps', 'extensions']
28 platforms = set() 38 platforms = set()
29 for dependency in dependencies: 39 for dependency in dependencies:
30 dep_type, dep_name = dependency.split(':') 40 dep_type, dep_name = dependency.split(':')
31 dependency_features = features_map[dep_type] 41 dependency_features = features_map[dep_type]
32 dependency_feature = dependency_features.get(dep_name) 42 dependency_feature = dependency_features.get(dep_name)
33 # If the dependency can't be resolved, it is inaccessible and therefore 43 # If the dependency can't be resolved, it is inaccessible and therefore
34 # so is this feature. 44 # so is this feature.
35 if dependency_feature is None: 45 if dependency_feature is None:
36 return [] 46 return []
37 platforms = platforms.union(dependency_feature['platforms']) 47 platforms = platforms.union(dependency_feature['platforms'])
38 feature['platforms'] = list(platforms) 48 feature['platforms'] = list(platforms)
39 49
40 50
41 class _FeaturesCache(object): 51 class _FeaturesCache(object):
42 def __init__(self, file_system, compiled_fs_factory, *json_paths): 52 def __init__(self, file_system, compiled_fs_factory, json_paths):
43 populate = self._CreateCache 53 populate = self._CreateCache
44 if len(json_paths) == 1: 54 if len(json_paths) == 1:
45 populate = SingleFile(populate) 55 populate = SingleFile(populate)
46 56
47 self._cache = compiled_fs_factory.Create(file_system, populate, type(self)) 57 self._cache = compiled_fs_factory.Create(file_system, populate, type(self))
48 self._text_cache = compiled_fs_factory.ForUnicode(file_system) 58 self._text_cache = compiled_fs_factory.ForUnicode(file_system)
49 self._json_path = json_paths[0] 59 self._json_path = json_paths[0]
50 self._extra_paths = json_paths[1:] 60 self._extra_paths = json_paths[1:]
51 61
52 @Unicode 62 @Unicode
(...skipping 17 matching lines...) Expand all
70 return self._cache.GetFromFile(self._json_path) 80 return self._cache.GetFromFile(self._json_path)
71 81
72 82
73 class FeaturesBundle(object): 83 class FeaturesBundle(object):
74 '''Provides access to properties of API, Manifest, and Permission features. 84 '''Provides access to properties of API, Manifest, and Permission features.
75 ''' 85 '''
76 def __init__(self, file_system, compiled_fs_factory, object_store_creator): 86 def __init__(self, file_system, compiled_fs_factory, object_store_creator):
77 self._api_cache = _FeaturesCache( 87 self._api_cache = _FeaturesCache(
78 file_system, 88 file_system,
79 compiled_fs_factory, 89 compiled_fs_factory,
80 API_FEATURES) 90 _GetFeaturePaths(_API_FEATURES))
81 self._manifest_cache = _FeaturesCache( 91 self._manifest_cache = _FeaturesCache(
82 file_system, 92 file_system,
83 compiled_fs_factory, 93 compiled_fs_factory,
84 MANIFEST_FEATURES, 94 _GetFeaturePaths(_MANIFEST_FEATURES,
85 posixpath.join(JSON_TEMPLATES, 'manifest.json')) 95 posixpath.join(JSON_TEMPLATES, 'manifest.json')))
86 self._permission_cache = _FeaturesCache( 96 self._permission_cache = _FeaturesCache(
87 file_system, 97 file_system,
88 compiled_fs_factory, 98 compiled_fs_factory,
89 PERMISSION_FEATURES, 99 _GetFeaturePaths(_PERMISSION_FEATURES,
90 posixpath.join(JSON_TEMPLATES, 'permissions.json')) 100 posixpath.join(JSON_TEMPLATES, 'permissions.json')))
91 # Namespace the object store by the file system ID because this class is 101 # Namespace the object store by the file system ID because this class is
92 # used by the availability finder cross-channel. 102 # used by the availability finder cross-channel.
93 # TODO(kalman): Configure this at the ObjectStore level. 103 # TODO(kalman): Configure this at the ObjectStore level.
94 self._object_store = object_store_creator.Create( 104 self._object_store = object_store_creator.Create(
95 _FeaturesCache, category=file_system.GetIdentity()) 105 _FeaturesCache, category=file_system.GetIdentity())
96 106
97 def GetPermissionFeatures(self): 107 def GetPermissionFeatures(self):
98 return self._permission_cache.GetFeatures() 108 return self._permission_cache.GetFeatures()
99 109
100 def GetManifestFeatures(self): 110 def GetManifestFeatures(self):
(...skipping 14 matching lines...) Expand all
115 # TODO(rockot): Handle inter-API dependencies more gracefully. 125 # TODO(rockot): Handle inter-API dependencies more gracefully.
116 # Not yet a problem because there is only one such case (windows -> tabs). 126 # 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 127 # If we don't store this value before annotating platforms, inter-API
118 # dependencies will lead to infinite recursion. 128 # dependencies will lead to infinite recursion.
119 for feature in api_features.itervalues(): 129 for feature in api_features.itervalues():
120 _AddPlatformsFromDependencies( 130 _AddPlatformsFromDependencies(
121 feature, api_features, manifest_features, permission_features) 131 feature, api_features, manifest_features, permission_features)
122 self._object_store.Set('api_features', api_features) 132 self._object_store.Set('api_features', api_features)
123 return api_features 133 return api_features
124 return Future(callback=resolve) 134 return Future(callback=resolve)
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/extensions_paths.py ('k') | chrome/renderer/extensions/dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698