Bug 1298945 - Only show Slow Startup notification if profile is 3 months old. r=MattN draft
authorFelipe Gomes <felipc@gmail.com>
Fri, 02 Sep 2016 14:40:21 -0300
changeset 409335 f63ddd59ca99cecd0c6d6e99b1319a77e081fefb
parent 409041 d5f20820c80514476f596090292a5d77c4b41e3b
child 530322 32e1e5d443a13b5b71777f3ef239c498c0054d0d
push id28450
push userfelipc@gmail.com
push dateFri, 02 Sep 2016 17:41:04 +0000
reviewersMattN
bugs1298945
milestone51.0a1
Bug 1298945 - Only show Slow Startup notification if profile is 3 months old. r=MattN MozReview-Commit-ID: J0bsvtBoEsv
browser/components/nsBrowserGlue.js
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -840,26 +840,44 @@ BrowserGlue.prototype = {
     } catch (e) { }
 
     let totalTime = (averageTime * samples) + currentTime;
     samples++;
     averageTime = totalTime / samples;
 
     if (samples >= Services.prefs.getIntPref("browser.slowStartup.maxSamples")) {
       if (averageTime > Services.prefs.getIntPref("browser.slowStartup.timeThreshold"))
-        this._showSlowStartupNotification();
+        this._calculateProfileAgeInDays().then(this._showSlowStartupNotification, null);
       averageTime = 0;
       samples = 0;
     }
 
     Services.prefs.setIntPref("browser.slowStartup.averageTime", averageTime);
     Services.prefs.setIntPref("browser.slowStartup.samples", samples);
   },
 
-  _showSlowStartupNotification: function () {
+  _calculateProfileAgeInDays: Task.async(function* () {
+    let ProfileAge = Cu.import("resource://gre/modules/ProfileAge.jsm", {}).ProfileAge;
+    let profileAge = new ProfileAge(null, null);
+
+    let creationDate = yield profileAge.created;
+    let resetDate = yield profileAge.reset;
+
+    // if the profile was reset, consider the
+    // reset date for its age.
+    let profileDate = resetDate || creationDate;
+
+    const ONE_DAY = 24 * 60 * 60 * 1000;
+    return (Date.now() - profileDate) / ONE_DAY;
+  }),
+
+  _showSlowStartupNotification: function (profileAge) {
+    if (profileAge < 90) // 3 months
+      return;
+
     let win = RecentWindow.getMostRecentBrowserWindow();
     if (!win)
       return;
 
     let productName = gBrandBundle.GetStringFromName("brandFullName");
     let message = win.gNavigatorBundle.getFormattedString("slowStartup.message", [productName]);
 
     let buttons = [