Chromium Code Reviews| Index: chrome/common/extensions/docs/server2/chained_compiled_file_system.py |
| =================================================================== |
| --- chrome/common/extensions/docs/server2/chained_compiled_file_system.py (revision 0) |
| +++ chrome/common/extensions/docs/server2/chained_compiled_file_system.py (revision 0) |
| @@ -0,0 +1,61 @@ |
| +# Copyright 2013 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +from compiled_file_system import CompiledFileSystem |
| +from file_system import FileNotFoundError |
| + |
| +class ChainedCompiledFileSystem(object): |
| + ''' A CompiledFileSystem implementation that fetches data from a chain of |
| + CompiledFileSystems. |
| + |
| + The rules for the compiled file system chain are: |
| + - Versions are fetched from the first compiled file system's underlying |
| + file system. |
| + - Each compiled file system is read in the reverse order (the last one is |
| + read first). If the version matches, return the data. Otherwise, read |
| + from the previous compiled file system until the first one is read. |
| + |
| + It is used to chain two compiled file systems whose underlying file systems |
| + are slightly different. This makes it possible to reuse cached compiled data |
|
not at google - send to devlin
2013/05/12 03:28:27
Nice comment, thanks.
But - s/two compiled file s
方觉(Fang Jue)
2013/05/12 04:22:07
Done.
|
| + in one of them without recompiling everything that is shared by them. |
| + ''' |
| + class Factory(CompiledFileSystem.Factory): |
| + def __init__(self, |
| + factory_chain): |
| + self._factory_chain = factory_chain |
| + |
| + def Create(self, populate_function, cls, category=None): |
| + return ChainedCompiledFileSystem( |
| + [factory.Create(populate_function, cls, category) |
| + for factory in self._factory_chain]) |
| + |
| + def __init__(self, compiled_fs_chain): |
| + assert len(compiled_fs_chain) > 0 |
| + self._compiled_fs_chain = compiled_fs_chain |
| + |
| + def GetFromFile(self, path, binary=False): |
| + # It's possible that a new file is added in the first compiled file system |
| + # and it doesn't exist in other compiled file systems. |
| + try: |
| + version = self._compiled_fs_chain[0]._file_system.Stat(path).version |
| + for compiled_fs in reversed(self._compiled_fs_chain): |
| + cache_entry = compiled_fs._GetCacheEntryFromFile(path, binary) |
|
not at google - send to devlin
2013/05/12 03:28:27
Is the version stuff necessary if you check them i
方觉(Fang Jue)
2013/05/12 04:22:07
Yes. It's necessary. version is used to determine
not at google - send to devlin
2013/05/12 05:11:41
Ok, never mind, I found a problem with what I was
|
| + if cache_entry.version == version: |
| + return cache_entry.cache_data |
| + except FileNotFoundError: |
| + pass |
| + return self._compiled_fs_chain[0].GetFromFile(path, binary) |
|
not at google - send to devlin
2013/05/12 03:28:27
Coud you add the comment here and below "Try first
方觉(Fang Jue)
2013/05/12 04:22:07
Done.
|
| + |
| + def GetFromFileListing(self, path): |
| + if not path.endswith('/'): |
| + path += '/' |
| + try: |
| + version = self._compiled_fs_chain[0]._file_system.Stat(path).version |
| + for compiled_fs in reversed(self._compiled_fs_chain): |
| + cache_entry = compiled_fs._GetCacheEntryFromFileListing(path) |
| + if cache_entry.version == version: |
| + return cache_entry.cache_data |
| + except FileNotFoundError: |
| + pass |
| + return self._compiled_fs_chain[0].GetFromFileListing(path) |
| Property changes on: chrome/common/extensions/docs/server2/chained_compiled_file_system.py |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |