Bug 1141550 - Register an AsyncShutdown blocker to persist download changes. r=paolo
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Mon, 16 Mar 2015 14:40:00 -0700
changeset 233855 0743512ea4cc6ba0d14dd4e54ea2a90404d9b663
parent 233854 83645820fc28239bc99b41051532e953122714b9
child 233856 a94d9479d749250ff0c878083caf0e2030543b53
push id28425
push usercbook@mozilla.com
push dateTue, 17 Mar 2015 10:33:06 +0000
treeherdermozilla-central@a194e8023090 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspaolo
bugs1141550
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1141550 - Register an AsyncShutdown blocker to persist download changes. r=paolo
toolkit/components/jsdownloads/src/DownloadIntegration.jsm
--- a/toolkit/components/jsdownloads/src/DownloadIntegration.jsm
+++ b/toolkit/components/jsdownloads/src/DownloadIntegration.jsm
@@ -83,33 +83,21 @@ XPCOMUtils.defineLazyServiceGetter(this,
                                    "@mozilla.org/telephony/volume-service;1",
                                    "nsIVolumeService");
 
 const Timer = Components.Constructor("@mozilla.org/timer;1", "nsITimer",
                                      "initWithCallback");
 
 /**
  * Indicates the delay between a change to the downloads data and the related
- * save operation.  This value is the result of a delicate trade-off, assuming
- * the host application uses the browser history instead of the download store
- * to save completed downloads.
- *
- * If a download takes less than this interval to complete (for example, saving
- * a page that is already displayed), then no input/output is triggered by the
- * download store except for an existence check, resulting in the best possible
- * efficiency.
+ * save operation.
  *
- * Conversely, if the browser is closed before this interval has passed, the
- * download will not be saved.  This prevents it from being restored in the next
- * session, and if there is partial data associated with it, then the ".part"
- * file will not be deleted when the browser starts again.
- *
- * In all cases, for best efficiency, this value should be high enough that the
- * input/output for opening or closing the target file does not overlap with the
- * one for saving the list of downloads.
+ * For best efficiency, this value should be high enough that the input/output
+ * for opening or closing the target file does not overlap with the one for
+ * saving the list of downloads.
  */
 const kSaveDelayMs = 1500;
 
 /**
  * This pref indicates if we have already imported (or attempted to import)
  * the downloads database from the previous SQLite storage.
  */
 const kPrefImportedFromSqlite = "browser.download.importedFromSqlite";
@@ -1221,16 +1209,18 @@ this.DownloadHistoryObserver = function 
  *        The DownloadStore object used for saving.
  */
 this.DownloadAutoSaveView = function (aList, aStore)
 {
   this._list = aList;
   this._store = aStore;
   this._downloadsMap = new Map();
   this._writer = new DeferredTask(() => this._store.save(), kSaveDelayMs);
+  AsyncShutdown.profileBeforeChange.addBlocker("DownloadAutoSaveView: writing data",
+                                               () => this._writer.finalize());
 }
 
 this.DownloadAutoSaveView.prototype = {
   /**
    * DownloadList object linked to this view.
    */
   _list: null,