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

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

Issue 15087006: Docserver: there is only one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: better redirects Created 7 years, 7 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 class _CacheEntry(object): 5 class _CacheEntry(object):
6 def __init__(self, cache_data, version): 6 def __init__(self, cache_data, version):
7 self._cache_data = cache_data 7 self._cache_data = cache_data
8 self.version = version 8 self.version = version
9 9
10 class CompiledFileSystem(object): 10 class CompiledFileSystem(object):
11 """This class caches FileSystem data that has been processed. 11 """This class caches FileSystem data that has been processed.
12 """ 12 """
13 class Factory(object): 13 class Factory(object):
14 """A class to build a CompiledFileSystem backed by |file_system|. 14 """A class to build a CompiledFileSystem backed by |file_system|.
15 """ 15 """
16 def __init__(self, file_system, object_store_creator): 16 def __init__(self, file_system, object_store_creator):
17 self._file_system = file_system 17 self._file_system = file_system
18 self._object_store_creator = object_store_creator 18 self._object_store_creator = object_store_creator
19 19
20 def Create(self, populate_function, cls, category=None): 20 def Create(self, populate_function, cls, category=None):
21 """Create a CompiledFileSystem that populates the cache by calling 21 """Create a CompiledFileSystem that populates the cache by calling
22 |populate_function| with (path, data), where |data| is the data that was 22 |populate_function| with (path, data), where |data| is the data that was
23 fetched from |path|. 23 fetched from |path|.
24 The namespace for the file system is derived like ObjectStoreCreator: from 24 The namespace for the file system is derived like ObjectStoreCreator: from
25 |cls| along with an optional |category|. 25 |cls| along with an optional |category|.
26 """ 26 """
27 assert isinstance(cls, type) 27 assert isinstance(cls, type)
28 assert not cls.__name__[0].islower() # guard against non-class types 28 assert not cls.__name__[0].islower() # guard against non-class types
29 full_name = cls.__name__ 29 full_name = [cls.__name__, self._file_system.GetIdentity()]
30 if category is not None: 30 if category is not None:
31 full_name = '%s/%s' % (full_name, category) 31 full_name.append(category)
32 def create_object_store(category): 32 def create_object_store(my_category):
33 return self._object_store_creator.Create( 33 return self._object_store_creator.Create(
34 CompiledFileSystem, category='%s/%s' % (full_name, category)) 34 CompiledFileSystem, category='/'.join(full_name + [my_category]))
35 return CompiledFileSystem(self._file_system, 35 return CompiledFileSystem(self._file_system,
36 populate_function, 36 populate_function,
37 create_object_store('file'), 37 create_object_store('file'),
38 create_object_store('list')) 38 create_object_store('list'))
39 39
40 def CreateIdentity(self, cls): 40 def CreateIdentity(self, cls):
41 '''Handy helper to get or create the identity compiled file system. 41 '''Handy helper to get or create the identity compiled file system.
42 GetFromFile will return the file's contents. 42 GetFromFile will return the file's contents.
43 GetFromFileListing will return the directory list. 43 GetFromFileListing will return the directory list.
44 ''' 44 '''
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 return cache_entry.version 100 return cache_entry.version
101 return self._file_system.Stat(path).version 101 return self._file_system.Stat(path).version
102 102
103 def StatFileListing(self, path): 103 def StatFileListing(self, path):
104 if not path.endswith('/'): 104 if not path.endswith('/'):
105 path += '/' 105 path += '/'
106 cache_entry = self._list_object_store.Get(path).Get() 106 cache_entry = self._list_object_store.Get(path).Get()
107 if cache_entry is not None: 107 if cache_entry is not None:
108 return cache_entry.version 108 return cache_entry.version
109 return self._file_system.Stat(path).version 109 return self._file_system.Stat(path).version
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698