| Index: chrome/common/extensions/docs/server2/path_canonicalizer.py
|
| diff --git a/chrome/common/extensions/docs/server2/path_canonicalizer.py b/chrome/common/extensions/docs/server2/path_canonicalizer.py
|
| index fd95e9b71b32dca54d69b96648e067918216b2ad..1d8e3fc2995d767b000e2b1bd2ab12a39f79d3b9 100644
|
| --- a/chrome/common/extensions/docs/server2/path_canonicalizer.py
|
| +++ b/chrome/common/extensions/docs/server2/path_canonicalizer.py
|
| @@ -5,6 +5,7 @@
|
| from collections import defaultdict
|
| import posixpath
|
|
|
| +from future import Gettable, Future
|
| from path_util import SplitParent
|
| from special_paths import SITE_VERIFICATION_FILE
|
|
|
| @@ -34,47 +35,51 @@ class PathCanonicalizer(object):
|
| self._strip_extensions = strip_extensions
|
|
|
| def _LoadCache(self):
|
| - cached = self._cache.GetMulti(('canonical_paths',
|
| - 'simplified_paths_map')).Get()
|
| -
|
| - # |canonical_paths| is the pre-calculated set of canonical paths.
|
| - # |simplified_paths_map| is a lazily populated mapping of simplified file
|
| - # names to a list of full paths that contain them. For example,
|
| - # - browseraction: [extensions/browserAction.html]
|
| - # - storage: [apps/storage.html, extensions/storage.html]
|
| - canonical_paths, simplified_paths_map = (
|
| - cached.get('canonical_paths'), cached.get('simplified_paths_map'))
|
| -
|
| - if canonical_paths is None:
|
| - assert simplified_paths_map is None
|
| - canonical_paths = set()
|
| - simplified_paths_map = defaultdict(list)
|
| - for base, dirs, files in self._file_system.Walk(''):
|
| - for path in dirs + files:
|
| - path_without_ext, ext = posixpath.splitext(path)
|
| - canonical_path = posixpath.join(base, path_without_ext)
|
| - if (ext not in self._strip_extensions or
|
| - path == SITE_VERIFICATION_FILE):
|
| - canonical_path += ext
|
| - canonical_paths.add(canonical_path)
|
| - simplified_paths_map[_SimplifyFileName(path)].append(canonical_path)
|
| - # Store |simplified_paths_map| sorted. Ties in length are broken by taking
|
| - # the shortest, lexicographically smallest path.
|
| - for path_list in simplified_paths_map.itervalues():
|
| - path_list.sort(key=lambda p: (len(p), p))
|
| - self._cache.SetMulti({
|
| - 'canonical_paths': canonical_paths,
|
| - 'simplified_paths_map': simplified_paths_map,
|
| - })
|
| - else:
|
| - assert simplified_paths_map is not None
|
| -
|
| - return canonical_paths, simplified_paths_map
|
| + cached_future = self._cache.GetMulti(('canonical_paths',
|
| + 'simplified_paths_map'))
|
| +
|
| + def resolve():
|
| + # |canonical_paths| is the pre-calculated set of canonical paths.
|
| + # |simplified_paths_map| is a lazily populated mapping of simplified file
|
| + # names to a list of full paths that contain them. For example,
|
| + # - browseraction: [extensions/browserAction.html]
|
| + # - storage: [apps/storage.html, extensions/storage.html]
|
| + cached = cached_future.Get()
|
| + canonical_paths, simplified_paths_map = (
|
| + cached.get('canonical_paths'), cached.get('simplified_paths_map'))
|
| +
|
| + if canonical_paths is None:
|
| + assert simplified_paths_map is None
|
| + canonical_paths = set()
|
| + simplified_paths_map = defaultdict(list)
|
| + for base, dirs, files in self._file_system.Walk(''):
|
| + for path in dirs + files:
|
| + path_without_ext, ext = posixpath.splitext(path)
|
| + canonical_path = posixpath.join(base, path_without_ext)
|
| + if (ext not in self._strip_extensions or
|
| + path == SITE_VERIFICATION_FILE):
|
| + canonical_path += ext
|
| + canonical_paths.add(canonical_path)
|
| + simplified_paths_map[_SimplifyFileName(path)].append(canonical_path)
|
| + # Store |simplified_paths_map| sorted. Ties in length are broken by
|
| + # taking the shortest, lexicographically smallest path.
|
| + for path_list in simplified_paths_map.itervalues():
|
| + path_list.sort(key=lambda p: (len(p), p))
|
| + self._cache.SetMulti({
|
| + 'canonical_paths': canonical_paths,
|
| + 'simplified_paths_map': simplified_paths_map,
|
| + })
|
| + else:
|
| + assert simplified_paths_map is not None
|
| +
|
| + return canonical_paths, simplified_paths_map
|
| +
|
| + return Future(delegate=Gettable(resolve))
|
|
|
| def Canonicalize(self, path):
|
| '''Returns the canonical path for |path|.
|
| '''
|
| - canonical_paths, simplified_paths_map = self._LoadCache()
|
| + canonical_paths, simplified_paths_map = self._LoadCache().Get()
|
|
|
| # Path may already be the canonical path.
|
| if path in canonical_paths:
|
| @@ -99,3 +104,6 @@ class PathCanonicalizer(object):
|
| max_prefix, max_prefix_length = path_for_file, prefix_length
|
|
|
| return max_prefix
|
| +
|
| + def Cron(self):
|
| + return self._LoadCache()
|
|
|