OLD | NEW |
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 logging | 5 import logging |
6 import mimetypes | 6 import mimetypes |
7 import posixpath | 7 import posixpath |
8 import traceback | 8 import traceback |
9 | 9 |
10 from compiled_file_system import SingleFile | 10 from compiled_file_system import SingleFile |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 .Then(get_index_if_directory_exists)) | 190 .Then(get_index_if_directory_exists)) |
191 | 191 |
192 # Try to find a file with the right name. If not, and it's a directory, | 192 # Try to find a file with the right name. If not, and it's a directory, |
193 # look for an index file in that directory. If nothing at all is found, | 193 # look for an index file in that directory. If nothing at all is found, |
194 # return the original |path| - its nonexistence will be caught up the stack. | 194 # return the original |path| - its nonexistence will be caught up the stack. |
195 return (find_file_with_name(path) | 195 return (find_file_with_name(path) |
196 .Then(lambda found: found or find_index_file()) | 196 .Then(lambda found: found or find_index_file()) |
197 .Then(lambda found: found or path)) | 197 .Then(lambda found: found or path)) |
198 | 198 |
199 def Cron(self): | 199 def Cron(self): |
200 futures = [self._path_canonicalizer.Cron()] | 200 def map_cron_paths(op): |
201 for root, _, files in self.file_system.Walk(''): | 201 results = [] |
202 for f in files: | 202 for root, _, files in self.file_system.Walk(''): |
203 futures.append(self.GetContentAndType(Join(root, f))) | 203 for f in files: |
204 # Also cache the extension-less version of the file if needed. | 204 results.append(op(Join(root, f))) |
205 base, ext = posixpath.splitext(f) | 205 # Also cache the extension-less version of the file if needed. |
206 if f != SITE_VERIFICATION_FILE and ext in self._default_extensions: | 206 base, ext = posixpath.splitext(f) |
207 futures.append(self.GetContentAndType(Join(root, base))) | 207 if f != SITE_VERIFICATION_FILE and ext in self._default_extensions: |
208 # TODO(kalman): Cache .zip files for each directory (if supported). | 208 results.append(op(Join(root, base))) |
209 return All(futures, except_pass=Exception, except_pass_log=True) | 209 # TODO(kalman): Cache .zip files for each directory (if supported). |
| 210 return results |
| 211 |
| 212 # XXX(kalman): Need to do this stuff in APIModels as well - basically |
| 213 # anywhere the _patch logic has been implemented. Err, sort of. |
| 214 # Has it been implemented in here? Does it need to be? |
| 215 |
| 216 # Immediately stat everything so that files are guaranteed to be eventually |
| 217 # up to date. See http://crbug.com/398042 for background. |
| 218 All(map_cron_paths(self.GetVersion)).Get() |
| 219 |
| 220 # Update content in the future. |
| 221 futures = [('<path_canonicalizer>', # semi-arbitrary string since there is |
| 222 # no path associated with this Future. |
| 223 self._path_canonicalizer.Cron())] |
| 224 futures += map_cron_paths(lambda path: (path, self.GetContentAndType(path))) |
| 225 def resolve(): |
| 226 for label, future in futures: |
| 227 try: future.Get() |
| 228 except: logging.error('%s: %s' % (label, traceback.format_exc())) |
| 229 return Future(callback=resolve) |
210 | 230 |
211 def __repr__(self): | 231 def __repr__(self): |
212 return 'ContentProvider of <%s>' % repr(self.file_system) | 232 return 'ContentProvider of <%s>' % repr(self.file_system) |
OLD | NEW |