Bug 1137961 - Check for new GMPs as soon as possible after an update to Firefox. r=gavin
authorStephen Pohl <spohl.mozilla.bugs@gmail.com>
Fri, 06 Mar 2015 10:14:00 +0100
changeset 249007 d31eb86fe05c8bc2d84331ed0043ef13026c69c8
parent 249006 784963e853520164caa46b735c559ccab10797b5
child 249008 335d3dc298d6606e1858bab3710ef837efbeee1f
push id966
push usermleibovic@mozilla.com
push dateTue, 10 Mar 2015 01:36:33 +0000
reviewersgavin
bugs1137961
milestone39.0a1
Bug 1137961 - Check for new GMPs as soon as possible after an update to Firefox. r=gavin
toolkit/modules/GMPInstallManager.jsm
--- a/toolkit/modules/GMPInstallManager.jsm
+++ b/toolkit/modules/GMPInstallManager.jsm
@@ -117,16 +117,17 @@ let GMPPrefs = {
   KEY_URL: "media.gmp-manager.url",
   KEY_URL_OVERRIDE: "media.gmp-manager.url.override",
   KEY_CERT_CHECKATTRS: "media.gmp-manager.cert.checkAttributes",
   KEY_CERT_REQUIREBUILTIN: "media.gmp-manager.cert.requireBuiltIn",
   KEY_UPDATE_LAST_CHECK: "media.gmp-manager.lastCheck",
   KEY_UPDATE_SECONDS_BETWEEN_CHECKS: "media.gmp-manager.secondsBetweenChecks",
   KEY_APP_DISTRIBUTION: "distribution.id",
   KEY_APP_DISTRIBUTION_VERSION: "distribution.version",
+  KEY_BUILDID: "media.gmp-manager.buildID",
 
   CERTS_BRANCH: "media.gmp-manager.certs."
 };
 
 // This is copied directly from nsUpdateService.js
 // It is used for calculating the URL string w/ var replacement.
 // TODO: refactor this out somewhere else
 XPCOMUtils.defineLazyGetter(this, "gOSVersion", function aus_gOSVersion() {
@@ -421,35 +422,50 @@ GMPInstallManager.prototype = {
   _isAddonUpdateEnabled: function(aAddon) {
     return GMPPrefs.get(GMPPrefs.KEY_ADDON_ENABLED, true, aAddon) &&
            GMPPrefs.get(GMPPrefs.KEY_ADDON_AUTOUPDATE, true, aAddon);
   },
   _updateLastCheck: function() {
     let now = Math.round(Date.now() / 1000);
     GMPPrefs.set(GMPPrefs.KEY_UPDATE_LAST_CHECK, now);
   },
+  _versionchangeOccurred: function() {
+    let savedBuildID = GMPPrefs.get(GMPPrefs.KEY_BUILDID, null);
+    let buildID = Services.appinfo.platformBuildID;
+    if (savedBuildID == buildID) {
+      return false;
+    }
+    GMPPrefs.set(GMPPrefs.KEY_BUILDID, buildID);
+    return true;
+  },
   /**
    * Wrapper for checkForAddons and installAddon.
    * Will only install if not already installed and will log the results.
    * This will only install/update the OpenH264 and EME plugins
    * @return a promise which will be resolved if all addons could be installed
    *         successfully, rejected otherwise.
    */
   simpleCheckAndInstall: Task.async(function*() {
     let log = getScopedLogger("GMPInstallManager.simpleCheckAndInstall");
 
-    let secondsBetweenChecks =
-      GMPPrefs.get(GMPPrefs.KEY_UPDATE_SECONDS_BETWEEN_CHECKS,
-                   DEFAULT_SECONDS_BETWEEN_CHECKS)
-    let secondsSinceLast = this._getTimeSinceLastCheck();
-    log.info("Last check was: " + secondsSinceLast +
-             " seconds ago, minimum seconds: " + secondsBetweenChecks);
-    if (secondsBetweenChecks > secondsSinceLast) {
-      log.info("Will not check for updates.");
-      return {status: "too-frequent-no-check"};
+    if (this._versionchangeOccurred()) {
+      log.info("A version change occurred. Ignoring " +
+               "media.gmp-manager.lastCheck to check immediately for " +
+               "new or updated GMPs.");
+    } else {
+      let secondsBetweenChecks =
+        GMPPrefs.get(GMPPrefs.KEY_UPDATE_SECONDS_BETWEEN_CHECKS,
+                     DEFAULT_SECONDS_BETWEEN_CHECKS)
+      let secondsSinceLast = this._getTimeSinceLastCheck();
+      log.info("Last check was: " + secondsSinceLast +
+               " seconds ago, minimum seconds: " + secondsBetweenChecks);
+      if (secondsBetweenChecks > secondsSinceLast) {
+        log.info("Will not check for updates.");
+        return {status: "too-frequent-no-check"};
+      }
     }
 
     try {
       let gmpAddons = yield this.checkForAddons();
       this._updateLastCheck();
       log.info("Found " + gmpAddons.length + " addons advertised.");
       let addonsToInstall = gmpAddons.filter(function(gmpAddon) {
         log.info("Found addon: " + gmpAddon.toString());