Bug 1287747 - GetFilesHelper must release mFiles and mGlobal on the main-thread, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Sat, 17 Sep 2016 09:55:30 +0200
changeset 355623 7b707a4dd05637594fe5680c3fed005d501ef078
parent 355622 ea326f6e7e6c485907fdb4e1739bcb2707f7c1bc
child 355624 a96d20959be2116edb706aa26a205439d912a0d7
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1287747
milestone51.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 1287747 - GetFilesHelper must release mFiles and mGlobal on the main-thread, r=smaug
dom/filesystem/GetFilesHelper.cpp
--- a/dom/filesystem/GetFilesHelper.cpp
+++ b/dom/filesystem/GetFilesHelper.cpp
@@ -16,50 +16,58 @@ namespace {
 
 // This class is used in the DTOR of GetFilesHelper to release resources in the
 // correct thread.
 class ReleaseRunnable final : public Runnable
 {
 public:
   static void
   MaybeReleaseOnMainThread(nsTArray<RefPtr<Promise>>& aPromises,
-                           nsTArray<RefPtr<GetFilesCallback>>& aCallbacks)
+                           nsTArray<RefPtr<GetFilesCallback>>& aCallbacks,
+                           Sequence<RefPtr<File>>& aFiles,
+                           already_AddRefed<nsIGlobalObject> aGlobal)
   {
     if (NS_IsMainThread()) {
       return;
     }
 
-    if (!aPromises.IsEmpty() || !aCallbacks.IsEmpty()) {
-      RefPtr<ReleaseRunnable> runnable =
-        new ReleaseRunnable(aPromises, aCallbacks);
-      NS_DispatchToMainThread(runnable);
-    }
+    RefPtr<ReleaseRunnable> runnable =
+      new ReleaseRunnable(aPromises, aCallbacks, aFiles, Move(aGlobal));
+    NS_DispatchToMainThread(runnable);
   }
 
   NS_IMETHOD
   Run() override
   {
     MOZ_ASSERT(NS_IsMainThread());
 
     mPromises.Clear();
     mCallbacks.Clear();
+    mFiles.Clear();
+    mGlobal = nullptr;
 
     return NS_OK;
   }
 
 private:
   ReleaseRunnable(nsTArray<RefPtr<Promise>>& aPromises,
-                  nsTArray<RefPtr<GetFilesCallback>>& aCallbacks)
+                  nsTArray<RefPtr<GetFilesCallback>>& aCallbacks,
+                  Sequence<RefPtr<File>>& aFiles,
+                  already_AddRefed<nsIGlobalObject> aGlobal)
   {
     mPromises.SwapElements(aPromises);
     mCallbacks.SwapElements(aCallbacks);
+    mFiles.SwapElements(aFiles);
+    mGlobal = aGlobal;
   }
 
   nsTArray<RefPtr<Promise>> mPromises;
   nsTArray<RefPtr<GetFilesCallback>> mCallbacks;
+  Sequence<RefPtr<File>> mFiles;
+  nsCOMPtr<nsIGlobalObject> mGlobal;
 };
 
 } // anonymous
 
 ///////////////////////////////////////////////////////////////////////////////
 // GetFilesHelper Base class
 
 already_AddRefed<GetFilesHelper>
@@ -126,17 +134,18 @@ GetFilesHelper::GetFilesHelper(nsIGlobal
   , mErrorResult(NS_OK)
   , mMutex("GetFilesHelper::mMutex")
   , mCanceled(false)
 {
 }
 
 GetFilesHelper::~GetFilesHelper()
 {
-  ReleaseRunnable::MaybeReleaseOnMainThread(mPromises, mCallbacks);
+  ReleaseRunnable::MaybeReleaseOnMainThread(mPromises, mCallbacks, mFiles,
+                                            mGlobal.forget());
 }
 
 void
 GetFilesHelper::AddPromise(Promise* aPromise)
 {
   MOZ_ASSERT(aPromise);
 
   // Still working.