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

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

Issue 14125010: Docserver: Add support for viewing docs with a codereview patch applied (Closed) Base URL: https://src.chromium.org/svn/trunk/src/
Patch Set: Created 7 years, 7 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 from compiled_file_system import CompiledFileSystem
6 from file_system import FileNotFoundError
7
8 class ChainedCompiledFileSystem(object):
9 ''' A CompiledFileSystem implementation that fetches data from a chain of
10 CompiledFileSystems that have different file systems and separate cache
11 namespaces.
12
13 The rules for the compiled file system chain are:
14 - Versions are fetched from the first compiled file system's underlying
15 file system.
16 - Each compiled file system is read in the reverse order (the last one is
17 read first). If the version matches, return the data. Otherwise, read
18 from the previous compiled file system until the first one is read.
19
20 It is used to chain compiled file systems whose underlying file systems are
21 slightly different. This makes it possible to reuse cached compiled data in
22 one of them without recompiling everything that is shared by them.
23 '''
24 class Factory(CompiledFileSystem.Factory):
25 def __init__(self,
26 factory_chain):
27 self._factory_chain = factory_chain
28
29 def Create(self, populate_function, cls, category=None):
30 return ChainedCompiledFileSystem(
31 [factory.Create(populate_function, cls, category)
32 for factory in self._factory_chain])
33
34 def __init__(self, compiled_fs_chain):
35 assert len(compiled_fs_chain) > 0
36 self._compiled_fs_chain = compiled_fs_chain
37
38 def GetFromFile(self, path, binary=False):
39 # It's possible that a new file is added in the first compiled file system
40 # and it doesn't exist in other compiled file systems.
41 try:
42 version = self._compiled_fs_chain[0]._file_system.Stat(path).version
not at google - send to devlin 2013/05/12 05:13:42 p.s. however this code ends up turning out, it's q
43 for compiled_fs in reversed(self._compiled_fs_chain):
44 cache_entry = compiled_fs._GetCacheEntryFromFile(path, binary)
45 if cache_entry.version == version:
46 return cache_entry.cache_data
47 except FileNotFoundError:
48 pass
49 # Try first operation again to generate the correct stack trace
50 return self._compiled_fs_chain[0].GetFromFile(path, binary)
51
52 def GetFromFileListing(self, path):
53 if not path.endswith('/'):
54 path += '/'
55 try:
56 version = self._compiled_fs_chain[0]._file_system.Stat(path).version
57 for compiled_fs in reversed(self._compiled_fs_chain):
58 cache_entry = compiled_fs._GetCacheEntryFromFileListing(path)
59 if cache_entry.version == version:
60 return cache_entry.cache_data
61 except FileNotFoundError:
62 pass
63 # Try first operation again to generate the correct stack trace
64 return self._compiled_fs_chain[0].GetFromFileListing(path)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698