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

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

Issue 26538009: Docserver: make file_system a property of Create (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: niggles 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 | 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 sys 5 import sys
6 6
7 from file_system import FileNotFoundError 7 from file_system import FileNotFoundError
8 from future import Gettable, Future 8 from future import Gettable, Future
9 9
10 10
11 class _CacheEntry(object): 11 class _CacheEntry(object):
12 def __init__(self, cache_data, version): 12 def __init__(self, cache_data, version):
13 self._cache_data = cache_data 13 self._cache_data = cache_data
14 self.version = version 14 self.version = version
15 15
16 class CompiledFileSystem(object): 16 class CompiledFileSystem(object):
17 """This class caches FileSystem data that has been processed. 17 """This class caches FileSystem data that has been processed.
18 """ 18 """
19 class Factory(object): 19 class Factory(object):
20 """A class to build a CompiledFileSystem backed by |file_system|. 20 """A class to build a CompiledFileSystem backed by |file_system|.
21 """ 21 """
22 def __init__(self, file_system, object_store_creator): 22 def __init__(self, object_store_creator):
23 self._file_system = file_system
24 self._object_store_creator = object_store_creator 23 self._object_store_creator = object_store_creator
25 24
26 def Create(self, populate_function, cls, category=None): 25 def Create(self, file_system, populate_function, cls, category=None):
27 """Create a CompiledFileSystem that populates the cache by calling 26 """Creates a CompiledFileSystem view over |file_system| that populates
28 |populate_function| with (path, data), where |data| is the data that was 27 its cache by calling |populate_function| with (path, data), where |data|
29 fetched from |path|. 28 is the data that was fetched from |path| in |file_system|.
30 The namespace for the file system is derived like ObjectStoreCreator: from 29
31 |cls| along with an optional |category|. 30 The namespace for the compiled file system is derived similar to
31 ObjectStoreCreator: from |cls| along with an optional |category|.
32 """ 32 """
33 assert isinstance(cls, type) 33 assert isinstance(cls, type)
34 assert not cls.__name__[0].islower() # guard against non-class types 34 assert not cls.__name__[0].islower() # guard against non-class types
35 full_name = [cls.__name__, self._file_system.GetIdentity()] 35 full_name = [cls.__name__, file_system.GetIdentity()]
36 if category is not None: 36 if category is not None:
37 full_name.append(category) 37 full_name.append(category)
38 def create_object_store(my_category): 38 def create_object_store(my_category):
39 return self._object_store_creator.Create( 39 return self._object_store_creator.Create(
40 CompiledFileSystem, category='/'.join(full_name + [my_category])) 40 CompiledFileSystem, category='/'.join(full_name + [my_category]))
41 return CompiledFileSystem(self._file_system, 41 return CompiledFileSystem(file_system,
42 populate_function, 42 populate_function,
43 create_object_store('file'), 43 create_object_store('file'),
44 create_object_store('list')) 44 create_object_store('list'))
45 45
46 def __init__(self, 46 def __init__(self,
47 file_system, 47 file_system,
48 populate_function, 48 populate_function,
49 file_object_store, 49 file_object_store,
50 list_object_store): 50 list_object_store):
51 self._file_system = file_system 51 self._file_system = file_system
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 if (cache_entry is not None) and (version == cache_entry.version): 146 if (cache_entry is not None) and (version == cache_entry.version):
147 return Future(value=cache_entry._cache_data) 147 return Future(value=cache_entry._cache_data)
148 148
149 recursive_list_future = self._RecursiveList(path) 149 recursive_list_future = self._RecursiveList(path)
150 def resolve(): 150 def resolve():
151 cache_data = self._populate_function(path, recursive_list_future.Get()) 151 cache_data = self._populate_function(path, recursive_list_future.Get())
152 self._list_object_store.Set(path, _CacheEntry(cache_data, version)) 152 self._list_object_store.Set(path, _CacheEntry(cache_data, version))
153 return cache_data 153 return cache_data
154 return Future(delegate=Gettable(resolve)) 154 return Future(delegate=Gettable(resolve))
155 155
156 def StatFile(self, path): 156 def GetFileVersion(self, path):
157 cache_entry = self._file_object_store.Get(path).Get() 157 cache_entry = self._file_object_store.Get(path).Get()
158 if cache_entry is not None: 158 if cache_entry is not None:
159 return cache_entry.version 159 return cache_entry.version
160 return self._file_system.Stat(path).version 160 return self._file_system.Stat(path).version
161 161
162 def StatFileListing(self, path): 162 def GetFileListingVersion(self, path):
163 if not path.endswith('/'): 163 if not path.endswith('/'):
164 path += '/' 164 path += '/'
165 cache_entry = self._list_object_store.Get(path).Get() 165 cache_entry = self._list_object_store.Get(path).Get()
166 if cache_entry is not None: 166 if cache_entry is not None:
167 return cache_entry.version 167 return cache_entry.version
168 return self._file_system.Stat(path).version 168 return self._file_system.Stat(path).version
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698