Bug 1049501: Don't let the GMPThread event loop recurse while handling IPDL shutdowns r=bsmedberg

This commit is contained in:
Randell Jesup 2014-08-14 13:50:25 -04:00
parent 1c39379cd6
commit 7ecd01e5fb

View File

@ -12,6 +12,7 @@
#include "nsAutoRef.h" #include "nsAutoRef.h"
#include "GMPParent.h" #include "GMPParent.h"
#include "mozilla/gmp/GMPTypes.h" #include "mozilla/gmp/GMPTypes.h"
#include "nsThread.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "runnable_utils.h" #include "runnable_utils.h"
@ -72,7 +73,9 @@ GMPVideoEncoderParent::GMPVideoEncoderParent(GMPParent *aPlugin)
GMPVideoEncoderParent::~GMPVideoEncoderParent() GMPVideoEncoderParent::~GMPVideoEncoderParent()
{ {
mEncodedThread->Shutdown(); if (mEncodedThread) {
mEncodedThread->Shutdown();
}
} }
GMPVideoHostImpl& GMPVideoHostImpl&
@ -238,6 +241,12 @@ GMPVideoEncoderParent::Shutdown()
} }
} }
static void
ShutdownEncodedThread(nsCOMPtr<nsIThread>& aThread)
{
aThread->Shutdown();
}
// Note: Keep this sync'd up with Shutdown // Note: Keep this sync'd up with Shutdown
void void
GMPVideoEncoderParent::ActorDestroy(ActorDestroyReason aWhy) GMPVideoEncoderParent::ActorDestroy(ActorDestroyReason aWhy)
@ -249,6 +258,15 @@ GMPVideoEncoderParent::ActorDestroy(ActorDestroyReason aWhy)
mCallback->Terminated(); mCallback->Terminated();
mCallback = nullptr; mCallback = nullptr;
} }
// Must be shut down before VideoEncoderDestroyed(), since this can recurse
// the GMPThread event loop. See bug 1049501
if (mEncodedThread) {
// Can't get it to allow me to use WrapRunnable with a nsCOMPtr<nsIThread>()
NS_DispatchToMainThread(
WrapRunnableNM<decltype(&ShutdownEncodedThread),
nsCOMPtr<nsIThread> >(&ShutdownEncodedThread, mEncodedThread));
mEncodedThread = nullptr;
}
if (mPlugin) { if (mPlugin) {
// Ignore any return code. It is OK for this to fail without killing the process. // Ignore any return code. It is OK for this to fail without killing the process.
mPlugin->VideoEncoderDestroyed(this); mPlugin->VideoEncoderDestroyed(this);