private T GetChromeRootFolderWorker(FullPathName filename, Func <FullPathName, T> factory)
        {
            var root = _chromiumDiscovery.GetEnlistmentRoot(filename);

            if (root == default(FullPathName))
            {
                lock (_lock) {
                    // No one in the parent chain is a Chromium directory.
                    filename.EnumerateParents().ForAll(x => _nonChromiumDirectories.Add(x, null));
                }
                return(default(T));
            }

            var result = factory(root);

            lock (_lock) {
                _chromiumRootDirectories.Add(root, result);
            }
            return(result);
        }
        public T GetEnlistmentRootFromFilename(FullPathName filename, Func <FullPathName, T> factory)
        {
            lock (_lock) {
                // Cache hit?
                foreach (var parent in filename.EnumerateParents())
                {
                    T value;
                    if (_chromiumRootDirectories.TryGet(parent, out value))
                    {
                        return(value);
                    }
                }

                // Negative cache hit?
                if (_nonChromiumDirectories.Contains(filename.Parent))
                {
                    return(default(T));
                }
            }

            // Nope: compute all the way...
            return(GetChromeRootFolderWorker(filename, factory));
        }