Bug 420370: nsUrlClassifierHashCompleter not configured immediately at startup. r=tony, blocking-firefox3=beltzner

This commit is contained in:
dcamp@mozilla.com 2008-03-04 14:05:05 -08:00
parent d3365453db
commit 09fbf95030
5 changed files with 26 additions and 35 deletions

View File

@ -105,7 +105,7 @@ function PROT_ListManager() {
.getService(Ci.nsIUrlClassifierDBService);
this.hashCompleter_ = Cc["@mozilla.org/url-classifier/hashcompleter;1"]
.createInstance(Ci.nsIUrlClassifierHashCompleter);
.getService(Ci.nsIUrlClassifierHashCompleter);
}
/**
@ -178,7 +178,6 @@ PROT_ListManager.prototype.registerTable = function(tableName,
opt_requireMac) {
this.tablesData[tableName] = {};
this.tablesData[tableName].needsUpdate = false;
this.dbService_.setHashCompleter(tableName, this.hashCompleter_);
return true;
}

View File

@ -3720,6 +3720,18 @@ nsUrlClassifierDBService::CacheCompletions(nsTArray<nsUrlClassifierLookupResult>
return mWorkerProxy->CacheCompletions(results);
}
PRBool
nsUrlClassifierDBService::GetCompleter(const nsACString &tableName,
nsIUrlClassifierHashCompleter **completer)
{
if (mCompleters.Get(tableName, completer)) {
return PR_TRUE;
}
return NS_SUCCEEDED(CallGetService(NS_URLCLASSIFIERHASHCOMPLETER_CONTRACTID,
completer));
}
NS_IMETHODIMP
nsUrlClassifierDBService::Observe(nsISupports *aSubject, const char *aTopic,
const PRUnichar *aData)

View File

@ -87,10 +87,7 @@ public:
NS_DECL_NSIOBSERVER
PRBool GetCompleter(const nsACString& tableName,
nsIUrlClassifierHashCompleter** completer) {
return mCompleters.Get(tableName, completer);
}
nsIUrlClassifierHashCompleter** completer);
nsresult CacheCompletions(nsTArray<nsUrlClassifierLookupResult> *results);
private:

View File

@ -530,9 +530,13 @@ nsUrlClassifierHashCompleter::Complete(const nsACString &partialHash,
return NS_ERROR_OUT_OF_MEMORY;
}
// If we don't have a gethash url yet, don't bother scheduling
// the request until we have one.
if (!mGethashUrl.IsEmpty()) {
// Schedule ourselves to start this request on the main loop.
NS_DispatchToCurrentThread(this);
}
}
return mRequest->Add(partialHash, c);
}
@ -541,6 +545,12 @@ NS_IMETHODIMP
nsUrlClassifierHashCompleter::SetGethashUrl(const nsACString &url)
{
mGethashUrl = url;
if (mRequest) {
// Schedule any pending request.
NS_DispatchToCurrentThread(this);
}
return NS_OK;
}

View File

@ -318,32 +318,6 @@ function testMixedSizesDifferentDomains() {
doTest([update1, update2], assertions);
}
function testMixedSizesNoCompleter() {
var add1Urls = [ "foo.com/a" ];
var add2Urls = [ "foo.com/b" ];
var update1 = buildPhishingUpdate(
[
{ "chunkNum" : 1,
"urls" : add1Urls }],
4);
var update2 = buildPhishingUpdate(
[
{ "chunkNum" : 2,
"urls" : add2Urls }],
32);
var assertions = {
"tableData" : "test-phish-simple;a:1-2",
// add1Urls shouldn't work, because there is no completer.
"urlsDontExist" : add1Urls,
// but add2Urls were complete, they should work.
"urlsExist" : add2Urls
};
doTest([update1, update2], assertions);
}
function testInvalidHashSize()
{
var addUrls = [ "foo.com/a", "foo.com/b", "bar.com/c" ];
@ -530,7 +504,6 @@ function run_test()
testCompleterFailure,
testMixedSizesSameDomain,
testMixedSizesDifferentDomains,
testMixedSizesNoCompleter,
testInvalidHashSize,
testCachedResults,
testCachedResultsWithSub,