Bug 784404 - Intermittent assertion in dom/devicestorage/test/test_basic.html. r=bent
authorDoug Turner <dougt@dougt.org>
Sun, 26 Aug 2012 21:28:10 -0700
changeset 105536 a5ffaa0753dd052d540b69855646fa5a76fd9b4d
parent 105535 0a9e931cdcf3ffc4f34bcd440b1f2fe087afa44a
child 105548 8af6a22827ecaffe6328a02633411da0421ccb90
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersbent
bugs784404
milestone17.0a1
Bug 784404 - Intermittent assertion in dom/devicestorage/test/test_basic.html. r=bent
dom/devicestorage/DeviceStorageRequestParent.h
--- a/dom/devicestorage/DeviceStorageRequestParent.h
+++ b/dom/devicestorage/DeviceStorageRequestParent.h
@@ -44,21 +44,27 @@ private:
 
     virtual ~CancelableRunnable() {
     }
 
     NS_IMETHOD Run() {
       nsresult rv = NS_OK;
       if (!mCanceled) {
         rv = CancelableRun();
-        mParent->RemoveRunnable(this);
+
+        nsCOMPtr<nsIRunnable> event = NS_NewRunnableMethod(this, &CancelableRunnable::RemoveRunnable);
+        NS_DispatchToMainThread(event);
       }
       return rv;
     }
 
+    void RemoveRunnable() {
+      mParent->RemoveRunnable(this);
+    }
+
     void Cancel() {
       mCanceled = true;
     }
 
     virtual nsresult CancelableRun() = 0;
 
   protected:
     nsRefPtr<DeviceStorageRequestParent> mParent;
@@ -179,19 +185,21 @@ private:
       virtual ~PostStatResultEvent();
       virtual nsresult CancelableRun();
     private:
       int64_t mFreeBytes, mTotalBytes;
    };
 
 protected:
   void AddRunnable(CancelableRunnable* aRunnable) {
+    NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
     mRunnables.AppendElement(aRunnable);
   }
   void RemoveRunnable(CancelableRunnable* aRunnable) {
+    NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
     mRunnables.RemoveElement(aRunnable);
   }
   nsTArray<nsRefPtr<CancelableRunnable> > mRunnables;
 };
 
 } // namespace devicestorage
 } // namespace dom
 } // namespace mozilla