| OLD | NEW |
| 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 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 else: | 63 else: |
| 64 files.append(filename) | 64 files.append(filename) |
| 65 return files | 65 return files |
| 66 | 66 |
| 67 def GetFromFile(self, path, binary=False): | 67 def GetFromFile(self, path, binary=False): |
| 68 """Calls |populate_function| on the contents of the file at |path|. If | 68 """Calls |populate_function| on the contents of the file at |path|. If |
| 69 |binary| is True then the file will be read as binary - but this will only | 69 |binary| is True then the file will be read as binary - but this will only |
| 70 apply for the first time the file is fetched; if already cached, |binary| | 70 apply for the first time the file is fetched; if already cached, |binary| |
| 71 will be ignored. | 71 will be ignored. |
| 72 """ | 72 """ |
| 73 return self._GetCacheEntryFromFile(path, binary).cache_data |
| 74 |
| 75 def _GetCacheEntryFromFile(self, path, binary=False): |
| 73 version = self._file_system.Stat(path).version | 76 version = self._file_system.Stat(path).version |
| 74 cache_entry = self._file_object_store.Get(path).Get() | 77 cache_entry = self._file_object_store.Get(path).Get() |
| 75 if (cache_entry is not None) and (version == cache_entry.version): | 78 if (cache_entry is not None) and (version == cache_entry.version): |
| 76 return cache_entry._cache_data | 79 return cache_entry |
| 77 cache_data = self._populate_function( | 80 cache_data = self._populate_function( |
| 78 path, | 81 path, |
| 79 self._file_system.ReadSingle(path, binary=binary)) | 82 self._file_system.ReadSingle(path, binary=binary)) |
| 80 self._file_object_store.Set(path, _CacheEntry(cache_data, version)) | 83 cache_entry = _CacheEntry(cache_data, version) |
| 81 return cache_data | 84 self._file_object_store.Set(path, cache_entry) |
| 85 return cache_entry |
| 82 | 86 |
| 83 def GetFromFileListing(self, path): | 87 def GetFromFileListing(self, path): |
| 84 """Calls |populate_function| on the listing of the files at |path|. | 88 """Calls |populate_function| on the listing of the files at |path|. |
| 85 Assumes that the path given is to a directory. | 89 Assumes that the path given is to a directory. |
| 86 """ | 90 """ |
| 87 if not path.endswith('/'): | 91 if not path.endswith('/'): |
| 88 path += '/' | 92 path += '/' |
| 93 return self._GetCacheEntryFromFileListing(path).cache_data |
| 94 |
| 95 def _GetCacheEntryFromFileListing(self, path): |
| 96 assert path.endswith('/') |
| 89 version = self._file_system.Stat(path).version | 97 version = self._file_system.Stat(path).version |
| 90 cache_entry = self._list_object_store.Get(path).Get() | 98 cache_entry = self._list_object_store.Get(path).Get() |
| 91 if (cache_entry is not None) and (version == cache_entry.version): | 99 if (cache_entry is not None) and (version == cache_entry.version): |
| 92 return cache_entry._cache_data | 100 return cache_entry |
| 93 cache_data = self._populate_function(path, self._RecursiveList(path)) | 101 cache_data = self._populate_function(path, self._RecursiveList(path)) |
| 94 self._list_object_store.Set(path, _CacheEntry(cache_data, version)) | 102 cache_entry = _CacheEntry(cache_data, version) |
| 95 return cache_data | 103 self._list_object_store.Set(path, cache_entry) |
| 104 return cache_entry |
| OLD | NEW |