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

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

Issue 23867003: Docserver: Consolidate features caching and access. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: let's try this again, shall we? Created 7 years, 2 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
1 # Copyright 2013 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 ''' 5 '''
6 Provides a Manifest Feature abstraction, similar to but more strict than the 6 Provides a Manifest Feature abstraction, similar to but more strict than the
7 Feature schema (see feature_utility.py). 7 Feature schema (see feature_utility.py).
8 8
9 Each Manifest Feature has a 'level' in addition to the keys defined in a 9 Each Manifest Feature has a 'level' in addition to the keys defined in a
10 Feature. 'level' can be 'required', 'only_one', 'recommended', or 'optional', 10 Feature. 'level' can be 'required', 'only_one', 'recommended', or 'optional',
11 indicating how an app or extension should define a manifest property. If 'level' 11 indicating how an app or extension should define a manifest property. If 'level'
12 is missing, 'optional' is assumed. 12 is missing, 'optional' is assumed.
13 ''' 13 '''
14 14
15 import features_utility
16
17 def CreateManifestFeatures(features_json, manifest_json, filter_platform=None):
18 '''Create a manifest features dictionary by normalizing |features_json| and
19 merging it with |manifest_json|. If filter_platform is 'app' or 'extension'
20 then irrelevant features will be removed.
21 '''
22 assert filter_platform in ['app', 'extension', None]
23 manifest_features = features_utility.MergedWith(
24 features_utility.Parse(features_json), manifest_json)
25
26 if filter_platform:
27 manifest_features = features_utility.Filtered(
28 manifest_features, filter_platform)
29
30 return manifest_features
31
32
33 def ConvertDottedKeysToNested(features): 15 def ConvertDottedKeysToNested(features):
34 '''Some Manifest Features are subordinate to others, such as app.background to 16 '''Some Manifest Features are subordinate to others, such as app.background to
35 app. Subordinate Features can be moved inside the parent Feature under the key 17 app. Subordinate Features can be moved inside the parent Feature under the key
36 'children'. 18 'children'.
37 19
38 Modifies |features|, a Manifest Features dictionary, by moving subordinate 20 Modifies |features|, a Manifest Features dictionary, by moving subordinate
39 Features with names of the form 'parent.child' into the 'parent' Feature. 21 Features with names of the form 'parent.child' into the 'parent' Feature.
40 Child features are renamed to the 'child' section of their previous name. 22 Child features are renamed to the 'child' section of their previous name.
41 23
42 Applied recursively so that children can be nested arbitrarily. 24 Applied recursively so that children can be nested arbitrarily.
(...skipping 10 matching lines...) Expand all
53 value = features.pop(name) 35 value = features.pop(name)
54 parent, child_name = name.split('.', 1) 36 parent, child_name = name.split('.', 1)
55 add_child(features, parent, child_name, value) 37 add_child(features, parent, child_name, value)
56 38
57 for value in features.values(): 39 for value in features.values():
58 if 'children' in value: 40 if 'children' in value:
59 insert_children(value['children']) 41 insert_children(value['children'])
60 42
61 insert_children(features) 43 insert_children(features)
62 return features 44 return features
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698