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

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

Issue 437323003: Docserver: Factor SamplesModel out of SamplesDataSource (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: The cron is on Created 6 years, 4 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
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 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 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 from compiled_file_system import CompiledFileSystem 5 from compiled_file_system import CompiledFileSystem
6 from docs_server_utils import StringIdentity 6 from docs_server_utils import StringIdentity
7 from file_system import FileNotFoundError 7 from file_system import FileNotFoundError
8 from future import Future 8 from future import Future
9 from path_util import ToDirectory
9 10
10 11
11 class ChainedCompiledFileSystem(object): 12 class ChainedCompiledFileSystem(object):
12 '''A CompiledFileSystem implementation that fetches data from a chain of 13 '''A CompiledFileSystem implementation that fetches data from a chain of
13 possible FileSystems. The chain consists of some number of FileSystems which 14 possible FileSystems. The chain consists of some number of FileSystems which
14 may have cached data for their CompiledFileSystem instances (injected on 15 may have cached data for their CompiledFileSystem instances (injected on
15 Factory construction) + the main FileSystem (injected at Creation time). 16 Factory construction) + the main FileSystem (injected at Creation time).
16 17
17 The expected configuration is that the main FileSystem is a PatchedFileSystem 18 The expected configuration is that the main FileSystem is a PatchedFileSystem
18 and the chain the FileSystem which it patches, but with file systems 19 and the chain the FileSystem which it patches, but with file systems
(...skipping 26 matching lines...) Expand all
45 self._compiled_fs_chain = compiled_fs_chain 46 self._compiled_fs_chain = compiled_fs_chain
46 self._identity = identity 47 self._identity = identity
47 48
48 def GetFromFile(self, path): 49 def GetFromFile(self, path):
49 return self._GetImpl( 50 return self._GetImpl(
50 path, 51 path,
51 lambda compiled_fs: compiled_fs.GetFromFile(path), 52 lambda compiled_fs: compiled_fs.GetFromFile(path),
52 lambda compiled_fs: compiled_fs.GetFileVersion(path)) 53 lambda compiled_fs: compiled_fs.GetFileVersion(path))
53 54
54 def GetFromFileListing(self, path): 55 def GetFromFileListing(self, path):
55 if not path.endswith('/'): 56 path = ToDirectory(path)
56 path += '/'
57 return self._GetImpl( 57 return self._GetImpl(
58 path, 58 path,
59 lambda compiled_fs: compiled_fs.GetFromFileListing(path), 59 lambda compiled_fs: compiled_fs.GetFromFileListing(path),
60 lambda compiled_fs: compiled_fs.GetFileListingVersion(path)) 60 lambda compiled_fs: compiled_fs.GetFileListingVersion(path))
61 61
62 def _GetImpl(self, path, reader, version_getter): 62 def _GetImpl(self, path, reader, version_getter):
63 # Strategy: Get the current version of |path| in main FileSystem, then run 63 # Strategy: Get the current version of |path| in main FileSystem, then run
64 # through |_compiled_fs_chain| in *reverse* to find the "oldest" FileSystem 64 # through |_compiled_fs_chain| in *reverse* to find the "oldest" FileSystem
65 # with an up-to-date version of that file. 65 # with an up-to-date version of that file.
66 # 66 #
(...skipping 17 matching lines...) Expand all
84 return read_future.Get() 84 return read_future.Get()
85 except FileNotFoundError: 85 except FileNotFoundError:
86 pass 86 pass
87 # Try an arbitrary operation again to generate a realistic stack trace. 87 # Try an arbitrary operation again to generate a realistic stack trace.
88 return read_futures[0][0].Get() 88 return read_futures[0][0].Get()
89 89
90 return Future(callback=resolve) 90 return Future(callback=resolve)
91 91
92 def GetIdentity(self): 92 def GetIdentity(self):
93 return self._identity 93 return self._identity
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698