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

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: Done 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):
Jeffrey Yasskin 2013/10/14 18:52:31 Please document the file_system argument.
not at google - send to devlin 2013/10/14 21:03:34 Done.
27 """Create a CompiledFileSystem that populates the cache by calling 26 """Create a CompiledFileSystem that populates the cache by calling
28 |populate_function| with (path, data), where |data| is the data that was 27 |populate_function| with (path, data), where |data| is the data that was
29 fetched from |path|. 28 fetched from |path|.
30 The namespace for the file system is derived like ObjectStoreCreator: from 29 The namespace for the file system is derived like ObjectStoreCreator: from
31 |cls| along with an optional |category|. 30 |cls| along with an optional |category|.
32 """ 31 """
33 assert isinstance(cls, type) 32 assert isinstance(cls, type)
34 assert not cls.__name__[0].islower() # guard against non-class types 33 assert not cls.__name__[0].islower() # guard against non-class types
35 full_name = [cls.__name__, self._file_system.GetIdentity()] 34 full_name = [cls.__name__, file_system.GetIdentity()]
36 if category is not None: 35 if category is not None:
37 full_name.append(category) 36 full_name.append(category)
38 def create_object_store(my_category): 37 def create_object_store(my_category):
39 return self._object_store_creator.Create( 38 return self._object_store_creator.Create(
40 CompiledFileSystem, category='/'.join(full_name + [my_category])) 39 CompiledFileSystem, category='/'.join(full_name + [my_category]))
41 return CompiledFileSystem(self._file_system, 40 return CompiledFileSystem(file_system,
42 populate_function, 41 populate_function,
43 create_object_store('file'), 42 create_object_store('file'),
44 create_object_store('list')) 43 create_object_store('list'))
45 44
46 def __init__(self, 45 def __init__(self,
47 file_system, 46 file_system,
48 populate_function, 47 populate_function,
49 file_object_store, 48 file_object_store,
50 list_object_store): 49 list_object_store):
51 self._file_system = file_system 50 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): 145 if (cache_entry is not None) and (version == cache_entry.version):
147 return Future(value=cache_entry._cache_data) 146 return Future(value=cache_entry._cache_data)
148 147
149 recursive_list_future = self._RecursiveList(path) 148 recursive_list_future = self._RecursiveList(path)
150 def resolve(): 149 def resolve():
151 cache_data = self._populate_function(path, recursive_list_future.Get()) 150 cache_data = self._populate_function(path, recursive_list_future.Get())
152 self._list_object_store.Set(path, _CacheEntry(cache_data, version)) 151 self._list_object_store.Set(path, _CacheEntry(cache_data, version))
153 return cache_data 152 return cache_data
154 return Future(delegate=Gettable(resolve)) 153 return Future(delegate=Gettable(resolve))
155 154
156 def StatFile(self, path): 155 def GetFileVersion(self, path):
157 cache_entry = self._file_object_store.Get(path).Get() 156 cache_entry = self._file_object_store.Get(path).Get()
158 if cache_entry is not None: 157 if cache_entry is not None:
159 return cache_entry.version 158 return cache_entry.version
160 return self._file_system.Stat(path).version 159 return self._file_system.Stat(path).version
161 160
162 def StatFileListing(self, path): 161 def GetFileListingVersion(self, path):
163 if not path.endswith('/'): 162 if not path.endswith('/'):
164 path += '/' 163 path += '/'
165 cache_entry = self._list_object_store.Get(path).Get() 164 cache_entry = self._list_object_store.Get(path).Get()
166 if cache_entry is not None: 165 if cache_entry is not None:
167 return cache_entry.version 166 return cache_entry.version
168 return self._file_system.Stat(path).version 167 return self._file_system.Stat(path).version
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698