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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/features.py
diff --git a/chrome/common/extensions/docs/server2/features.py b/chrome/common/extensions/docs/server2/features.py
new file mode 100644
index 0000000000000000000000000000000000000000..7283a3c0074e3d28b675bb2fd2f21b6e0b7a0b6c
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/features.py
@@ -0,0 +1,46 @@
+# Copyright 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from copy import deepcopy
+
+import features_utility
+from third_party.json_schema_compiler.json_parse import Parse
+
+class Features(object):
+ '''Provides cached access to data for a specific features set. This can be
+ subclassed to provide special transformation or handling during the feature
+ parsing process by overriding Parse, FilterByPlatform, and/or
+ CreateCache.
+ '''
+ def __init__(self, compiled_fs_factory, features_path):
+ self._features_path = features_path
+ self._cache = compiled_fs_factory.Create(self._CreateFeatures, type(self))
+
+ def _CreateFeatures(self, _, content):
+ features = self.Parse(Parse(content))
+ cache = self.CreateCache(features)
+ cache['all'] = features
+ return cache
+
+ 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
+ return features_utility.Parse(features_json)
+
+ def FilterByPlatform(self, features, platform):
+ filtered_features = {}
+ for name, feature in features.iteritems():
+ platforms = features_utility.GetPlatformSetForExtensionTypes(
+ feature.get('extension_types', ()))
+ if not platform or platform in platforms:
+ filtered_features[name] = deepcopy(feature)
+ return filtered_features
+
+ def CreateCache(self, features):
+ return {
+ 'apps': self.FilterByPlatform(features, 'apps'),
+ 'extensions': self.FilterByPlatform(features, 'extensions'),
+ }
+
+ def get(self, key):
+ return self._cache.GetFromFile(self._features_path)[key]
+

Powered by Google App Engine
This is Rietveld 408576698