Bug 1543341 - Refine Safe Browsing log output. r=baku
authordlee <dlee@mozilla.com>
Thu, 11 Apr 2019 18:57:56 +0000
changeset 469072 186322f1d1f212f92a5a925814a5869e9c78d19b
parent 469071 c523c4658e98d236594a1124820a0b142300e6cd
child 469073 e56cd039fd9461b9946ac166a6c2a0a12664adb3
push id35856
push usercsabou@mozilla.com
push dateFri, 12 Apr 2019 03:19:48 +0000
treeherdermozilla-central@940684cd1065 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1543341
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1543341 - Refine Safe Browsing log output. r=baku After calling Lookup API per table, Safe Browsing outputs too many debug message for a single URL lookup. Refine the current output. Differential Revision: https://phabricator.services.mozilla.com/D27066
toolkit/components/url-classifier/Classifier.cpp
toolkit/components/url-classifier/LookupCache.cpp
toolkit/components/url-classifier/LookupCacheV4.cpp
--- a/toolkit/components/url-classifier/Classifier.cpp
+++ b/toolkit/components/url-classifier/Classifier.cpp
@@ -404,49 +404,58 @@ void Classifier::TableRequest(nsACString
   mTableRequestResult = aResult;
   mIsTableRequestResultOutdated = false;
 }
 
 nsresult Classifier::CheckURIFragments(
     const nsTArray<nsCString>& aSpecFragments, const nsACString& aTable,
     LookupResultArray& aResults) {
   // A URL can form up to 30 different fragments
+  MOZ_ASSERT(aSpecFragments.Length() != 0);
   MOZ_ASSERT(aSpecFragments.Length() <=
              (MAX_HOST_COMPONENTS * (MAX_PATH_COMPONENTS + 2)));
 
-  LOG(("Checking table %s", aTable.BeginReading()));
+  if (LOG_ENABLED()) {
+    uint32_t urlIdx = 0;
+    for (uint32_t i = 1; i < aSpecFragments.Length(); i++) {
+      if (aSpecFragments[urlIdx].Length() < aSpecFragments[i].Length()) {
+        urlIdx = i;
+      }
+    }
+    LOG(("Checking table %s, URL is %s", aTable.BeginReading(), aSpecFragments[urlIdx].get()));
+  }
+
   RefPtr<LookupCache> cache = GetLookupCache(aTable);
   if (NS_WARN_IF(!cache)) {
     return NS_ERROR_FAILURE;
   }
 
   // Now check each lookup fragment against the entries in the DB.
   for (uint32_t i = 0; i < aSpecFragments.Length(); i++) {
     Completion lookupHash;
     lookupHash.FromPlaintext(aSpecFragments[i]);
 
-    if (LOG_ENABLED()) {
-      nsAutoCString checking;
-      lookupHash.ToHexString(checking);
-      LOG(("Checking fragment %s, hash %s (%X)", aSpecFragments[i].get(),
-           checking.get(), lookupHash.ToUint32()));
-    }
-
     bool has, confirmed;
     uint32_t matchLength;
 
     nsresult rv = cache->Has(lookupHash, &has, &matchLength, &confirmed);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (has) {
       RefPtr<LookupResult> result = new LookupResult;
       aResults.AppendElement(result);
 
-      LOG(("Found a result in %s: %s", cache->TableName().get(),
-           confirmed ? "confirmed." : "Not confirmed."));
+      if (LOG_ENABLED()) {
+        nsAutoCString checking;
+        lookupHash.ToHexString(checking);
+        LOG(("Found a result in fragment %s, hash %s (%X)", aSpecFragments[i].get(),
+             checking.get(), lookupHash.ToUint32()));
+        LOG(("Result %s, match %d-bytes prefix", confirmed ? "confirmed." : "Not confirmed.",
+             matchLength));
+      }
 
       result->hash.complete = lookupHash;
       result->mConfirmed = confirmed;
       result->mTableName.Assign(cache->TableName());
       result->mPartialHashLength = confirmed ? COMPLETE_SIZE : matchLength;
       result->mProtocolV2 = LookupCache::Cast<LookupCacheV2>(cache);
     }
   }
--- a/toolkit/components/url-classifier/LookupCache.cpp
+++ b/toolkit/components/url-classifier/LookupCache.cpp
@@ -366,17 +366,16 @@ nsresult LookupCache::GetLookupFragments
   paths.AppendElement(EmptyCString());
 
   for (uint32_t hostIndex = 0; hostIndex < hosts.Length(); hostIndex++) {
     for (uint32_t pathIndex = 0; pathIndex < paths.Length(); pathIndex++) {
       nsCString key;
       key.Assign(hosts[hostIndex]);
       key.Append('/');
       key.Append(paths[pathIndex]);
-      LOG(("Checking fragment %s", key.get()));
 
       aFragments->AppendElement(key);
     }
   }
 
   return NS_OK;
 }
 
@@ -553,19 +552,16 @@ nsresult LookupCacheV2::Has(const Comple
     *aMatchLength = COMPLETE_SIZE;
     *aConfirmed = true;
   }
 
   if (*aHas && !(*aConfirmed)) {
     rv = CheckCache(aCompletion, aHas, aConfirmed);
   }
 
-  LOG(("Probe in %s: %X, has %d, confirmed %d", mTableName.get(), prefix, *aHas,
-       *aConfirmed));
-
   return rv;
 }
 
 bool LookupCacheV2::IsEmpty() const {
   bool isEmpty;
   mPrefixSet->IsEmpty(&isEmpty);
   return isEmpty;
 }
--- a/toolkit/components/url-classifier/LookupCacheV4.cpp
+++ b/toolkit/components/url-classifier/LookupCacheV4.cpp
@@ -199,22 +199,16 @@ nsresult LookupCacheV4::Has(const Comple
   nsresult rv = mVLPrefixSet->Matches(fullhash, &length);
   NS_ENSURE_SUCCESS(rv, rv);
 
   MOZ_ASSERT(length == 0 || (length >= PREFIX_SIZE && length <= COMPLETE_SIZE));
 
   *aHas = length >= PREFIX_SIZE;
   *aMatchLength = length;
 
-  if (LOG_ENABLED()) {
-    uint32_t prefix = aCompletion.ToUint32();
-    LOG(("Probe in V4 %s: %X, found %d, complete %d", mTableName.get(), prefix,
-         *aHas, length == COMPLETE_SIZE));
-  }
-
   // Check if fullhash match any prefix in the local database
   if (!(*aHas)) {
     return NS_OK;
   }
 
   // Even though V4 supports variable-length prefix, we always send 4-bytes for
   // completion (Bug 1323953). This means cached prefix length is also 4-bytes.
   return CheckCache(aCompletion, aHas, aConfirmed);