Bug 1321706: Fix race in closed window handling. r?mikedeboer draft
authorKris Maglione <maglione.k@gmail.com>
Wed, 11 Jan 2017 14:20:27 -0800
changeset 459410 a1751c13325b00d560b26e733e4fe16ee1c1706f
parent 459409 ab5b06088fb5eeddff45e48c39ab917b8c285888
child 541889 18ade18602e11e54546728481bc28aa062913d10
push id41215
push usermaglione.k@gmail.com
push dateWed, 11 Jan 2017 22:21:52 +0000
reviewersmikedeboer
bugs1321706
milestone53.0a1
Bug 1321706: Fix race in closed window handling. r?mikedeboer MozReview-Commit-ID: KszEE0I7w7e
browser/components/sessionstore/SessionStore.jsm
--- a/browser/components/sessionstore/SessionStore.jsm
+++ b/browser/components/sessionstore/SessionStore.jsm
@@ -2940,17 +2940,19 @@ var SessionStoreInternal = {
 
   /**
    * gather session data as object
    * @param aUpdateAll
    *        Bool update all windows
    * @returns object
    */
   getCurrentState: function (aUpdateAll) {
-    this._handleClosedWindows();
+    this._handleClosedWindows().then(() => {
+      this._notifyOfClosedObjectsChange();
+    });
 
     var activeWindow = this._getMostRecentBrowserWindow();
 
     TelemetryStopwatch.start("FX_SESSION_RESTORE_COLLECT_ALL_WINDOWS_DATA_MS");
     if (RunState.isRunning) {
       // update the data for all windows with activities since the last save operation
       this._forEachBrowserWindow(function(aWindow) {
         if (!this._isWindowLoaded(aWindow)) // window data is still in _statesToRestore
@@ -4001,22 +4003,24 @@ var SessionStoreInternal = {
   /**
    * Calls onClose for windows that are determined to be closed but aren't
    * destroyed yet, which would otherwise cause getBrowserState and
    * setBrowserState to treat them as open windows.
    */
   _handleClosedWindows: function ssi_handleClosedWindows() {
     var windowsEnum = Services.wm.getEnumerator("navigator:browser");
 
+    let promises = [];
     while (windowsEnum.hasMoreElements()) {
       var window = windowsEnum.getNext();
       if (window.closed) {
-        this.onClose(window);
+        promises.push(this.onClose(window));
       }
     }
+    return Promise.all(promises);
   },
 
   /**
    * open a new browser window for a given session state
    * called when restoring a multi-window session
    * @param aState
    *        Object containing session data
    */