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

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

Powered by Google App Engine
This is Rietveld 408576698