[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor-browser] 79/311: Bug 1749996 - Ensure CrashMonitor writes sessionstore final checkpoint before IOUtils shuts down. r=Gijs, a=RyanVM



This is an automated email from the git hooks/post-receive script.

pierov pushed a commit to branch geckoview-99.0.1-11.0-1
in repository tor-browser.

commit ff7edb3e2dedcc1a940d96223bb863e1385408d6
Author: Barret Rennie <barret@xxxxxxxxxx>
AuthorDate: Sat Feb 5 20:57:50 2022 +0000

    Bug 1749996 - Ensure CrashMonitor writes sessionstore final checkpoint before IOUtils shuts down. r=Gijs, a=RyanVM
    
    Differential Revision: https://phabricator.services.mozilla.com/D137797
---
 browser/components/sessionstore/SessionFile.jsm  |  7 ++--
 toolkit/components/crashmonitor/CrashMonitor.jsm | 41 +++++++++++++++++++++---
 2 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/browser/components/sessionstore/SessionFile.jsm b/browser/components/sessionstore/SessionFile.jsm
index 49ee979e231c6..c6abd2d6faa5d 100644
--- a/browser/components/sessionstore/SessionFile.jsm
+++ b/browser/components/sessionstore/SessionFile.jsm
@@ -28,9 +28,6 @@ const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 const { XPCOMUtils } = ChromeUtils.import(
   "resource://gre/modules/XPCOMUtils.jsm"
 );
-const { AsyncShutdown } = ChromeUtils.import(
-  "resource://gre/modules/AsyncShutdown.jsm"
-);
 
 XPCOMUtils.defineLazyModuleGetters(this, {
   RunState: "resource:///modules/sessionstore/RunState.jsm",
@@ -488,7 +485,7 @@ var SessionFileInternal = {
 
     // Ensure that we can write sessionstore.js cleanly before the profile
     // becomes unaccessible.
-    AsyncShutdown.profileBeforeChange.addBlocker(
+    IOUtils.profileBeforeChange.addBlocker(
       "SessionFile: Finish writing Session Restore data",
       promise,
       {
@@ -506,7 +503,7 @@ var SessionFileInternal = {
     // doesn't forward the rejection.
     return promise.then(() => {
       // Remove the blocker, no matter if writing failed or not.
-      AsyncShutdown.profileBeforeChange.removeBlocker(promise);
+      IOUtils.profileBeforeChange.removeBlocker(promise);
 
       if (isFinalWrite) {
         Services.obs.notifyObservers(
diff --git a/toolkit/components/crashmonitor/CrashMonitor.jsm b/toolkit/components/crashmonitor/CrashMonitor.jsm
index 44ae8b85f2e63..f3710c1bea46e 100644
--- a/toolkit/components/crashmonitor/CrashMonitor.jsm
+++ b/toolkit/components/crashmonitor/CrashMonitor.jsm
@@ -33,16 +33,26 @@
 
 var EXPORTED_SYMBOLS = ["CrashMonitor"];
 
+const { PrivateBrowsingUtils } = ChromeUtils.import(
+  "resource://gre/modules/PrivateBrowsingUtils.jsm"
+);
+const { PromiseUtils } = ChromeUtils.import(
+  "resource://gre/modules/PromiseUtils.jsm"
+);
 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
+const SESSIONSTORE_WINDOWS_RESTORED_TOPIC = "sessionstore-windows-restored";
+const SESSIONSTORE_FINAL_STATE_WRITE_COMPLETE_TOPIC =
+  "sessionstore-final-state-write-complete";
+
 const NOTIFICATIONS = [
   "final-ui-startup",
-  "sessionstore-windows-restored",
+  SESSIONSTORE_WINDOWS_RESTORED_TOPIC,
   "quit-application-granted",
   "quit-application",
   "profile-change-net-teardown",
   "profile-change-teardown",
-  "sessionstore-final-state-write-complete",
+  SESSIONSTORE_FINAL_STATE_WRITE_COMPLETE_TOPIC,
 ];
 
 const SHUTDOWN_PHASES = ["profile-before-change"];
@@ -59,6 +69,11 @@ var CrashMonitorInternal = {
    */
   checkpoints: {},
 
+  /**
+   * A deferred promise that resolves when all checkpoints have been written.
+   */
+  sessionStoreFinalWriteComplete: PromiseUtils.defer(),
+
   /**
    * Notifications received during previous session.
    *
@@ -158,9 +173,21 @@ var CrashMonitor = {
 
     // Add shutdown blocker for profile-before-change
     IOUtils.profileBeforeChange.addBlocker(
-      "CrashMonitor: Writing notifications to file after receiving profile-before-change",
-      () => this.writeCheckpoint("profile-before-change"),
-      () => this.checkpoints
+      "CrashMonitor: Writing notifications to file after receiving profile-before-change and awaiting all checkpoints written",
+      async () => {
+        await this.writeCheckpoint("profile-before-change");
+
+        // If SessionStore has not initialized, we don't want to wait for
+        // checkpoints that we won't hit, or we'll crash the browser during
+        // async shutdown.
+        if (
+          !PrivateBrowsingUtils.permanentPrivateBrowsing &&
+          CrashMonitorInternal.checkpoints[SESSIONSTORE_WINDOWS_RESTORED_TOPIC]
+        ) {
+          await CrashMonitorInternal.sessionStoreFinalWriteComplete.promise;
+        }
+      },
+      () => CrashMonitorInternal.checkpoints
     );
 
     CrashMonitorInternal.initialized = true;
@@ -184,6 +211,10 @@ var CrashMonitor = {
         Services.obs.removeObserver(this, aTopic);
       }, this);
     }
+
+    if (aTopic === SESSIONSTORE_FINAL_STATE_WRITE_COMPLETE_TOPIC) {
+      CrashMonitorInternal.sessionStoreFinalWriteComplete.resolve();
+    }
   },
 
   async writeCheckpoint(aCheckpoint) {

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits