bug 865798 add timestamps to social provider install for proper fhr support, r-felipe
authorShane Caraveo <scaraveo@mozilla.com>
Mon, 29 Apr 2013 13:09:10 -0700
changeset 141249 2d02910b859e77cd165b13179eda6e398e3bfb6f
parent 141248 d44d0b5590b7f07f45ce2ea44b3da9c2116a1246
child 141250 2893ed05e7392d51d016279854dac8a4ed23c997
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs865798
milestone23.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 865798 add timestamps to social provider install for proper fhr support, r-felipe
browser/base/content/test/social/browser_addons.js
toolkit/components/social/SocialService.jsm
toolkit/components/social/test/xpcshell/test_SocialServiceMigration21.js
toolkit/components/social/test/xpcshell/test_SocialServiceMigration22.js
--- a/browser/base/content/test/social/browser_addons.js
+++ b/browser/base/content/test/social/browser_addons.js
@@ -52,16 +52,18 @@ function installListener(next, aManifest
     onInstalling: function(addon) {
       is(expectEvent, "onInstalling", "install started");
       is(addon.manifest.origin, aManifest.origin, "provider about to be installed");
       ok(!Services.prefs.prefHasUserValue(prefname), "manifest is not in user-prefs");
       expectEvent = "onInstalled";
     },
     onInstalled: function(addon) {
       is(addon.manifest.origin, aManifest.origin, "provider installed");
+      ok(addon.installDate.getTime() > 0, "addon has installDate");
+      ok(addon.updateDate.getTime() > 0, "addon has updateDate");
       ok(Services.prefs.prefHasUserValue(prefname), "manifest is in user-prefs");
       expectEvent = "onUninstalling";
     },
     onUninstalling: function(addon) {
       is(expectEvent, "onUninstalling", "uninstall started");
       is(addon.manifest.origin, aManifest.origin, "provider about to be uninstalled");
       ok(Services.prefs.prefHasUserValue(prefname), "manifest is in user-prefs");
       expectEvent = "onUninstalled";
--- a/toolkit/components/social/SocialService.jsm
+++ b/toolkit/components/social/SocialService.jsm
@@ -130,42 +130,37 @@ function migrateSettings() {
   } catch(e) {
     // not set, we'll check if we need to migrate older prefs
   }
   if (activeProviders) {
     // migration from fx21 to fx22 or later
     // ensure any *builtin* provider in activeproviders is in user level prefs
     for (let origin in ActiveProviders._providers) {
       let prefname;
+      let manifest;
       try {
         prefname = getPrefnameFromOrigin(origin);
+        manifest = JSON.parse(Services.prefs.getComplexValue(prefname, Ci.nsISupportsString).data);
       } catch(e) {
         // Our preference is missing or bad, remove from ActiveProviders and
         // continue. This is primarily an error-case and should only be
         // reached by either messing with preferences or hitting the one or
         // two days of nightly that ran into it, so we'll flush right away.
         ActiveProviders.delete(origin);
         ActiveProviders.flush();
         continue;
       }
-      if (!Services.prefs.prefHasUserValue(prefname)) {
-        // if we've got an active *builtin* provider, ensure that the pref
-        // is set at a user-level as that will signify *installed* status.
-        let manifest;
-        try {
-          manifest = JSON.parse(Services.prefs.getComplexValue(prefname, Ci.nsISupportsString).data);
-        } catch(e) {
-          // see comment in the delete/flush code above.
-          ActiveProviders.delete(origin);
-          ActiveProviders.flush();
-          continue;
+      if (!manifest.updateDate) {
+        // the provider was installed with an older build, so we will update the
+        // timestamp and ensure the manifest is in user prefs
+        delete manifest.builtin;
+        if (!manifest.updateDate) {
+          manifest.updateDate = Date.now();
+          manifest.installDate = 0; // we don't know when it was installed
         }
-        // our default manifests have been updated with the builtin flags as of
-        // fx22, delete it so we can set the user-pref
-        delete manifest.builtin;
 
         let string = Cc["@mozilla.org/supports-string;1"].
                      createInstance(Ci.nsISupportsString);
         string.data = JSON.stringify(manifest);
         Services.prefs.setComplexValue(prefname, Ci.nsISupportsString, string);
       }
     }
     return;
@@ -191,16 +186,20 @@ function migrateSettings() {
       } catch(e) {
         // bad or missing preference, we wont update this one.
         continue;
       }
       if (manifest && typeof(manifest) == "object" && manifest.origin) {
         // our default manifests have been updated with the builtin flags as of
         // fx22, delete it so we can set the user-pref
         delete manifest.builtin;
+        if (!manifest.updateDate) {
+          manifest.updateDate = Date.now();
+          manifest.installDate = 0; // we don't know when it was installed
+        }
 
         let string = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
         string.data = JSON.stringify(manifest);
         // pref here is just the branch name, set the full pref name
         Services.prefs.setComplexValue("social.manifest." + pref, Ci.nsISupportsString, string);
         ActiveProviders.add(manifest.origin);
         ActiveProviders.flush();
         // social.active was used at a time that there was only one
@@ -831,16 +830,24 @@ function getAddonIDFromOrigin(origin) {
   return originUri.host + ID_SUFFIX;
 }
 
 function getPrefnameFromOrigin(origin) {
   return "social.manifest." + SocialServiceInternal.getManifestPrefname(origin);
 }
 
 function AddonInstaller(sourceURI, aManifest, installCallback) {
+  aManifest.updateDate = Date.now();
+  // get the existing manifest for installDate
+  let manifest = SocialServiceInternal.getManifestByOrigin(aManifest.origin);
+  if (manifest && manifest.installDate)
+    aManifest.installDate = manifest.installDate;
+  else
+    aManifest.installDate = aManifest.updateDate;
+
   this.sourceURI = sourceURI;
   this.install = function() {
     let addon = this.addon;
     AddonManagerPrivate.callInstallListeners("onExternalInstall", null, addon, null, false);
     AddonManagerPrivate.callAddonListeners("onInstalling", addon, false);
 
     let string = Cc["@mozilla.org/supports-string;1"].
                  createInstance(Ci.nsISupportsString);
--- a/toolkit/components/social/test/xpcshell/test_SocialServiceMigration21.js
+++ b/toolkit/components/social/test/xpcshell/test_SocialServiceMigration21.js
@@ -43,9 +43,14 @@ function testMigration(manifest, next) {
 
   let activeProviders;
   let pref = Services.prefs.getComplexValue("social.activeProviders",
                                             Ci.nsISupportsString);
   activeProviders = JSON.parse(pref);
   do_check_true(activeProviders[manifest.origin]);
   do_check_true(MANIFEST_PREFS.prefHasUserValue(manifest.origin));
   do_check_true(JSON.parse(DEFAULT_PREFS.getCharPref(manifest.origin)).builtin);
+
+  let userPref = JSON.parse(MANIFEST_PREFS.getCharPref(manifest.origin));
+  do_check_true(parseInt(userPref.updateDate) > 0);
+  // migrated providers wont have an installDate
+  do_check_true(userPref.installDate === 0);
 }
--- a/toolkit/components/social/test/xpcshell/test_SocialServiceMigration22.js
+++ b/toolkit/components/social/test/xpcshell/test_SocialServiceMigration22.js
@@ -55,11 +55,16 @@ function testMigration(manifest, next) {
   let activeProviders;
   let pref = Services.prefs.getComplexValue("social.activeProviders",
                                             Ci.nsISupportsString);
   activeProviders = JSON.parse(pref);
   do_check_true(activeProviders[manifest.origin]);
   do_check_true(MANIFEST_PREFS.prefHasUserValue(manifest.origin));
   do_check_true(JSON.parse(DEFAULT_PREFS.getCharPref(manifest.origin)).builtin);
 
+  let userPref = JSON.parse(MANIFEST_PREFS.getCharPref(manifest.origin));
+  do_check_true(parseInt(userPref.updateDate) > 0);
+  // migrated providers wont have an installDate
+  do_check_true(userPref.installDate === 0);
+
   // bug 859715, this should have been removed during migration
   do_check_false(!!activeProviders["bad.origin"]);
 }