| 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 from data_source import DataSource | 8 from data_source import DataSource |
| 9 from extensions_paths import PRIVATE_TEMPLATES |
| 9 import features_utility as features | 10 import features_utility as features |
| 10 from future import Gettable, Future | 11 from future import Gettable, Future |
| 11 from svn_constants import PRIVATE_TEMPLATE_PATH | |
| 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 def _ListifyPermissions(permissions): | 15 def _ListifyPermissions(permissions): |
| 15 '''Filter out any permissions that do not have a description or with a name | 16 '''Filter out any permissions that do not have a description or with a name |
| 16 that ends with Private then sort permissions features by name into a list. | 17 that ends with Private then sort permissions features by name into a list. |
| 17 ''' | 18 ''' |
| 18 def filter_permissions(perm): | 19 def filter_permissions(perm): |
| 19 return 'description' in perm and not perm['name'].endswith('Private') | 20 return 'description' in perm and not perm['name'].endswith('Private') |
| 20 | 21 |
| 21 return sorted( | 22 return sorted( |
| 22 ifilter(filter_permissions, permissions.values()), | 23 ifilter(filter_permissions, permissions.values()), |
| 23 key=itemgetter('name')) | 24 key=itemgetter('name')) |
| 24 | 25 |
| 26 |
| 25 def _AddDependencyDescriptions(permissions, api_features): | 27 def _AddDependencyDescriptions(permissions, api_features): |
| 26 '''Use |api_features| to determine the dependencies APIs have on permissions. | 28 '''Use |api_features| to determine the dependencies APIs have on permissions. |
| 27 Add descriptions to |permissions| based on those dependencies. | 29 Add descriptions to |permissions| based on those dependencies. |
| 28 ''' | 30 ''' |
| 29 for name, permission in permissions.iteritems(): | 31 for name, permission in permissions.iteritems(): |
| 30 # Don't overwrite the description created by expanding a partial template. | 32 # Don't overwrite the description created by expanding a partial template. |
| 31 if 'partial' in permission or not permission['platforms']: | 33 if 'partial' in permission or not permission['platforms']: |
| 32 continue | 34 continue |
| 33 | 35 |
| 34 has_deps = False | 36 has_deps = False |
| (...skipping 21 matching lines...) Expand all Loading... |
| 56 def resolve(): | 58 def resolve(): |
| 57 permission_features = permission_features_future.Get() | 59 permission_features = permission_features_future.Get() |
| 58 _AddDependencyDescriptions(permission_features, api_features_future.Get()) | 60 _AddDependencyDescriptions(permission_features, api_features_future.Get()) |
| 59 | 61 |
| 60 # Turn partial templates into descriptions, ensure anchors are set. | 62 # Turn partial templates into descriptions, ensure anchors are set. |
| 61 for permission in permission_features.values(): | 63 for permission in permission_features.values(): |
| 62 if not 'anchor' in permission: | 64 if not 'anchor' in permission: |
| 63 permission['anchor'] = permission['name'] | 65 permission['anchor'] = permission['name'] |
| 64 if 'partial' in permission: | 66 if 'partial' in permission: |
| 65 permission['description'] = self._template_cache.GetFromFile('%s/%s' % | 67 permission['description'] = self._template_cache.GetFromFile('%s/%s' % |
| 66 (PRIVATE_TEMPLATE_PATH, permission['partial'])).Get() | 68 (PRIVATE_TEMPLATES, permission['partial'])).Get() |
| 67 del permission['partial'] | 69 del permission['partial'] |
| 68 | 70 |
| 69 def filter_for_platform(permissions, platform): | 71 def filter_for_platform(permissions, platform): |
| 70 return _ListifyPermissions(features.Filtered(permissions, platform)) | 72 return _ListifyPermissions(features.Filtered(permissions, platform)) |
| 71 return { | 73 return { |
| 72 'declare_apps': filter_for_platform(permission_features, 'apps'), | 74 'declare_apps': filter_for_platform(permission_features, 'apps'), |
| 73 'declare_extensions': filter_for_platform( | 75 'declare_extensions': filter_for_platform( |
| 74 permission_features, 'extensions') | 76 permission_features, 'extensions') |
| 75 } | 77 } |
| 76 return Future(delegate=Gettable(resolve)) | 78 return Future(delegate=Gettable(resolve)) |
| 77 | 79 |
| 78 def _GetCachedPermissionsData(self): | 80 def _GetCachedPermissionsData(self): |
| 79 data = self._object_store.Get('permissions_data').Get() | 81 data = self._object_store.Get('permissions_data').Get() |
| 80 if data is None: | 82 if data is None: |
| 81 data = self._CreatePermissionsData().Get() | 83 data = self._CreatePermissionsData().Get() |
| 82 self._object_store.Set('permissions_data', data) | 84 self._object_store.Set('permissions_data', data) |
| 83 return data | 85 return data |
| 84 | 86 |
| 85 def Cron(self): | 87 def Cron(self): |
| 86 return self._CreatePermissionsData() | 88 return self._CreatePermissionsData() |
| 87 | 89 |
| 88 def get(self, key): | 90 def get(self, key): |
| 89 return self._GetCachedPermissionsData().get(key) | 91 return self._GetCachedPermissionsData().get(key) |
| OLD | NEW |