Chromium Code Reviews| 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 from itertools import ifilter | 5 from itertools import ifilter |
| 6 from operator import itemgetter | 6 from operator import itemgetter |
| 7 | 7 |
| 8 import features_utility as features | 8 import features_utility as features |
| 9 from third_party.json_schema_compiler.json_parse import Parse | 9 from third_party.json_schema_compiler.json_parse import Parse |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 if dependency.startswith('permission:'): | 34 if dependency.startswith('permission:'): |
| 35 has_deps = True | 35 has_deps = True |
| 36 | 36 |
| 37 if has_deps: | 37 if has_deps: |
| 38 permission['partial'] = 'permissions/generic_description' | 38 permission['partial'] = 'permissions/generic_description' |
| 39 | 39 |
| 40 class PermissionsDataSource(object): | 40 class PermissionsDataSource(object): |
| 41 '''Load and format permissions features to be used by templates. Requries a | 41 '''Load and format permissions features to be used by templates. Requries a |
| 42 template data source be set before use. | 42 template data source be set before use. |
| 43 ''' | 43 ''' |
| 44 def __init__(self, | 44 def __init__(self, features_bundle): |
| 45 compiled_fs_factory, | 45 self._features_bundle = features_bundle |
| 46 file_system, | 46 self._cache = None |
| 47 api_features_path, | |
| 48 permissions_features_path, | |
| 49 permissions_json_path): | |
| 50 self._api_features_path = api_features_path | |
| 51 self._permissions_features_path = permissions_features_path | |
| 52 self._permissions_json_path = permissions_json_path | |
| 53 self._file_system = file_system | |
| 54 self._cache = compiled_fs_factory.Create( | |
| 55 self._CreatePermissionsDataSource, PermissionsDataSource) | |
| 56 | 47 |
| 57 def SetTemplateDataSource(self, template_data_source_factory): | 48 def SetTemplateDataSource(self, template_data_source_factory): |
| 58 '''Initialize a template data source to be used to render partial templates | 49 '''Initialize a template data source to be used to render partial templates |
| 59 into descriptions for permissions. Must be called before .get | 50 into descriptions for permissions. Must be called before .get |
| 60 ''' | 51 ''' |
| 61 self._template_data_source = template_data_source_factory.Create( | 52 self._template_data_source = template_data_source_factory.Create( |
| 62 None, {}) | 53 None, {}) |
| 63 | 54 |
| 64 def _CreatePermissionsDataSource(self, _, content): | 55 def _CreateCache(self): |
| 65 '''Combine the contents of |_permissions_json_path| and | 56 api_features = self._features_bundle.GetAPIFeatures() |
| 66 |_permissions_features_path|. Filter into lists, one for extensions and | 57 permission_features = self._features_bundle.GetPermissionFeatures() |
| 67 one for apps. | |
| 68 ''' | |
| 69 api_features = Parse(self._file_system.ReadSingle(self._api_features_path)) | |
| 70 | 58 |
| 71 def filter_for_platform(permissions, platform): | 59 def filter_for_platform(permissions, platform): |
| 72 return _ListifyPermissions(features.Filtered(permissions, platform)) | 60 return _ListifyPermissions(features.Filtered(permissions, platform)) |
| 73 | 61 |
| 74 permissions_json = Parse(self._file_system.ReadSingle( | |
| 75 self._permissions_json_path)) | |
| 76 permission_features = features.MergedWith( | |
| 77 features.Parse(Parse(content)), permissions_json) | |
| 78 | |
| 79 _AddDependencyDescriptions(permission_features, api_features) | 62 _AddDependencyDescriptions(permission_features, api_features) |
| 80 # Turn partial templates into descriptions, ensure anchors are set. | 63 # Turn partial templates into descriptions, ensure anchors are set. |
| 81 for permission in permission_features.values(): | 64 for permission in permission_features.values(): |
| 82 if not 'anchor' in permission: | 65 if not 'anchor' in permission: |
| 83 permission['anchor'] = permission['name'] | 66 permission['anchor'] = permission['name'] |
| 84 if 'partial' in permission: | 67 if 'partial' in permission: |
| 85 permission['description'] = self._template_data_source.get( | 68 permission['description'] = self._template_data_source.get( |
| 86 permission['partial']) | 69 permission['partial']) |
| 87 del permission['partial'] | 70 del permission['partial'] |
| 88 | 71 |
| 89 return { | 72 return { |
| 90 'declare_apps': filter_for_platform(permission_features, 'app'), | 73 'declare_apps': filter_for_platform(permission_features, 'apps'), |
| 91 'declare_extensions': filter_for_platform( | 74 'declare_extensions': filter_for_platform( |
| 92 permission_features, 'extension') | 75 permission_features, 'extensions') |
| 93 } | 76 } |
| 94 | 77 |
| 95 def get(self, key): | 78 def get(self, key): |
| 96 return self._cache.GetFromFile(self._permissions_features_path)[key] | 79 if self._cache is None: |
| 80 self._cache = self._CreateCache() | |
| 81 return self._cache.get(key) | |
|
not at google - send to devlin
2013/10/01 16:34:34
same comment as in manifest_data_source
Ken Rockot(use gerrit already)
2013/10/01 22:18:16
Done.
| |
| OLD | NEW |