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

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

Issue 417163004: Docserver: Update Future.Then() to be more Promise-like (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 import posixpath 5 import posixpath
6 6
7 from file_system import FileSystem, FileNotFoundError 7 from file_system import FileSystem, FileNotFoundError
8 from future import Future 8 from future import Future
9 from test_file_system import _List, _StatTracker, TestFileSystem 9 from test_file_system import _List, _StatTracker, TestFileSystem
10 from path_util import IsDirectory 10 from path_util import IsDirectory
(...skipping 24 matching lines...) Expand all
35 35
36 # 36 #
37 # FileSystem implementation. 37 # FileSystem implementation.
38 # 38 #
39 39
40 def Read(self, paths, skip_not_found=False): 40 def Read(self, paths, skip_not_found=False):
41 '''Reads |paths| from |_file_system|, then applies the most recent update 41 '''Reads |paths| from |_file_system|, then applies the most recent update
42 from |_updates|, if any. 42 from |_updates|, if any.
43 ''' 43 '''
44 self._read_count += 1 44 self._read_count += 1
45 future_result = self._file_system.Read(paths, skip_not_found=skip_not_found) 45 def next(result):
46 def resolve():
47 self._read_resolve_count += 1 46 self._read_resolve_count += 1
48 result = future_result.Get()
49 for path in result.iterkeys(): 47 for path in result.iterkeys():
50 update = self._GetMostRecentUpdate(path) 48 update = self._GetMostRecentUpdate(path)
51 if update is not None: 49 if update is not None:
52 result[path] = update 50 result[path] = update
53 return result 51 return result
54 return Future(callback=resolve) 52 return self._file_system.Read(paths,
53 skip_not_found=skip_not_found).Then(next)
55 54
56 def Refresh(self): 55 def Refresh(self):
57 return self._file_system.Refresh() 56 return self._file_system.Refresh()
58 57
59 def _GetMostRecentUpdate(self, path): 58 def _GetMostRecentUpdate(self, path):
60 '''Returns the latest update for the file at |path|, or None if |path| 59 '''Returns the latest update for the file at |path|, or None if |path|
61 has never been updated. 60 has never been updated.
62 ''' 61 '''
63 for update in reversed(self._updates): 62 for update in reversed(self._updates):
64 try: 63 try:
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 self._read_resolve_count = 0 123 self._read_resolve_count = 0
125 self._stat_count = 0 124 self._stat_count = 0
126 125
127 def Update(self, update): 126 def Update(self, update):
128 self._updates.append(TestFileSystem(update)) 127 self._updates.append(TestFileSystem(update))
129 for path in _List(update).iterkeys(): 128 for path in _List(update).iterkeys():
130 # Any files (not directories) which changed are now at the version 129 # Any files (not directories) which changed are now at the version
131 # derived from |_updates|. 130 # derived from |_updates|.
132 if not IsDirectory(path): 131 if not IsDirectory(path):
133 self._stat_tracker.SetVersion(path, len(self._updates)) 132 self._stat_tracker.SetVersion(path, len(self._updates))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698