diff --git a/dom/media/MediaResource.cpp b/dom/media/MediaResource.cpp index 80ceff511de..8cd5e00fed1 100644 --- a/dom/media/MediaResource.cpp +++ b/dom/media/MediaResource.cpp @@ -50,20 +50,14 @@ namespace mozilla { void MediaResource::Destroy() { - // If we're being destroyed on a non-main thread, we AddRef again and - // use a proxy to release the MediaResource on the main thread, where - // the MediaResource is deleted. This ensures we only delete the - // MediaResource on the main thread. - if (!NS_IsMainThread()) { - nsCOMPtr mainThread = do_GetMainThread(); - NS_ENSURE_TRUE_VOID(mainThread); - nsRefPtr doomed(this); - if (NS_FAILED(NS_ProxyRelease(mainThread, doomed, true))) { - NS_WARNING("Failed to proxy release to main thread!"); - } - } else { + // Ensures we only delete the MediaResource on the main thread. + if (NS_IsMainThread()) { delete this; + return; } + nsCOMPtr destroyRunnable = + NS_NewNonOwningRunnableMethod(this, &MediaResource::Destroy); + MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToMainThread(destroyRunnable))); } NS_IMPL_ADDREF(MediaResource)