Bug 1131327 - Patch 10 - Remember to remove the feature. r=baku
authorNikhil Marathe <nsm.nikhil@gmail.com>
Fri, 17 Apr 2015 16:44:58 -0700
changeset 272135 fc091f913859e9545f535d57d3690152258818c1
parent 272134 b24b2eb809c3fb06f5f8238caaeec19ed90f9abb
child 272136 527cd70f241fea6bf9d0cb0d1745d21621795259
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1131327
milestone40.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 1131327 - Patch 10 - Remember to remove the feature. r=baku
dom/workers/ServiceWorkerRegistration.cpp
dom/workers/ServiceWorkerRegistration.h
--- a/dom/workers/ServiceWorkerRegistration.cpp
+++ b/dom/workers/ServiceWorkerRegistration.cpp
@@ -842,22 +842,28 @@ public:
     mListener->StopListeningForEvents();
     return true;
   }
 };
 
 void
 ServiceWorkerRegistrationWorkerThread::ReleaseListener(Reason aReason)
 {
-  // Can't assert worker thread here since the worker may have gone away.
-  MOZ_ASSERT(!NS_IsMainThread());
   if (!mListener) {
     return;
   }
 
+  // We can assert worker here, because:
+  // 1) We always AddFeature, so if the worker has shutdown already, we'll have
+  //    received Notify and removed it. If AddFeature had failed, mListener will
+  //    be null and we won't reach here.
+  // 2) Otherwise, worker is still around even if we are going away.
+  mWorkerPrivate->AssertIsOnWorkerThread();
+  mWorkerPrivate->RemoveFeature(mWorkerPrivate->GetJSContext(), this);
+
   mListener->ClearRegistration();
 
   if (aReason == RegistrationIsGoingAway) {
     nsRefPtr<AsyncStopListeningRunnable> r =
       new AsyncStopListeningRunnable(mListener);
     MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToMainThread(r)));
   } else if (aReason == WorkerIsGoingAway) {
     nsRefPtr<SyncStopListeningRunnable> r =
@@ -867,16 +873,23 @@ ServiceWorkerRegistrationWorkerThread::R
     }
   } else {
     MOZ_CRASH("Bad reason");
   }
   mListener = nullptr;
   mWorkerPrivate = nullptr;
 }
 
+bool
+ServiceWorkerRegistrationWorkerThread::Notify(JSContext* aCx, workers::Status aStatus)
+{
+  ReleaseListener(WorkerIsGoingAway);
+  return true;
+}
+
 class FireUpdateFoundRunnable final : public WorkerRunnable
 {
   nsRefPtr<WorkerListener> mListener;
 public:
   FireUpdateFoundRunnable(WorkerPrivate* aWorkerPrivate,
                           WorkerListener* aListener)
     : WorkerRunnable(aWorkerPrivate, WorkerThreadModifyBusyCount)
     , mListener(aListener)
--- a/dom/workers/ServiceWorkerRegistration.h
+++ b/dom/workers/ServiceWorkerRegistration.h
@@ -205,21 +205,17 @@ public:
 
   void
   GetScope(nsAString& aScope) const
   {
     aScope = mScope;
   }
 
   bool
-  Notify(JSContext* aCx, workers::Status aStatus) override
-  {
-    ReleaseListener(WorkerIsGoingAway);
-    return true;
-  }
+  Notify(JSContext* aCx, workers::Status aStatus) override;
 
 private:
   enum Reason
   {
     RegistrationIsGoingAway = 0,
     WorkerIsGoingAway,
   };