Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 from functools import partial | |
| 6 | |
| 7 from features import Features | |
| 8 import features_utility | |
| 9 import svn_constants | |
| 10 from third_party.json_schema_compiler.json_parse import Parse | |
| 11 | |
| 12 class _FeaturesCache(object): | |
| 13 def __init__(self, file_system, compiled_fs_factory, json_paths): | |
|
not at google - send to devlin
2013/10/01 16:34:34
this json_paths thing is only necessary to support
Ken Rockot(use gerrit already)
2013/10/01 22:18:16
Done.
| |
| 14 self._file_system = file_system | |
| 15 self._cache = compiled_fs_factory.Create(self._CreateCache, type(self)) | |
| 16 if json_paths is None: | |
| 17 self._json_path = None | |
| 18 self._extra_paths = () | |
| 19 else: | |
| 20 self._json_path = json_paths[0] | |
| 21 self._extra_paths = json_paths[1:] | |
| 22 | |
| 23 def _CreateCache(self, _, features_json): | |
| 24 features = features_utility.Parse(Parse(features_json)) | |
| 25 for path in self._extra_paths: | |
| 26 extra_json = self._file_system.ReadSingle(path) | |
| 27 features = features_utility.MergedWith( | |
| 28 features_utility.Parse(Parse(extra_json)), features) | |
| 29 return features | |
| 30 | |
| 31 def GetFeatures(self): | |
| 32 if self._json_path is None: | |
| 33 return {} | |
| 34 return self._cache.GetFromFile(self._json_path) | |
| 35 | |
| 36 class FeaturesBundle(object): | |
| 37 '''Provides access to properties of API, Manifest, and Permission features.''' | |
|
not at google - send to devlin
2013/10/01 16:34:34
'''Foo
'''
not
'''Foo'''.
Ken Rockot(use gerrit already)
2013/10/01 22:18:16
Done.
| |
| 38 def __init__(self, | |
| 39 file_system, | |
| 40 compiled_fs_factory, | |
| 41 features_files_override=None): | |
| 42 if features_files_override is not None: | |
| 43 features_files = features_files_override | |
|
not at google - send to devlin
2013/10/01 16:34:34
rather than this, create a FakeFeaturesBundle clas
Ken Rockot(use gerrit already)
2013/10/01 22:18:16
Done.
| |
| 44 else: | |
| 45 features_files = { | |
| 46 'api': (svn_constants.API_FEATURES_PATH,), | |
| 47 'manifest': (svn_constants.MANIFEST_FEATURES_PATH, | |
| 48 svn_constants.MANIFEST_JSON_PATH), | |
| 49 'permission': (svn_constants.PERMISSION_FEATURES_PATH, | |
| 50 svn_constants.PERMISSIONS_JSON_PATH) | |
| 51 } | |
| 52 self._api_cache = _FeaturesCache( | |
| 53 file_system, | |
| 54 compiled_fs_factory, | |
| 55 features_files.get('api')) | |
| 56 self._manifest_cache = _FeaturesCache( | |
| 57 file_system, | |
| 58 compiled_fs_factory, | |
| 59 features_files.get('manifest')) | |
| 60 self._permission_cache = _FeaturesCache( | |
| 61 file_system, | |
| 62 compiled_fs_factory, | |
| 63 features_files.get('permission')) | |
| 64 # Store an intermediate cache of API features since we add annotations. | |
| 65 self._api_features = None | |
| 66 | |
| 67 def GetPermissionFeatures(self): | |
| 68 return self._permission_cache.GetFeatures() | |
| 69 | |
| 70 def GetManifestFeatures(self): | |
| 71 return self._manifest_cache.GetFeatures() | |
| 72 | |
| 73 def GetAPIFeatures(self, force_refresh=False): | |
|
not at google - send to devlin
2013/10/01 16:34:34
doesn't look like force_refresh is used.
Ken Rockot(use gerrit already)
2013/10/01 22:18:16
Oops. Was going to be used as a Cron hack. Shouldn
| |
| 74 if self._api_features is not None and not force_refresh: | |
| 75 return self._api_features | |
| 76 # Manifest and permission features must be loaded and annotated already | |
| 77 # for API features to be properly annotated. | |
| 78 self.GetManifestFeatures() | |
| 79 self.GetPermissionFeatures() | |
| 80 self._api_features = self._api_cache.GetFeatures() | |
| 81 for feature in self._api_features.itervalues(): | |
| 82 features_utility.AddPlatformsFromDependencies(feature, self) | |
|
not at google - send to devlin
2013/10/01 16:34:34
AddPlatformsFromDependencies is only used in this
Ken Rockot(use gerrit already)
2013/10/01 22:18:16
Done, and on that note features_utility.Filtered i
| |
| 83 return self._api_features | |
| OLD | NEW |