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

Side by Side Diff: chrome/common/extensions/docs/server2/manifest_data_source.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 import json 5 import json
6 6
7 from data_source import DataSource 7 from data_source import DataSource
8 import features_utility 8 import features_utility
9 from manifest_features import CreateManifestFeatures, ConvertDottedKeysToNested 9 from manifest_features import ConvertDottedKeysToNested
10 from third_party.json_schema_compiler.json_parse import Parse 10 from third_party.json_schema_compiler.json_parse import Parse
11 11
12 def _ListifyAndSortDocs(features, app_name): 12 def _ListifyAndSortDocs(features, app_name):
13 '''Convert a |feautres| dictionary, and all 'children' dictionaries, into 13 '''Convert a |feautres| dictionary, and all 'children' dictionaries, into
14 lists recursively. Sort lists first by 'level' then by name. 14 lists recursively. Sort lists first by 'level' then by name.
15 ''' 15 '''
16 def sort_key(item): 16 def sort_key(item):
17 '''Key function to sort items primarily by level (according to index into 17 '''Key function to sort items primarily by level (according to index into
18 levels) then subsort by name. 18 levels) then subsort by name.
19 ''' 19 '''
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 if features: 93 if features:
94 features[-1]['is_last'] = True 94 features[-1]['is_last'] = True
95 95
96 annotate('required', features) 96 annotate('required', features)
97 return features 97 return features
98 98
99 class ManifestDataSource(DataSource): 99 class ManifestDataSource(DataSource):
100 '''Provides access to the properties in manifest features. 100 '''Provides access to the properties in manifest features.
101 ''' 101 '''
102 def __init__(self, server_instance, _): 102 def __init__(self, server_instance, _):
103 self._manifest_path = server_instance.manifest_json_path 103 self._features_bundle = server_instance.features_bundle
104 self._features_path = server_instance.manifest_features_path 104 self._object_store = server_instance.object_store_creator.Create(
105 self._file_system = server_instance.host_file_system 105 ManifestDataSource)
106 self._cache = server_instance.compiled_host_fs_factory.Create(
107 self._CreateManifestData, ManifestDataSource)
108 106
109 def _CreateManifestData(self, _, content): 107 def _CreateManifestData(self):
110 '''Combine the contents of |_manifest_path| and |_features_path| and filter
111 the results into lists specific to apps or extensions for templates. Marks
112 up features with annotations.
113 '''
114 def for_templates(manifest_features, platform): 108 def for_templates(manifest_features, platform):
115 return _AddLevelAnnotations( 109 return _AddLevelAnnotations(
116 _ListifyAndSortDocs( 110 _ListifyAndSortDocs(
117 ConvertDottedKeysToNested( 111 ConvertDottedKeysToNested(
118 features_utility.Filtered(manifest_features, platform)), 112 features_utility.Filtered(manifest_features, platform)),
119 app_name=platform.capitalize())) 113 app_name=platform.capitalize()))
120 114 manifest_features = self._features_bundle.GetManifestFeatures()
121 manifest_json = Parse(self._file_system.ReadSingle(self._manifest_path))
122 manifest_features = CreateManifestFeatures(
123 features_json=Parse(content), manifest_json=manifest_json)
124
125 return { 115 return {
126 'apps': for_templates(manifest_features, 'app'), 116 'apps': for_templates(manifest_features, 'apps'),
127 'extensions': for_templates(manifest_features, 'extension') 117 'extensions': for_templates(manifest_features, 'extensions')
128 } 118 }
129 119
120 def _GetCachedManifestData(self, force_update=False):
121 data = self._object_store.Get('manifest_data').Get()
122 if data is None or force_update:
123 data = self._CreateManifestData()
124 self._object_store.Set('manifest_data', data)
125 return data
126
130 def Cron(self): 127 def Cron(self):
131 self._cache.GetFromFile(self._features_path) 128 self._GetCachedManifestData(force_update=True)
132 self._file_system.ReadSingle(self._manifest_path)
133 129
134 def get(self, key): 130 def get(self, key):
135 return self._cache.GetFromFile(self._features_path)[key] 131 return self._GetCachedManifestData().get(key)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698