From e66314769137ced25b65a248643a22af32ef1e95 Mon Sep 17 00:00:00 2001 From: Phil Crosby Date: Mon, 4 Jun 2012 22:03:10 -0700 Subject: Monitor newly visited pages and update the list of domains for completions. --- background_scripts/completion.coffee | 7 +++++-- tests/completion_test.coffee | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 040b1fdb..0a9daed0 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -163,8 +163,13 @@ class DomainCompleter # Thankfully, the domains in HistoryCache are sorted from oldest to most recent. domain = @parseDomain(entry.url) @domains[domain] = entry if domain + chrome.history.onVisited.addListener(@onPageVisited.proxy(this)) onComplete() + onPageVisited: (newPage) -> + domain = @parseDomain(newPage.url) + @domains[domain] = newPage if domain + parseDomain: (url) -> url.split("/")[2] || "" # Suggestions from the Domain completer have the maximum relevancy. They should be shown first in the list. @@ -234,8 +239,6 @@ RankingUtils = # incresingly discount older history entries. recencyScore = recencyDifference * recencyDifference * recencyDifference - - # Takes the difference of two numbers and returns a number between [0, 1] (the percentage difference). normalizeDifference: (a, b) -> max = Math.max(a, b) diff --git a/tests/completion_test.coffee b/tests/completion_test.coffee index edb1b59f..531d06b1 100644 --- a/tests/completion_test.coffee +++ b/tests/completion_test.coffee @@ -50,6 +50,7 @@ context "domain completer", @history2 = { title: "history2", url: "http://history2.com", lastVisitTime: hours(1) } stub(HistoryCache, "use", (onComplete) => onComplete([@history1, @history2])) + global.chrome.history = { onVisited: { addListener: -> } } stub(Date, "now", returns(hours(24))) @completer = new DomainCompleter() -- cgit v1.2.3