Bug 862256 - don't (re)reference CameraControl object during/after destructor, r=sotaro, a=tef+

This commit is contained in:
Mike Habicher 2013-04-17 16:30:44 +02:00
parent 84e2de4a5d
commit 282ec3c583
2 changed files with 32 additions and 7 deletions

View File

@ -275,19 +275,40 @@ CameraControlImpl::OnShutter()
}
}
void
CameraControlImpl::OnClosedInternal()
class OnClosedTask : public nsRunnable
{
DOM_CAMERA_LOGI("Camera hardware was closed\n");
if (mOnClosedCb.get()) {
mOnClosedCb->HandleEvent();
public:
OnClosedTask(nsMainThreadPtrHandle<nsICameraClosedCallback> onClosed, uint64_t aWindowId)
: mOnClosedCb(onClosed)
, mWindowId(aWindowId)
{
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
}
}
virtual ~OnClosedTask()
{
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
}
NS_IMETHOD Run()
{
MOZ_ASSERT(NS_IsMainThread());
if (mOnClosedCb.get() && nsDOMCameraManager::IsWindowStillActive(mWindowId)) {
mOnClosedCb->HandleEvent();
}
return NS_OK;
}
protected:
nsMainThreadPtrHandle<nsICameraClosedCallback> mOnClosedCb;
uint64_t mWindowId;
};
void
CameraControlImpl::OnClosed()
{
nsCOMPtr<nsIRunnable> onClosed = NS_NewRunnableMethod(this, &CameraControlImpl::OnClosedInternal);
nsCOMPtr<nsIRunnable> onClosed = new OnClosedTask(mOnClosedCb, mWindowId);
nsresult rv = NS_DispatchToMainThread(onClosed);
if (NS_FAILED(rv)) {
DOM_CAMERA_LOGW("Failed to dispatch onClosed event to main thread (%d)\n", rv);

View File

@ -218,6 +218,10 @@ GonkCameraHardware::~GonkCameraHardware()
mCamera.clear();
mNativeWindow.clear();
if (mClosing) {
return;
}
/**
* Trigger the OnClosed event; the upper layers can't do anything
* with the hardware layer once they receive this event.