Bug 1289231 - Remove notification after it's been displayed for 3 days. r=dolske, a=lizzard
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Thu, 25 Aug 2016 19:00:31 +0100
changeset 349935 656a6b1bdec9749882809999daa4cdc740e7054a
parent 349934 468ca2351fe24b9244915e7d2ffde07810849f64
child 349936 0fe247649cf4fccc9bb86ea1b3896ee451c2d32b
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdolske, lizzard
bugs1289231
milestone50.0a2
Bug 1289231 - Remove notification after it's been displayed for 3 days. r=dolske, a=lizzard MozReview-Commit-ID: CFARPDu3FnI
browser/app/profile/firefox.js
browser/components/migration/AutoMigrate.jsm
browser/components/migration/content/automigration.properties
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1470,16 +1470,20 @@ pref("toolkit.pageThumbs.minHeight", 190
 // Enable speech synthesis
 pref("media.webspeech.synth.enabled", true);
 
 pref("browser.esedbreader.loglevel", "Error");
 
 pref("browser.laterrun.enabled", false);
 
 pref("browser.migrate.automigrate.enabled", false);
+// 4 here means the suggestion notification will be automatically
+// hidden the 4th day, so it will actually be shown on 3 different days.
+pref("browser.migrate.automigrate.daysToOfferUndo", 4);
+pref("browser.migrate.automigrate.ui.enabled", true);
 
 // Enable browser frames for use on desktop.  Only exposed to chrome callers.
 pref("dom.mozBrowserFramesEnabled", true);
 
 pref("extensions.pocket.enabled", true);
 
 pref("signon.schemeUpgrades", true);
 
--- a/browser/components/migration/AutoMigrate.jsm
+++ b/browser/components/migration/AutoMigrate.jsm
@@ -4,21 +4,25 @@
 
 "use strict";
 
 this.EXPORTED_SYMBOLS = ["AutoMigrate"];
 
 const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
 
 const kAutoMigrateEnabledPref = "browser.migrate.automigrate.enabled";
+const kUndoUIEnabledPref = "browser.migrate.automigrate.ui.enabled";
 
 const kAutoMigrateStartedPref = "browser.migrate.automigrate.started";
 const kAutoMigrateFinishedPref = "browser.migrate.automigrate.finished";
 const kAutoMigrateBrowserPref = "browser.migrate.automigrate.browser";
 
+const kAutoMigrateLastUndoPromptDateMsPref = "browser.migrate.automigrate.lastUndoPromptDateMs";
+const kAutoMigrateDaysToOfferUndoPref = "browser.migrate.automigrate.daysToOfferUndo";
+
 const kPasswordManagerTopic = "passwordmgr-storage-changed";
 const kPasswordManagerTopicTypes = new Set([
   "addLogin",
   "modifyLogin",
 ]);
 
 const kNotificationId = "abouthome-automigration-undo";
 
@@ -41,17 +45,20 @@ function getBundle() {
 
 const AutoMigrate = {
   get resourceTypesToUse() {
     let {BOOKMARKS, HISTORY, PASSWORDS} = Ci.nsIBrowserProfileMigrator;
     return BOOKMARKS | HISTORY | PASSWORDS;
   },
 
   init() {
-    this.enabled = Preferences.get(kAutoMigrateEnabledPref, false);
+    this.enabled = Preferences.get(kAutoMigrateEnabledPref, false) &&
+                   Cc["@mozilla.org/chrome/chrome-registry;1"].
+                     getService(Ci.nsIXULChromeRegistry).
+                     getSelectedLocale("browser") == "en-US";
     if (this.enabled) {
       this.maybeInitUndoObserver();
     }
   },
 
   maybeInitUndoObserver() {
     // Check synchronously (NB: canUndo is async) if we really need
     // to do this:
@@ -290,25 +297,34 @@ const AutoMigrate = {
       return getBundle().GetStringFromName(str);
     return getBundle().formatStringFromName(
       str, args, args.length);
   },
 
   maybeShowUndoNotification(target) {
     this.canUndo().then(canUndo => {
       // The tab might have navigated since we requested the undo state:
-      if (!canUndo || target.currentURI.spec != "about:home") {
+      if (!canUndo || target.currentURI.spec != "about:home" ||
+          !Preferences.get(kUndoUIEnabledPref, false)) {
         return;
       }
       let win = target.ownerGlobal;
       let notificationBox = win.gBrowser.getNotificationBox(target);
       if (!notificationBox || notificationBox.getNotificationWithValue("abouthome-automigration-undo")) {
         return;
       }
 
+      // At this stage we're committed to show the prompt - unless we shouldn't,
+      // in which case we remove the undo prefs (which will cause canUndo() to
+      // return false from now on.):
+      if (!this.shouldStillShowUndoPrompt()) {
+        this.removeUndoOption();
+        return;
+      }
+
       let browserName = this.getBrowserUsedForMigration();
       let message;
       if (browserName) {
         message = this.getLocalizedString("automigration.undo.message",
                                                     [browserName]);
       } else {
         message = this.getLocalizedString("automigration.undo.unknownBrowserMessage");
       }
@@ -330,14 +346,35 @@ const AutoMigrate = {
         },
       ];
       notificationBox.appendNotification(
         message, kNotificationId, null, notificationBox.PRIORITY_INFO_HIGH, buttons
       );
     });
   },
 
+  shouldStillShowUndoPrompt() {
+    let today = new Date();
+    // Round down to midnight:
+    today = new Date(today.getFullYear(), today.getMonth(), today.getDate());
+    // We store the unix timestamp corresponding to midnight on the last day
+    // on which we prompted. Fetch that and compare it to today's date.
+    // (NB: stored as a string because int prefs are too small for unix
+    // timestamps.)
+    let previousPromptDateMsStr = Preferences.get(kAutoMigrateLastUndoPromptDateMsPref, "0");
+    let previousPromptDate = new Date(parseInt(previousPromptDateMsStr, 10));
+    if (previousPromptDate < today) {
+      let remainingDays = Preferences.get(kAutoMigrateDaysToOfferUndoPref, 4) - 1;
+      Preferences.set(kAutoMigrateDaysToOfferUndoPref, remainingDays);
+      Preferences.set(kAutoMigrateLastUndoPromptDateMsPref, today.valueOf().toString());
+      if (remainingDays <= 0) {
+        return false;
+      }
+    }
+    return true;
+  },
+
   QueryInterface: XPCOMUtils.generateQI(
     [Ci.nsIObserver, Ci.nsINavBookmarkObserver, Ci.nsISupportsWeakReference]
   ),
 };
 
 AutoMigrate.init();
--- a/browser/components/migration/content/automigration.properties
+++ b/browser/components/migration/content/automigration.properties
@@ -1,7 +1,7 @@
 # Automigration undo notification.
 automigration.undo.message               = We automatically imported your data from %S. Would you like to keep it?
 automigration.undo.unknownBrowserMessage = We automatically imported your data from another browser. Would you like to keep it?
 automigration.undo.keep.label            = Keep
 automigration.undo.keep.accesskey        = K
-automigration.undo.dontkeep.label        = Don't Keep
+automigration.undo.dontkeep.label        = Don’t Keep
 automigration.undo.dontkeep.accesskey    = D