Skip to content

Commit

Permalink
Bug 1287747 - GetFilesHelper must release mFiles and mGlobal on the m…
Browse files Browse the repository at this point in the history
…ain-thread, r=smaug
  • Loading branch information
bakulf committed Sep 17, 2016
1 parent f16fbf4 commit 845139c
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions dom/filesystem/GetFilesHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ 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
Expand All @@ -41,20 +41,28 @@ class ReleaseRunnable final : public Runnable

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
Expand Down Expand Up @@ -131,7 +139,8 @@ GetFilesHelper::GetFilesHelper(nsIGlobalObject* aGlobal, bool aRecursiveFlag)

GetFilesHelper::~GetFilesHelper()
{
ReleaseRunnable::MaybeReleaseOnMainThread(mPromises, mCallbacks);
ReleaseRunnable::MaybeReleaseOnMainThread(mPromises, mCallbacks, mFiles,
mGlobal.forget());
}

void
Expand Down

0 comments on commit 845139c

Please sign in to comment.