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

Unified Diff: chrome/common/extensions/docs/server2/api_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/api_features.py
diff --git a/chrome/common/extensions/docs/server2/api_features.py b/chrome/common/extensions/docs/server2/api_features.py
new file mode 100644
index 0000000000000000000000000000000000000000..b08bf44fd2f59436fb9c9b182990c0be457457ca
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/api_features.py
@@ -0,0 +1,59 @@
+# 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
+
+from features import Features
+import features_utility
+from third_party.json_schema_compiler.json_parse import Parse
+
+def _GetExtensionTypesRecursive(feature, feature_set):
+ extension_types = feature.get('extension_types')
+ if extension_types is None:
+ dependencies = feature.get('dependencies')
+ # No specific constraints == available on all platforms!
not at google - send to devlin 2013/09/23 18:31:30 this... should never happen. but what *can* happen
+ if dependencies is None:
+ return set(('platform_app', 'extension'))
+ extension_types = set()
+ for dependency in dependencies:
+ dep_type, dep_name = dependency.split(':')
+ dependency_features = feature_set[dep_type]
+ dependency_feature = dependency_features.get(dep_name)
+ # If the dependency can't be resolved, it is inaccessible and therefore
+ # so is this API feature.
+ if dependency_feature is None:
+ return set()
+ extension_types = extension_types.union(
+ _GetExtensionTypesRecursive(dependency_features.get(dep_name),
+ feature_set))
+ return set(extension_types)
+
+class APIFeatures(Features):
+ '''Subclass of Features that can dig into dependencies to deduce the feature's
+ supported extension types.
+ '''
+ def __init__(self,
+ compiled_fs_factory,
+ api_features_path,
+ manifest_features,
+ permission_features):
+ self._manifest_features = manifest_features
+ self._permission_features = permission_features
+ super(APIFeatures, self).__init__(compiled_fs_factory, api_features_path)
+
+ def FilterByPlatform(self, features, platform):
+ '''Filter API features by supported platform using data from feature
+ dependencies if necessary.'''
+ feature_set = {
+ 'api': features,
+ 'manifest': self._manifest_features.get('all'),
+ 'permission': self._permission_features.get('all'),
+ }
+ filtered_features = {}
+ for name, feature in features.iteritems():
+ platforms = features_utility.GetPlatformSetForExtensionTypes(
+ _GetExtensionTypesRecursive(feature, feature_set))
+ if not platform or platform in platforms:
+ filtered_features[name] = deepcopy(feature)
+ return filtered_features

Powered by Google App Engine
This is Rietveld 408576698