| Index: chrome/common/extensions/docs/server2/compiled_file_system.py
|
| ===================================================================
|
| --- chrome/common/extensions/docs/server2/compiled_file_system.py (revision 199575)
|
| +++ chrome/common/extensions/docs/server2/compiled_file_system.py (working copy)
|
| @@ -4,7 +4,7 @@
|
|
|
| class _CacheEntry(object):
|
| def __init__(self, cache_data, version):
|
| - self._cache_data = cache_data
|
| + self.cache_data = cache_data
|
| self.version = version
|
|
|
| class CompiledFileSystem(object):
|
| @@ -24,6 +24,13 @@
|
| The namespace for the file system is derived like ObjectStoreCreator: from
|
| |cls| along with an optional |category|.
|
| """
|
| + return self._Create(populate_function, cls, category)
|
| +
|
| + def _Create(self,
|
| + populate_function,
|
| + cls,
|
| + category=None,
|
| + constructor=None):
|
| assert isinstance(cls, type)
|
| assert not cls.__name__[0].islower() # guard against non-class types
|
| full_name = cls.__name__
|
| @@ -32,10 +39,12 @@
|
| def create_object_store(category):
|
| return self._object_store_creator.Create(
|
| CompiledFileSystem, category='%s/%s' % (full_name, category))
|
| - return CompiledFileSystem(self._file_system,
|
| - populate_function,
|
| - create_object_store('file'),
|
| - create_object_store('list'))
|
| + if constructor is None:
|
| + constructor = CompiledFileSystem
|
| + return constructor(self._file_system,
|
| + populate_function,
|
| + create_object_store('file'),
|
| + create_object_store('list'))
|
|
|
| def CreateIdentity(self, cls):
|
| '''Handy helper to get or create the identity compiled file system.
|
| @@ -70,15 +79,19 @@
|
| apply for the first time the file is fetched; if already cached, |binary|
|
| will be ignored.
|
| """
|
| + return self._GetCacheEntryFromFile(path, binary).cache_data
|
| +
|
| + def _GetCacheEntryFromFile(self, path, binary=False):
|
| version = self._file_system.Stat(path).version
|
| cache_entry = self._file_object_store.Get(path).Get()
|
| if (cache_entry is not None) and (version == cache_entry.version):
|
| - return cache_entry._cache_data
|
| + return cache_entry
|
| cache_data = self._populate_function(
|
| path,
|
| self._file_system.ReadSingle(path, binary=binary))
|
| - self._file_object_store.Set(path, _CacheEntry(cache_data, version))
|
| - return cache_data
|
| + cache_entry = _CacheEntry(cache_data, version)
|
| + self._file_object_store.Set(path, cache_entry)
|
| + return cache_entry
|
|
|
| def GetFromFileListing(self, path):
|
| """Calls |populate_function| on the listing of the files at |path|.
|
| @@ -86,10 +99,15 @@
|
| """
|
| if not path.endswith('/'):
|
| path += '/'
|
| + return self._GetCacheEntryFromFileListing(path).cache_data
|
| +
|
| + def _GetCacheEntryFromFileListing(self, path):
|
| + assert path.endswith('/')
|
| version = self._file_system.Stat(path).version
|
| cache_entry = self._list_object_store.Get(path).Get()
|
| if (cache_entry is not None) and (version == cache_entry.version):
|
| - return cache_entry._cache_data
|
| + return cache_entry
|
| cache_data = self._populate_function(path, self._RecursiveList(path))
|
| - self._list_object_store.Set(path, _CacheEntry(cache_data, version))
|
| - return cache_data
|
| + cache_entry = _CacheEntry(cache_data, version)
|
| + self._list_object_store.Set(path, cache_entry)
|
| + return cache_entry
|
|
|