Bug 997872 - Only consider SafeBrowsing tables that need updating for delay calculation. r=mmc
authorGian-Carlo Pascutto <gpascutto@mozilla.com>
Tue, 22 Apr 2014 15:11:53 +0200
changeset 179929 2a9610eb15b29afbcacc4c40bfafd697679401d6
parent 179928 452c9f6332bc7b78ad9dfa40458ffd8d987f45d0
child 179930 dd9b23471fc136175f8e0d246e27cdb515d706ab
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersmmc
bugs997872
milestone31.0a1
Bug 997872 - Only consider SafeBrowsing tables that need updating for delay calculation. r=mmc
toolkit/components/url-classifier/SafeBrowsing.jsm
toolkit/components/url-classifier/content/listmanager.js
--- a/toolkit/components/url-classifier/SafeBrowsing.jsm
+++ b/toolkit/components/url-classifier/SafeBrowsing.jsm
@@ -8,17 +8,22 @@ const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 Cu.import("resource://gre/modules/Services.jsm");
 
 // Skip all the ones containining "test", because we never need to ask for
 // updates for them.
 function getLists(prefName) {
-  return Services.prefs.getCharPref(prefName).split(",")
+  let pref = Services.prefs.getCharPref(prefName);
+  // Splitting an empty string returns [''], we really want an empty array.
+  if (!pref) {
+    return [];
+  }
+  return pref.split(",")
     .filter(function(value) { return value.indexOf("test-") == -1; })
     .map(function(value) { return value.trim(); });
 }
 
 // These may be a comma-separated lists of tables.
 const phishingLists = getLists("urlclassifier.phish_table");
 const malwareLists = getLists("urlclassifier.malware_table");
 const downloadBlockLists = getLists("urlclassifier.downloadBlockTable");
--- a/toolkit/components/url-classifier/content/listmanager.js
+++ b/toolkit/components/url-classifier/content/listmanager.js
@@ -183,23 +183,37 @@ PROT_ListManager.prototype.maybeStartMan
   if (this.isTesting_)
     return;
 
   // We might have been told about tables already, so see if we should be
   // actually updating.
   this.maybeToggleUpdateChecking();
 }
 
-PROT_ListManager.prototype.kickoffUpdate_ = function (tableData)
+/**
+ * Acts as a nsIUrlClassifierCallback for getTables.
+ */
+PROT_ListManager.prototype.kickoffUpdate_ = function (onDiskTableData)
 {
   this.startingUpdate_ = false;
+  var initialUpdateDelay = 3000;
+
+  // Check if any table registered for updates has ever been downloaded.
+  var diskTablesAreUpdating = false;
+  for (var tableName in this.tablesData) {
+    if (this.tablesData[tableName].needsUpdate) {
+      if (onDiskTableData.indexOf(tableName) != -1) {
+        diskTablesAreUpdating = true;
+      }
+    }
+  }
+
   // If the user has never downloaded tables, do the check now.
   // If the user has tables, add a fuzz of a few minutes.
-  var initialUpdateDelay = 3000;
-  if (tableData != "") {
+  if (diskTablesAreUpdating) {
     // Add a fuzz of 0-5 minutes.
     initialUpdateDelay += Math.floor(Math.random() * (5 * 60 * 1000));
   }
 
   this.currentUpdateChecker_ =
     new G_Alarm(BindToObject(this.checkForUpdates, this),
                 initialUpdateDelay);
 }