Bug 1164518 - Minor optimizations for Safe Browsing completions. r?gcp draft
authorFrancois Marier <francois@mozilla.com>
Wed, 02 Mar 2016 14:55:44 -0800
changeset 336250 f510f63b93af675aa5fe16da201328bad2d97b4d
parent 336249 fa106540989ac239884f8fc0ff2a6f1310aea01b
child 336251 725505ecce4104b4707ad0d4ff8875bf24cac385
child 336644 01ac84938aeea192b5412e19a4898511f21c6267
child 336970 39939bd53d23261a908b6286582512e9f3be38bc
child 337035 6f8f8f0ed995c5a6f40d24fa4c67107ef1668be4
push id12024
push userfmarier@mozilla.com
push dateWed, 02 Mar 2016 23:56:55 +0000
reviewersgcp
bugs1164518
milestone47.0a1
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
toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
--- 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);