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 1789b9c456
commit c2335eafbc
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;
MessageLoop* ImageBridgeParent::sMainLoop = nullptr;
ImageBridgeParent::ImageBridgeParent(MessageLoop* aLoop,
Transport* aTransport,
ProcessId aChildProcessId)
@ -57,6 +59,7 @@ ImageBridgeParent::ImageBridgeParent(MessageLoop* aLoop,
// with several bridges
CompositableMap::Create();
sImageBridges[aChildProcessId] = this;
sMainLoop = MessageLoop::current();
}
ImageBridgeParent::~ImageBridgeParent()
@ -271,23 +274,11 @@ MessageLoop * ImageBridgeParent::GetMessageLoop() const {
return mMessageLoop;
}
class ReleaseRunnable : public nsRunnable
static void
DeferredReleaseImageBridgeParentOnMainThread(ImageBridgeParent* aDyingImageBridgeParent)
{
public:
ReleaseRunnable(ImageBridgeParent* aRef)
: mRef(aRef)
{
}
NS_IMETHOD Run()
{
mRef->Release();
return NS_OK;
}
private:
ImageBridgeParent* mRef;
};
aDyingImageBridgeParent->Release();
}
void
ImageBridgeParent::DeferredDestroy()
@ -295,8 +286,9 @@ ImageBridgeParent::DeferredDestroy()
ImageBridgeParent* self;
mSelfRef.forget(&self);
nsCOMPtr<nsIRunnable> runnable = new ReleaseRunnable(self);
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToMainThread(runnable)));
sMainLoop->PostTask(
FROM_HERE,
NewRunnableFunction(&DeferredReleaseImageBridgeParentOnMainThread, this));
}
ImageBridgeParent*

View File

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