Bug 746756 - On feature activation, Download Panel should limit reported downloads. r=mak.
authorMike Conley <mconley@mozilla.com>
Wed, 24 Oct 2012 10:02:29 -0400
changeset 111378 6c68ce017824b3090a30bfe9427b32fa6cdf4e84
parent 111377 164d7dd54ee0864f9b9acff4de9448bf7e0a1256
child 111379 6222e6c573a3d12fbfae7d0394213a974f35cada
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersmak
bugs746756
milestone19.0a1
Bug 746756 - On feature activation, Download Panel should limit reported downloads. r=mak.
browser/app/profile/firefox.js
browser/components/downloads/src/DownloadsStartup.js
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -324,16 +324,20 @@ pref("browser.download.manager.scanWhenD
 pref("browser.download.manager.resumeOnWakeDelay", 10000);
 
 // This allows disabling the Downloads Panel in favor of the old interface.
 pref("browser.download.useToolkitUI", false);
 
 // This controls retention behavior in the Downloads Panel only.
 pref("browser.download.panel.removeFinishedDownloads", false);
 
+// This records whether or not at least one session with the Downloads Panel
+// enabled has been completed already.
+pref("browser.download.panel.firstSessionCompleted", false);
+
 // search engines URL
 pref("browser.search.searchEnginesURL",      "https://addons.mozilla.org/%LOCALE%/firefox/search-engines/");
 
 // pointer to the default engine name
 pref("browser.search.defaultenginename",      "chrome://browser-region/locale/region.properties");
 
 // disable logging for the search service by default
 pref("browser.search.log", false);
--- a/browser/components/downloads/src/DownloadsStartup.js
+++ b/browser/components/downloads/src/DownloadsStartup.js
@@ -93,17 +93,17 @@ DownloadsStartup.prototype = {
 
       case "sessionstore-windows-restored":
       case "sessionstore-browser-state-restored":
         // Unless there is no saved session, there is a chance that we are
         // starting up after a restart or a crash.  We should check the disk
         // database to see if there are completed downloads to recover and show
         // in the panel, in addition to in-progress downloads.
         if (gSessionStartup.sessionType != Ci.nsISessionStartup.NO_SESSION) {
-          this._recoverAllDownloads = true;
+          this._restoringSession = true;
         }
         this._ensureDataLoaded();
         break;
 
       case "download-manager-initialized":
         // Don't initialize the JavaScript data and user interface layer if we
         // are initializing the Download Manager service during shutdown.
         if (this._shuttingDown) {
@@ -183,28 +183,37 @@ DownloadsStartup.prototype = {
         // "quit-application" listeners are invoked, so that the Download
         // Manager service has a chance to pause or cancel in-progress downloads
         // before we remove completed downloads from the list.  Note that, since
         // "quit-application" was invoked, we've already exited Private Browsing
         // Mode, thus we are always working on the disk database.
         if (this._cleanupOnShutdown) {
           Services.downloads.cleanUp();
         }
+
+        if (!DownloadsCommon.useToolkitUI) {
+          // If we got this far, that means that we finished our first session
+          // with the Downloads Panel without crashing. This means that we don't
+          // have to force displaying only active downloads on the next startup
+          // now.
+          this._firstSessionCompleted = true;
+        }
         break;
     }
   },
 
   //////////////////////////////////////////////////////////////////////////////
   //// Private
 
   /**
-   * Indicates whether we should load all downloads from the previous session,
-   * including completed items as well as active downloads.
+   * Indicates whether we're restoring a previous session. This is used by
+   * _recoverAllDownloads to determine whether or not we should load and
+   * display all downloads data, or restrict it to only the active downloads.
    */
-  _recoverAllDownloads: false,
+  _restoringSession: false,
 
   /**
    * Indicates whether the Download Manager service has been initialized.  This
    * flag is required because we want to avoid accessing the service immediately
    * at browser startup.  The service will start when the user first requests a
    * download, or some time after browser startup.
    */
   _downloadsServiceInitialized: false,
@@ -215,16 +224,41 @@ DownloadsStartup.prototype = {
   _shuttingDown: false,
 
   /**
    * True during shutdown if we need to remove completed downloads.
    */
   _cleanupOnShutdown: false,
 
   /**
+   * True if we should display all downloads, as opposed to just active
+   * downloads. We decide to display all downloads if we're restoring a session,
+   * or if we're using the Downloads Panel anytime after the first session with
+   * it has completed.
+   */
+  get _recoverAllDownloads() {
+    return this._restoringSession ||
+           (!DownloadsCommon.useToolkitUI && this._firstSessionCompleted);
+  },
+
+  /**
+   * True if we've ever completed a session with the Downloads Panel enabled.
+   */
+  get _firstSessionCompleted() {
+    return Services.prefs
+                   .getBoolPref("browser.download.panel.firstSessionCompleted");
+  },
+
+  set _firstSessionCompleted(aValue) {
+    Services.prefs.setBoolPref("browser.download.panel.firstSessionCompleted",
+                               aValue);
+    return aValue;
+  },
+
+  /**
    * Ensures that persistent download data is reloaded at the appropriate time.
    */
   _ensureDataLoaded: function DS_ensureDataLoaded()
   {
     if (!this._downloadsServiceInitialized ||
         gPrivateBrowsingService.privateBrowsingEnabled) {
       return;
     }