Bug 1164518 - Minor optimizations for Safe Browsing completions. r?gcp
- added an early exit to skip table string comparisons on a 204
- removed an unnecessary NS_WARNING on gethash errors (e.g. 503s)
- do the noise check first since it's the majority of completions
MozReview-Commit-ID: Lqae5DbUrs8
--- a/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
@@ -172,16 +172,20 @@ nsUrlClassifierDBServiceWorker::DoLocalL
LOG(("Found %d results.", results->Length()));
return NS_OK;
}
static nsresult
TablesToResponse(const nsACString& tables)
{
+ if (tables.IsEmpty()) {
+ return NS_OK;
+ }
+
// We don't check mCheckMalware and friends because BuildTables never
// includes a table that is not enabled.
if (FindInReadable(NS_LITERAL_CSTRING("-malware-"), tables)) {
return NS_ERROR_MALWARE_URI;
}
if (FindInReadable(NS_LITERAL_CSTRING("-phish-"), tables)) {
return NS_ERROR_PHISHING_URI;
}
@@ -871,20 +875,21 @@ nsUrlClassifierLookupCallback::LookupCom
}
return NS_OK;
}
NS_IMETHODIMP
nsUrlClassifierLookupCallback::CompletionFinished(nsresult status)
{
- LOG(("nsUrlClassifierLookupCallback::CompletionFinished [%p, %08x]",
- this, status));
- if (NS_FAILED(status)) {
- NS_WARNING("gethash response failed.");
+ if (LOG_ENABLED()) {
+ nsAutoCString errorName;
+ mozilla::GetErrorName(status, errorName);
+ LOG(("nsUrlClassifierLookupCallback::CompletionFinished [%p, %s]",
+ this, errorName.get()));
}
mPendingCompletions--;
if (mPendingCompletions == 0) {
HandleResults();
}
return NS_OK;
@@ -947,21 +952,23 @@ nsUrlClassifierLookupCallback::HandleRes
nsTArray<nsCString> tables;
// Build a stringified list of result tables.
for (uint32_t i = 0; i < mResults->Length(); i++) {
LookupResult& result = mResults->ElementAt(i);
// Leave out results that weren't confirmed, as their existence on
// the list can't be verified. Also leave out randomly-generated
// noise.
- if (!result.Confirmed()) {
- LOG(("Skipping result from table %s (not confirmed)", result.mTableName.get()));
+ if (result.mNoise) {
+ LOG(("Skipping result %X from table %s (noise)",
+ result.hash.prefix.ToUint32(), result.mTableName.get()));
continue;
- } else if (result.mNoise) {
- LOG(("Skipping result from table %s (noise)", result.mTableName.get()));
+ } else if (!result.Confirmed()) {
+ LOG(("Skipping result %X from table %s (not confirmed)",
+ result.hash.prefix.ToUint32(), result.mTableName.get()));
continue;
}
LOG(("Confirmed result %X from table %s",
result.hash.prefix.ToUint32(), result.mTableName.get()));
if (tables.IndexOf(result.mTableName) == nsTArray<nsCString>::NoIndex) {
tables.AppendElement(result.mTableName);