Bug 924665 - Fix bug whereby BackgroundPageThumbs captures can finish twice. r=markh
authorDrew Willcoxon <adw@mozilla.com>
Wed, 09 Oct 2013 10:13:03 -0700
changeset 150198 daa8fbedef2f
parent 150197 15bab6ba175d
child 150199 10824701bc80
push id25426
push userryanvm@gmail.com
push dateWed, 09 Oct 2013 19:23:34 +0000
treeherdermozilla-central@10824701bc80 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs924665
milestone27.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 924665 - Fix bug whereby BackgroundPageThumbs captures can finish twice. r=markh
toolkit/components/thumbnails/BackgroundPageThumbs.jsm
--- a/toolkit/components/thumbnails/BackgroundPageThumbs.jsm
+++ b/toolkit/components/thumbnails/BackgroundPageThumbs.jsm
@@ -327,17 +327,18 @@ Capture.prototype = {
       delete this._timeoutTimer;
     }
     if (this._msgMan) {
       this._msgMan.removeMessageListener("BackgroundPageThumbs:didCapture",
                                          this);
       delete this._msgMan;
     }
     delete this.captureCallback;
-    Services.ww.unregisterNotification(this);
+    delete this.doneCallbacks;
+    delete this.options;
   },
 
   // Called when the didCapture message is received.
   receiveMessage: function (msg) {
     tel("CAPTURE_SERVICE_TIME_MS", new Date() - this.startDate);
 
     // A different timed-out capture may have finally successfully completed, so
     // discard messages that aren't meant for this capture.
@@ -347,35 +348,36 @@ Capture.prototype = {
 
   // Called when the timeout timer fires.
   notify: function () {
     this._done(null, TEL_CAPTURE_DONE_TIMEOUT);
   },
 
   _done: function (data, reason) {
     // Note that _done will be called only once, by either receiveMessage or
-    // notify, since it calls destroy, which cancels the timeout timer and
+    // notify, since it calls destroy here, which cancels the timeout timer and
     // removes the didCapture message listener.
+    let { captureCallback, doneCallbacks, options } = this;
+    this.destroy();
 
     if (typeof(reason) != "number")
       throw new Error("A done reason must be given.");
     tel("CAPTURE_DONE_REASON_2", reason);
     if (data && data.telemetry) {
       // Telemetry is currently disabled in the content process (bug 680508).
       for (let id in data.telemetry) {
         tel(id, data.telemetry[id]);
       }
     }
 
     let done = () => {
-      this.captureCallback(this);
-      this.destroy();
-      for (let callback of this.doneCallbacks) {
+      captureCallback(this);
+      for (let callback of doneCallbacks) {
         try {
-          callback.call(this.options, this.url);
+          callback.call(options, this.url);
         }
         catch (err) {
           Cu.reportError(err);
         }
       }
     };
 
     if (!data) {