Bug 1289231 - part 2: remove notification after it's been displayed for 3 days, r?dolske draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 26 Jul 2016 13:14:44 +0100
changeset 402707 eecf42510241cb1049e088795852835e7709df24
parent 402706 1632ae2dc84dc12bcb37b8393e730976247d8ce9
child 528750 ba25a8438000ada2aa0e823931dc4e2ea63fc434
push id26743
push usergijskruitbosch@gmail.com
push dateThu, 18 Aug 2016 18:44:43 +0000
reviewersdolske
bugs1289231
milestone51.0a1
Bug 1289231 - part 2: remove notification after it's been displayed for 3 days, r?dolske MozReview-Commit-ID: CFARPDu3FnI
browser/app/profile/firefox.js
browser/components/migration/AutoMigrate.jsm
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1476,16 +1476,19 @@ 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);
 
 // 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
@@ -9,16 +9,19 @@ this.EXPORTED_SYMBOLS = ["AutoMigrate"];
 const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
 
 const kAutoMigrateEnabledPref = "browser.migrate.automigrate.enabled";
 
 const kAutoMigrateStartedPref = "browser.migrate.automigrate.started";
 const kAutoMigrateFinishedPref = "browser.migrate.automigrate.finished";
 const kAutoMigrateBrowserPref = "browser.migrate.automigrate.browser";
 
+const kAutoMigrateLastUndoPromptDatePref = "browser.migrate.automigrate.lastUndoPromptDate";
+const kAutoMigrateDaysToOfferUndoPref = "browser.migrate.automigrate.daysToOfferUndo";
+
 const kPasswordManagerTopic = "passwordmgr-storage-changed";
 const kPasswordManagerTopicTypes = new Set([
   "addLogin",
   "modifyLogin",
 ]);
 
 const kNotificationId = "abouthome-automigration-undo";
 
@@ -282,16 +285,24 @@ const AutoMigrate = {
         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 removeNotification = () => {
         let notification = notificationBox.getNotificationWithValue(kNotificationId);
         notificationBox.removeNotification(notification, true);
       };
       let browserName = this.getBrowserUsedForMigration();
       let message;
       if (browserName) {
         message = MigrationUtils.getLocalizedString("automigration.undo.message",
@@ -319,14 +330,31 @@ const AutoMigrate = {
         },
       ];
       notificationBox.appendNotification(
         message, kNotificationId, null, notificationBox.PRIORITY_INFO_HIGH, buttons
       );
     });
   },
 
+  shouldStillShowUndoPrompt() {
+    let date = new Date();
+    // Round down to midnight:
+    date = new Date(date.getFullYear(), date.getMonth(), date.getDate());
+    let previousDateStr = Preferences.get(kAutoMigrateLastUndoPromptDatePref, "0");
+    let previousDate = new Date(parseInt(previousDateStr, 10));
+    if (previousDate < date) {
+      let remainingDays = Preferences.get(kAutoMigrateDaysToOfferUndoPref, 4) - 1;
+      Preferences.set(kAutoMigrateDaysToOfferUndoPref, remainingDays);
+      Preferences.set(kAutoMigrateLastUndoPromptDatePref, date.valueOf().toString());
+      if (remainingDays <= 0) {
+        return false;
+      }
+    }
+    return true;
+  },
+
   QueryInterface: XPCOMUtils.generateQI(
     [Ci.nsIObserver, Ci.nsINavBookmarkObserver, Ci.nsISupportsWeakReference]
   ),
 };
 
 AutoMigrate.init();