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

Unified Diff: chrome/common/extensions/docs/server2/features_utility.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_utility.py
diff --git a/chrome/common/extensions/docs/server2/features_utility.py b/chrome/common/extensions/docs/server2/features_utility.py
index f9626914811c32a81cfb047bf03454637d763161..023c228a6168ef851fa24222bf51cfa46302c414 100644
--- a/chrome/common/extensions/docs/server2/features_utility.py
+++ b/chrome/common/extensions/docs/server2/features_utility.py
@@ -4,10 +4,8 @@
'''
Utility functions for working with the Feature abstraction. Features are grouped
-into a dictionary by name. Each Feature is guaranteed to have the following two
-keys:
- name - a string, the name of the feature
- platform - a list containing 'app' or 'extension', both, or neither.
+into a dictionary by name. Each Feature is guaranteed to have a 'name' key
+holding the name of the feature.
A Feature may have other keys from a _features.json file as well. Features with
a whitelist are ignored as they are only useful to specific apps or extensions.
@@ -22,7 +20,7 @@ def Parse(features_json):
features = {}
for name, value in deepcopy(features_json).iteritems():
- # Some feature names corrispond to a list; force a list down to a single
+ # Some feature names correspond to a list; force a list down to a single
# feature by removing entries that have a 'whitelist'.
if isinstance(value, list):
values = [subvalue for subvalue in value if not 'whitelist' in subvalue]
@@ -34,31 +32,19 @@ def Parse(features_json):
if 'whitelist' in value:
continue
- features[name] = { 'platforms': [] }
-
- platforms = value.pop('extension_types')
- if platforms == 'all' or 'platform_app' in platforms:
- features[name]['platforms'].append('app')
- if platforms == 'all' or 'extension' in platforms:
- features[name]['platforms'].append('extension')
-
+ features[name] = {}
features[name]['name'] = name
features[name].update(value)
return features
-def Filtered(features, platform=None):
- '''Create a new Features dictionary from |features| that contains only items
- relevant to |platform|. Items retained are deepcopied. Returns new features
- dictionary.
- '''
- filtered_features = {}
-
- for name, feature in features.iteritems():
- if not platform or platform in feature['platforms']:
- filtered_features[name] = deepcopy(feature)
-
- return filtered_features
+def GetPlatformSetForExtensionTypes(extension_types):
+ platforms = set()
+ if extension_types == 'all' or 'platform_app' in extension_types:
+ platforms.add('apps')
+ if extension_types == 'all' or 'extension' in extension_types:
+ platforms.add('extensions')
+ return platforms
def MergedWith(features, other):
'''Merge |features| with an additional dictionary to create a new features
@@ -75,7 +61,5 @@ def MergedWith(features, other):
# Ensure the Feature schema is enforced for all added items.
if not 'name' in features[key]:
features[key]['name'] = key
- if not 'platforms' in features[key]:
- features[key]['platforms'] = []
return features

Powered by Google App Engine
This is Rietveld 408576698