Bug 887889 - Clean up ContentPrefServiceChild on xpcom-shutdown r?mak draft
authorDoug Thayer <dothayer@mozilla.com>
Fri, 30 Mar 2018 15:54:08 -0700
changeset 788706 be5903304b63dffffa17f7e2305243464c537e16
parent 788705 825867eb7878a6838ecc1d05bc3522407a631da0
child 788707 6152e912d0df502095ae69b034b3034e6171d6e9
push id108067
push userbmo:dothayer@mozilla.com
push dateThu, 26 Apr 2018 21:12:12 +0000
reviewersmak
bugs887889
milestone61.0a1
Bug 887889 - Clean up ContentPrefServiceChild on xpcom-shutdown r?mak I'm not sure why this became necessary as a result of migrating to Sqlite.jsm, but this is the only way I've found to eliminate leaks from the tab process on shutdown. These leaks occur when the child process requests something from the ContentPrefService2 but shuts down before it gets its response. MozReview-Commit-ID: 2Haks17D6Em
toolkit/components/contentprefs/ContentPrefServiceChild.jsm
--- a/toolkit/components/contentprefs/ContentPrefServiceChild.jsm
+++ b/toolkit/components/contentprefs/ContentPrefServiceChild.jsm
@@ -57,16 +57,23 @@ var ContentPrefServiceChild = {
 
   // Map from random ID string -> CallbackCaller, per request
   _requests: new Map(),
 
   init() {
     Services.cpmm.addMessageListener("ContentPrefs:HandleResult", this);
     Services.cpmm.addMessageListener("ContentPrefs:HandleError", this);
     Services.cpmm.addMessageListener("ContentPrefs:HandleCompletion", this);
+    Services.obs.addObserver(this, "xpcom-shutdown");
+  },
+
+  observe() {
+    Services.obs.removeObserver(this, "xpcom-shutdown");
+    delete this._observers;
+    delete this._requests;
   },
 
   receiveMessage(msg) {
     let data = msg.data;
     let callback;
     switch (msg.name) {
       case "ContentPrefs:HandleResult":
         callback = this._requests.get(data.requestId);