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

Side by Side Diff: chrome/common/extensions/docs/server2/features.py

Issue 23867003: Docserver: Consolidate features caching and access. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 7 years, 3 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
OLDNEW
(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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698