Bug 774388 - Patch 11: Use a plain RunnableFunction to release the ImageBridgeParent singleton - r=mattwoodrow

This commit is contained in:
Benoit Jacob 2014-07-04 14:04:12 -04:00
parent 69cbbb2503
commit 1867da80fd
2 changed files with 12 additions and 18 deletions

View File

@ -44,6 +44,8 @@ using namespace mozilla::gfx;
std::map<base::ProcessId, ImageBridgeParent*> ImageBridgeParent::sImageBridges; std::map<base::ProcessId, ImageBridgeParent*> ImageBridgeParent::sImageBridges;
MessageLoop* ImageBridgeParent::sMainLoop = nullptr;
ImageBridgeParent::ImageBridgeParent(MessageLoop* aLoop, ImageBridgeParent::ImageBridgeParent(MessageLoop* aLoop,
Transport* aTransport, Transport* aTransport,
ProcessId aChildProcessId) ProcessId aChildProcessId)
@ -57,6 +59,7 @@ ImageBridgeParent::ImageBridgeParent(MessageLoop* aLoop,
// with several bridges // with several bridges
CompositableMap::Create(); CompositableMap::Create();
sImageBridges[aChildProcessId] = this; sImageBridges[aChildProcessId] = this;
sMainLoop = MessageLoop::current();
} }
ImageBridgeParent::~ImageBridgeParent() ImageBridgeParent::~ImageBridgeParent()
@ -271,32 +274,21 @@ MessageLoop * ImageBridgeParent::GetMessageLoop() const {
return mMessageLoop; return mMessageLoop;
} }
class ReleaseRunnable : public nsRunnable static void
{ DeferredReleaseImageBridgeParentOnMainThread(ImageBridgeParent* aDyingImageBridgeParent)
public:
ReleaseRunnable(ImageBridgeParent* aRef)
: mRef(aRef)
{ {
aDyingImageBridgeParent->Release();
} }
NS_IMETHOD Run()
{
mRef->Release();
return NS_OK;
}
private:
ImageBridgeParent* mRef;
};
void void
ImageBridgeParent::DeferredDestroy() ImageBridgeParent::DeferredDestroy()
{ {
ImageBridgeParent* self; ImageBridgeParent* self;
mSelfRef.forget(&self); mSelfRef.forget(&self);
nsCOMPtr<nsIRunnable> runnable = new ReleaseRunnable(self); sMainLoop->PostTask(
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToMainThread(runnable))); FROM_HERE,
NewRunnableFunction(&DeferredReleaseImageBridgeParentOnMainThread, this));
} }
ImageBridgeParent* ImageBridgeParent*

View File

@ -151,6 +151,8 @@ private:
* Map of all living ImageBridgeParent instances * Map of all living ImageBridgeParent instances
*/ */
static std::map<base::ProcessId, ImageBridgeParent*> sImageBridges; static std::map<base::ProcessId, ImageBridgeParent*> sImageBridges;
static MessageLoop* sMainLoop;
}; };
} // layers } // layers