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

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

Issue 13470005: Refactor the devserver to make it easier to control caching (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cache static files in cron, fix path canonicalizer bug Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 copy 5 import copy
6 import json 6 import json
7 import logging 7 import logging
8 8
9 import compiled_file_system as compiled_fs 9 import compiled_file_system as compiled_fs
10 from file_system import FileNotFoundError 10 from file_system import FileNotFoundError
11 from third_party.json_schema_compiler.model import UnixName 11 from third_party.json_schema_compiler.model import UnixName
12 12
13 # Increment this if the data model changes for SidenavDataSource.
14 _VERSION = 1
15
13 class SidenavDataSource(object): 16 class SidenavDataSource(object):
14 """This class reads in and caches a JSON file representing the side navigation 17 """This class reads in and caches a JSON file representing the side navigation
15 menu. 18 menu.
16 """ 19 """
17 class Factory(object): 20 class Factory(object):
18 def __init__(self, cache_factory, json_path): 21 def __init__(self, compiled_fs_factory, json_path):
19 self._cache = cache_factory.Create(self._CreateSidenavDict, 22 self._cache = compiled_fs_factory.Create(self._CreateSidenavDict,
20 compiled_fs.SIDENAV) 23 SidenavDataSource,
24 version=_VERSION)
21 self._json_path = json_path 25 self._json_path = json_path
22 26
23 def Create(self, path): 27 def Create(self, path):
24 """Create a SidenavDataSource, binding it to |path|. |path| is the url 28 """Create a SidenavDataSource, binding it to |path|. |path| is the url
25 of the page that is being rendered. It is used to determine which item 29 of the page that is being rendered. It is used to determine which item
26 in the sidenav should be highlighted. 30 in the sidenav should be highlighted.
27 """ 31 """
28 return SidenavDataSource(self._cache, self._json_path, path) 32 return SidenavDataSource(self._cache, self._json_path, path)
29 33
30 def _AddLevels(self, items, level): 34 def _AddLevels(self, items, level):
(...skipping 27 matching lines...) Expand all
58 return False 62 return False
59 63
60 def get(self, key): 64 def get(self, key):
61 try: 65 try:
62 sidenav = copy.deepcopy(self._cache.GetFromFile( 66 sidenav = copy.deepcopy(self._cache.GetFromFile(
63 '%s/%s_sidenav.json' % (self._json_path, key))) 67 '%s/%s_sidenav.json' % (self._json_path, key)))
64 self._AddSelected(sidenav) 68 self._AddSelected(sidenav)
65 return sidenav 69 return sidenav
66 except FileNotFoundError as e: 70 except FileNotFoundError as e:
67 logging.error('%s: Error reading sidenav "%s".' % (e, key)) 71 logging.error('%s: Error reading sidenav "%s".' % (e, key))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698