diff options
| author | Stephen Blott | 2012-11-11 16:31:17 +0000 | 
|---|---|---|
| committer | Stephen Blott | 2012-11-11 16:31:17 +0000 | 
| commit | 0a8443d30dde0b7ba914a742182a1900baae2836 (patch) | |
| tree | 41354d8186f7f6ac526927325486f63731b08fe9 /background_scripts/completion.coffee | |
| parent | 2071873f5c9f496e4fde94d44cbf8b0e50bf4c21 (diff) | |
| download | vimium-0a8443d30dde0b7ba914a742182a1900baae2836.tar.bz2 | |
Refactor domain maintenance code.
Diffstat (limited to 'background_scripts/completion.coffee')
| -rw-r--r-- | background_scripts/completion.coffee | 22 | 
1 files changed, 6 insertions, 16 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index c12c6d80..95c50baf 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -200,29 +200,19 @@ class DomainCompleter    populateDomains: (onComplete) ->      HistoryCache.use (history) =>        @domains = {} -      history.forEach (entry) => -        # We want each key in our domains hash to point to the most recent History entry for that domain. -        domain = @parseDomain(entry.url) -        if domain -          previousEntry = @domains[domain] -          if previousEntry -            previousEntry.entry = entry if previousEntry.lastVisitTime < entry.lastVisitTime -            previousEntry.referenceCount +=1 -          else -            @domains[domain] = { entry: entry, referenceCount: 1 } +      history.forEach (entry) => @onPageVisited entry        chrome.history.onVisited.addListener(@onPageVisited.bind(this))        chrome.history.onVisitRemoved.addListener(@onVisitRemoved.bind(this))        onComplete() +  # We want each key in our domains hash to point to the most recent History entry for that domain.    onPageVisited: (newPage) ->      domain = @parseDomain(newPage.url)      if domain -      previousEntry = @domains[domain] -      if previousEntry -        previousEntry.entry = newPage -        previousEntry.referenceCount += 1 -      else -        @domains[domain] = { entry: newPage, referenceCount: 1 } +      @domains[domain] ||= { entry: newPage, referenceCount: 0 } +      slot = @domains[domain] +      slot.entry = newPage if slot.entry.lastVisitTime < newPage.lastVisitTime +      slot.referenceCount += 1    onVisitRemoved: (toRemove) ->      if toRemove.allHistory  | 
