diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js index 6d782bd2553a..b10b53e5d5bf 100644 --- a/browser/app/profile/firefox.js +++ b/browser/app/profile/firefox.js @@ -1479,6 +1479,9 @@ 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); diff --git a/browser/components/migration/AutoMigrate.jsm b/browser/components/migration/AutoMigrate.jsm index 848dc3057f2e..dccfd51e77b4 100644 --- a/browser/components/migration/AutoMigrate.jsm +++ b/browser/components/migration/AutoMigrate.jsm @@ -14,6 +14,9 @@ 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", @@ -287,6 +290,14 @@ const AutoMigrate = { 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) { @@ -318,6 +329,27 @@ const AutoMigrate = { }); }, + 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] ),