Bug 1373121 - about:url-classifier: Support get back-off time. r?francois draft
authorDimiL <dlee@mozilla.com>
Thu, 15 Jun 2017 11:41:13 +0800
changeset 595106 7818cf08d99361e6bd38674c11eabb4eb2b16a97
parent 594149 da66c4a05fda49d457d9411a7092fed87cf9e53a
child 633627 da3dc64f4e65d44685bf237a06d687434cc32099
push id64250
push userbmo:dlee@mozilla.com
push dateFri, 16 Jun 2017 02:02:43 +0000
reviewersfrancois
bugs1373121
milestone56.0a1
Bug 1373121 - about:url-classifier: Support get back-off time. r?francois MozReview-Commit-ID: 6Q83TOo7jHK
toolkit/components/url-classifier/content/listmanager.js
toolkit/components/url-classifier/nsIUrlListManager.idl
toolkit/content/aboutUrlClassifier.js
toolkit/content/aboutUrlClassifier.xhtml
toolkit/locales/en-US/chrome/global/aboutUrlClassifier.dtd
--- a/toolkit/components/url-classifier/content/listmanager.js
+++ b/toolkit/components/url-classifier/content/listmanager.js
@@ -596,16 +596,37 @@ PROT_ListManager.prototype.downloadError
   this.updateCheckers_[updateUrl] =
     new G_Alarm(BindToObject(this.checkForUpdates, this, updateUrl),
                 delay, false);
 
   Services.obs.notifyObservers(null, "safebrowsing-update-finished",
                                "download error: " + status);
 }
 
+/**
+ * Get back-off time for the given provider.
+ * Return 0 if we are not in back-off mode.
+ */
+PROT_ListManager.prototype.getBackOffTime = function(provider) {
+  let updateUrl = "";
+  for (var table in this.tablesData) {
+    if (this.tablesData[table].provider == provider) {
+      updateUrl = this.tablesData[table].updateUrl;
+      break;
+    }
+  }
+
+  if (!updateUrl || !this.requestBackoffs_[updateUrl]) {
+    return 0;
+  }
+
+  let delay = this.requestBackoffs_[updateUrl].nextRequestDelay();
+  return delay == 0 ? 0 : Date.now() + delay;
+}
+
 PROT_ListManager.prototype.QueryInterface = function(iid) {
   if (iid.equals(Ci.nsISupports) ||
       iid.equals(Ci.nsIUrlListManager) ||
       iid.equals(Ci.nsITimerCallback))
     return this;
 
   throw Components.results.NS_ERROR_NO_INTERFACE;
 }
--- a/toolkit/components/url-classifier/nsIUrlListManager.idl
+++ b/toolkit/components/url-classifier/nsIUrlListManager.idl
@@ -70,9 +70,16 @@ interface nsIUrlListManager : nsISupport
     void safeLookup(in nsIPrincipal key,
                     in nsIUrlListManagerCallback cb);
 
     /**
      * This is currently used by about:url-classifier to force an update
      * for the update url. Update may still fail because of backoff algorithm.
      */
     boolean checkForUpdates(in ACString updateUrl);
+
+    /**
+     * This is currently used by about:url-classifier to get back-off time
+     * (in millisecond since epoch) for the given provider. Return 0 if we
+     * are not in back-off mode.
+     */
+    uint64_t getBackOffTime(in ACString provider);
 };
--- a/toolkit/content/aboutUrlClassifier.js
+++ b/toolkit/content/aboutUrlClassifier.js
@@ -151,16 +151,21 @@ var Provider = {
       let pref = "browser.safebrowsing.provider." + provider + ".lastupdatetime";
       let lut = Services.prefs.getCharPref(pref, "");
       values["col-lastupdatetime"] = lut ? new Date(lut * 1) : STR_NA;
 
       pref = "browser.safebrowsing.provider." + provider + ".nextupdatetime";
       let nut = Services.prefs.getCharPref(pref, "");
       values["col-nextupdatetime"] = nut ? new Date(nut * 1) : STR_NA;
 
+      let listmanager = Cc["@mozilla.org/url-classifier/listmanager;1"]
+                        .getService(Ci.nsIUrlListManager);
+      let bot = listmanager.getBackOffTime(provider);
+      values["col-backofftime"] = bot ? new Date(bot * 1) : STR_NA;
+
       for (let key of Object.keys(values)) {
         let elem = document.getElementById(provider + "-" + key);
         elem.childNodes[0].nodeValue = values[key];
       }
     }
   },
 
   // Call update for the provider.
--- a/toolkit/content/aboutUrlClassifier.xhtml
+++ b/toolkit/content/aboutUrlClassifier.xhtml
@@ -23,16 +23,17 @@
   <div id="provider">
     <h2 class="major-section">&aboutUrlClassifier.providerTitle;</h2>
     <table id="provider-table">
       <thead>
         <tr id="provider-head-row">
           <th id="col-provider">&aboutUrlClassifier.provider;</th>
           <th id="col-lastupdatetime">&aboutUrlClassifier.providerLastUpdateTime;</th>
           <th id="col-nextupdatetime">&aboutUrlClassifier.providerNextUpdateTime;</th>
+          <th id="col-backofftime">&aboutUrlClassifier.providerBackOffTime;</th>
           <th id="col-lastupdateresult">&aboutUrlClassifier.providerLastUpdateStatus;</th>
           <th id="col-update">&aboutUrlClassifier.providerUpdateBtn;</th>
         </tr>
       </thead>
       <tbody id="provider-table-body">
         <!-- data is generated in javascript -->
       </tbody>
     </table>
--- a/toolkit/locales/en-US/chrome/global/aboutUrlClassifier.dtd
+++ b/toolkit/locales/en-US/chrome/global/aboutUrlClassifier.dtd
@@ -3,16 +3,17 @@
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <!-- LOCALIZATION NOTE the term "url-classifier" should not be translated. -->
 <!ENTITY aboutUrlClassifier.pageTitle                   "Information about the url-classifier">
 <!ENTITY aboutUrlClassifier.providerTitle               "Provider">
 <!ENTITY aboutUrlClassifier.provider                    "Provider">
 <!ENTITY aboutUrlClassifier.providerLastUpdateTime      "Last update time">
 <!ENTITY aboutUrlClassifier.providerNextUpdateTime      "Next update time">
+<!ENTITY aboutUrlClassifier.providerBackOffTime         "Back-off time">
 <!ENTITY aboutUrlClassifier.providerLastUpdateStatus    "Last update status">
 <!ENTITY aboutUrlClassifier.providerUpdateBtn           "Update">
 <!ENTITY aboutUrlClassifier.cacheTitle                  "Cache">
 <!ENTITY aboutUrlClassifier.cacheRefreshBtn             "Refresh">
 <!ENTITY aboutUrlClassifier.cacheClearBtn               "Clear">
 <!ENTITY aboutUrlClassifier.cacheTableName              "Table name">
 <!ENTITY aboutUrlClassifier.cacheNCacheEntries          "Number of negative cache entries">
 <!ENTITY aboutUrlClassifier.cachePCacheEntries          "Number of positive cache entries">