Client code for Bug 1309125 - Allow configuration of the download throttle via the update.xml. r=mhowell, a=rkothari
authorRobert Strong <robert.bugzilla@gmail.com>
Wed, 19 Oct 2016 11:50:01 -0700
changeset 356174 9a7b518552dd
parent 356173 698191832c64
child 356175 f1e1d246b097
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmhowell, rkothari
bugs1309125
milestone51.0a2
Client code for Bug 1309125 - Allow configuration of the download throttle via the update.xml. r=mhowell, a=rkothari
toolkit/mozapps/update/nsUpdateService.js
--- a/toolkit/mozapps/update/nsUpdateService.js
+++ b/toolkit/mozapps/update/nsUpdateService.js
@@ -1520,16 +1520,18 @@ function Update(update) {
   this._patches = [];
   this.isCompleteUpdate = false;
   this.isOSUpdate = false;
   this.showPrompt = false;
   this.showNeverForVersion = false;
   this.unsupported = false;
   this.channel = "default";
   this.promptWaitTime = getPref("getIntPref", PREF_APP_UPDATE_PROMPTWAITTIME, 43200);
+  this.backgroundInterval = getPref("getIntPref", PREF_APP_UPDATE_BACKGROUNDINTERVAL,
+                                    DOWNLOAD_BACKGROUND_INTERVAL);
 
   // Null <update>, assume this is a message container and do no
   // further initialization
   if (!update) {
     return;
   }
 
   const ELEMENT_NODE = Ci.nsIDOMNode.ELEMENT_NODE;
@@ -1580,16 +1582,20 @@ function Update(update) {
     } else if (attr.name == "showNeverForVersion") {
       this.showNeverForVersion = attr.value == "true";
     } else if (attr.name == "showPrompt") {
       this.showPrompt = attr.value == "true";
     } else if (attr.name == "promptWaitTime") {
       if (!isNaN(attr.value)) {
         this.promptWaitTime = parseInt(attr.value);
       }
+    } else if (attr.name == "backgroundInterval") {
+      if (!isNaN(attr.value)) {
+        this.backgroundInterval = parseInt(attr.value);
+      }
     } else if (attr.name == "unsupported") {
       this.unsupported = attr.value == "true";
     } else {
       this[attr.name] = attr.value;
 
       switch (attr.name) {
         case "appVersion":
         case "buildID":
@@ -1610,16 +1616,19 @@ function Update(update) {
       }
     }
   }
 
   if (!this.displayVersion) {
     this.displayVersion = this.appVersion;
   }
 
+  // Don't allow the background interval to be greater than 10 minutes.
+  this.backgroundInterval = Math.min(this.backgroundInterval, 600);
+
   // The Update Name is either the string provided by the <update> element, or
   // the string: "<App Name> <Update App Version>"
   var name = "";
   if (update.hasAttribute("name")) {
     name = update.getAttribute("name");
   } else {
     var brandBundle = Services.strings.createBundle(URI_BRAND_PROPERTIES);
     var appName = brandBundle.GetStringFromName("brandShortName");
@@ -1713,16 +1722,17 @@ Update.prototype = {
     update.setAttribute("installDate", this.installDate);
     update.setAttribute("isCompleteUpdate", this.isCompleteUpdate);
     update.setAttribute("isOSUpdate", this.isOSUpdate);
     update.setAttribute("name", this.name);
     update.setAttribute("serviceURL", this.serviceURL);
     update.setAttribute("showNeverForVersion", this.showNeverForVersion);
     update.setAttribute("showPrompt", this.showPrompt);
     update.setAttribute("promptWaitTime", this.promptWaitTime);
+    update.setAttribute("backgroundInterval", this.backgroundInterval);
     update.setAttribute("type", this.type);
 
     if (this.detailsURL) {
       update.setAttribute("detailsURL", this.detailsURL);
     }
     if (this.previousAppVersion) {
       update.setAttribute("previousAppVersion", this.previousAppVersion);
     }
@@ -3855,27 +3865,26 @@ Downloader.prototype = {
 
         if (!isInterruptedUpdate(status) && patchFile.exists()) {
           // Remove stale patchFile
           patchFile.remove(false);
         }
       }
     }
 
+    update.QueryInterface(Ci.nsIPropertyBag);
+    let interval = this.background ? update.getProperty("backgroundInterval")
+                                   : DOWNLOAD_FOREGROUND_INTERVAL;
+
     var uri = Services.io.newURI(this._patch.URL, null, null);
+    LOG("Downloader:downloadUpdate - url: " + uri.spec + ", path: " +
+        patchFile.path + ", interval: " + interval);
 
     this._request = Cc["@mozilla.org/network/incremental-download;1"].
                     createInstance(Ci.nsIIncrementalDownload);
-
-    LOG("Downloader:downloadUpdate - downloading from " + uri.spec + " to " +
-        patchFile.path);
-    var interval = this.background ? getPref("getIntPref",
-                                             PREF_APP_UPDATE_BACKGROUNDINTERVAL,
-                                             DOWNLOAD_BACKGROUND_INTERVAL)
-                                   : DOWNLOAD_FOREGROUND_INTERVAL;
     this._request.init(uri, patchFile, DOWNLOAD_CHUNK_SIZE, interval);
     this._request.start(this, null);
 
     writeStatusFile(updateDir, STATE_DOWNLOADING);
     this._patch.QueryInterface(Ci.nsIWritablePropertyBag);
     this._patch.state = STATE_DOWNLOADING;
     var um = Cc["@mozilla.org/updates/update-manager;1"].
              getService(Ci.nsIUpdateManager);