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 copy import deepcopy | |
| 6 | |
| 7 import features_utility | |
| 8 from third_party.json_schema_compiler.json_parse import Parse | |
| 9 | |
| 10 class Features(object): | |
| 11 '''Provides cached access to data for a specific features set. This can be | |
| 12 subclassed to provide special transformation or handling during the feature | |
| 13 parsing process by overriding Parse, FilterByPlatform, and/or | |
| 14 CreateCache. | |
| 15 ''' | |
| 16 def __init__(self, compiled_fs_factory, features_path): | |
| 17 self._features_path = features_path | |
| 18 self._cache = compiled_fs_factory.Create(self._CreateFeatures, type(self)) | |
| 19 | |
| 20 def _CreateFeatures(self, _, content): | |
| 21 features = self.Parse(Parse(content)) | |
| 22 cache = self.CreateCache(features) | |
| 23 cache['all'] = features | |
| 24 return cache | |
| 25 | |
| 26 def Parse(self, features_json): | |
|
not at google - send to devlin
2013/09/23 18:31:30
I don't quite understand the inheritance structure
| |
| 27 return features_utility.Parse(features_json) | |
| 28 | |
| 29 def FilterByPlatform(self, features, platform): | |
| 30 filtered_features = {} | |
| 31 for name, feature in features.iteritems(): | |
| 32 platforms = features_utility.GetPlatformSetForExtensionTypes( | |
| 33 feature.get('extension_types', ())) | |
| 34 if not platform or platform in platforms: | |
| 35 filtered_features[name] = deepcopy(feature) | |
| 36 return filtered_features | |
| 37 | |
| 38 def CreateCache(self, features): | |
| 39 return { | |
| 40 'apps': self.FilterByPlatform(features, 'apps'), | |
| 41 'extensions': self.FilterByPlatform(features, 'extensions'), | |
| 42 } | |
| 43 | |
| 44 def get(self, key): | |
| 45 return self._cache.GetFromFile(self._features_path)[key] | |
| 46 | |
| OLD | NEW |