Bug 1216972 - AsyncShutdown for content processes;r?froydnj draft
authorDavid Rajchenbach-Teller <dteller@mozilla.com>
Fri, 16 Oct 2015 11:30:21 +0200
changeset 308812 2987b998b7ce2fb92138f04d27d0a9a43faedeee
parent 308683 faf815a0fa9b052a38bce00c0c2aa1e2c9610936
child 308813 91d8ab369785377c2967f475acc0de4830e581df
push id7531
push usermconley@mozilla.com
push dateFri, 13 Nov 2015 22:48:42 +0000
reviewersfroydnj
bugs1216972
milestone45.0a1
Bug 1216972 - AsyncShutdown for content processes;r?froydnj
toolkit/components/asyncshutdown/AsyncShutdown.jsm
toolkit/components/asyncshutdown/nsAsyncShutdown.js
toolkit/components/asyncshutdown/nsIAsyncShutdown.idl
--- a/toolkit/components/asyncshutdown/AsyncShutdown.jsm
+++ b/toolkit/components/asyncshutdown/AsyncShutdown.jsm
@@ -61,16 +61,19 @@ Object.defineProperty(this, "gCrashRepor
       return this.gCrashReporter = reporter;
     } catch (ex) {
       return this.gCrashReporter = null;
     }
   },
   configurable: true
 });
 
+// `true` if this is a content process, `false` otherwise.
+const isContent = Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT;
+
 // Display timeout warnings after 10 seconds
 const DELAY_WARNING_MS = 10 * 1000;
 
 
 // Crash the process if shutdown is really too long
 // (allowing for sleep).
 const PREF_DELAY_CRASH_MS = "toolkit.asyncshutdown.crash_timeout";
 var DELAY_CRASH_MS = 60 * 1000; // One minute
@@ -974,18 +977,27 @@ Barrier.prototype = Object.freeze({
 
 
 
 // List of well-known phases
 // Ideally, phases should be registered from the component that decides
 // when they start/stop. For compatibility with existing startup/shutdown
 // mechanisms, we register a few phases here.
 
+// Parent process
 this.AsyncShutdown.profileChangeTeardown = getPhase("profile-change-teardown");
 this.AsyncShutdown.profileBeforeChange = getPhase("profile-before-change");
 this.AsyncShutdown.placesClosingInternalConnection = getPhase("places-will-close-connection");
 this.AsyncShutdown.sendTelemetry = getPhase("profile-before-change2");
+
+
+// Content process
+if (isContent) {
+  this.AsyncShutdown.contentChildShutdown = getPhase("content-child-shutdown");
+}
+
+// All processes
 this.AsyncShutdown.webWorkersShutdown = getPhase("web-workers-shutdown");
 this.AsyncShutdown.xpcomThreadsShutdown = getPhase("xpcom-threads-shutdown");
 
 this.AsyncShutdown.Barrier = Barrier;
 
 Object.freeze(this.AsyncShutdown);
--- a/toolkit/components/asyncshutdown/nsAsyncShutdown.js
+++ b/toolkit/components/asyncshutdown/nsAsyncShutdown.js
@@ -221,21 +221,28 @@ nsAsyncShutdownBarrier.prototype = {
   QueryInterface :  XPCOMUtils.generateQI([Ci.nsIAsyncShutdownBarrier]),
   classID:          Components.ID("{29a0e8b5-9111-4c09-a0eb-76cd02bf20fa}"),
 };
 
 function nsAsyncShutdownService() {
   // Cache for the getters
 
   for (let _k of
-   ["profileBeforeChange",
+   [// Parent process
+    "profileBeforeChange",
     "profileChangeTeardown",
     "sendTelemetry",
+
+    // Child processes
+    "contentChildShutdown",
+
+    // All processes
     "webWorkersShutdown",
-    "xpcomThreadsShutdown"]) {
+    "xpcomThreadsShutdown",
+    ]) {
     let k = _k;
     Object.defineProperty(this, k, {
       configurable: true,
       get: function() {
         delete this[k];
         let result = new nsAsyncShutdownClient(AsyncShutdown[k]);
         Object.defineProperty(this, k, {
           value: result
@@ -261,9 +268,8 @@ nsAsyncShutdownService.prototype = {
 };
 
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([
     nsAsyncShutdownService,
     nsAsyncShutdownBarrier,
     nsAsyncShutdownClient,
 ]);
-
--- a/toolkit/components/asyncshutdown/nsIAsyncShutdown.idl
+++ b/toolkit/components/asyncshutdown/nsIAsyncShutdown.idl
@@ -155,31 +155,32 @@ interface nsIAsyncShutdownBarrier: nsISu
    * The callback always receives NS_OK.
    */
   void wait(in nsIAsyncShutdownCompletionCallback aOnReady);
 };
 
 /**
  * A service that allows registering shutdown-time dependencies.
  */
-[scriptable, uuid(8a9a0859-0404-4d50-9e76-10a4f56dfb51)]
+[scriptable, uuid(10f51032-dcc9-4732-bec0-c0b7d6596622)]
 interface nsIAsyncShutdownService: nsISupports {
   /**
    * Create a new barrier.
    *
    * By convention, the name should respect the following format:
    * "MyModuleName: Doing something while it's time"
    * e.g.
    * "OS.File: Waiting for clients to flush before shutting down"
    *
    * This attribute is uploaded as part of crash reports.
    */
   nsIAsyncShutdownBarrier makeBarrier(in AString aName);
 
-  // Barriers for global shutdown stages
+
+  // Barriers for global shutdown stages in the parent process.
 
   /**
    * Barrier for notification profile-before-change.
    */
   readonly attribute nsIAsyncShutdownClient profileBeforeChange;
 
   /**
    * Barrier for notification profile-change-teardown.
@@ -195,13 +196,18 @@ interface nsIAsyncShutdownService: nsISu
    * Barrier for notification web-workers-shutdown.
    */
   readonly attribute nsIAsyncShutdownClient webWorkersShutdown;
 
   /**
    * Barrier for notification xpcom-threads-shutdown.
    */
   readonly attribute nsIAsyncShutdownClient xpcomThreadsShutdown;
+
+
+  // Barriers for global shutdown stages in the content process.
+
+  readonly attribute nsIAsyncShutdownClient contentBeforeShutdown;
 };
 
 %{C++
 #define NS_ASYNCSHUTDOWNSERVICE_CONTRACTID "@mozilla.org/async-shutdown-service;1"
 %}