mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-22 23:27:30 +09:00
Bug 1426129 - Hold CamerasChild via promoting "this" to a RefPtr. r=pehrsons, a=RyanVM
This commit is contained in:
parent
e6afe55c10
commit
8e5fec311a
2 changed files with 23 additions and 3 deletions
|
|
@ -35,7 +35,9 @@ CamerasSingleton::CamerasSingleton()
|
||||||
: mCamerasMutex("CamerasSingleton::mCamerasMutex"),
|
: mCamerasMutex("CamerasSingleton::mCamerasMutex"),
|
||||||
mCameras(nullptr),
|
mCameras(nullptr),
|
||||||
mCamerasChildThread(nullptr),
|
mCamerasChildThread(nullptr),
|
||||||
mFakeDeviceChangeEventThread(nullptr) {
|
mFakeDeviceChangeEventThread(nullptr),
|
||||||
|
mInShutdown(false)
|
||||||
|
{
|
||||||
LOG(("CamerasSingleton: %p", this));
|
LOG(("CamerasSingleton: %p", this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -285,6 +287,7 @@ CamerasChild::NumberOfCapabilities(CaptureEngine aCapEngine,
|
||||||
LOG((__PRETTY_FUNCTION__));
|
LOG((__PRETTY_FUNCTION__));
|
||||||
LOG(("NumberOfCapabilities for %s", deviceUniqueIdUTF8));
|
LOG(("NumberOfCapabilities for %s", deviceUniqueIdUTF8));
|
||||||
nsCString unique_id(deviceUniqueIdUTF8);
|
nsCString unique_id(deviceUniqueIdUTF8);
|
||||||
|
RefPtr<CamerasChild> deathGrip = this;
|
||||||
nsCOMPtr<nsIRunnable> runnable =
|
nsCOMPtr<nsIRunnable> runnable =
|
||||||
mozilla::NewNonOwningRunnableMethod<CaptureEngine, nsCString>
|
mozilla::NewNonOwningRunnableMethod<CaptureEngine, nsCString>
|
||||||
(this, &CamerasChild::SendNumberOfCapabilities, aCapEngine, unique_id);
|
(this, &CamerasChild::SendNumberOfCapabilities, aCapEngine, unique_id);
|
||||||
|
|
@ -321,6 +324,7 @@ int
|
||||||
CamerasChild::EnsureInitialized(CaptureEngine aCapEngine)
|
CamerasChild::EnsureInitialized(CaptureEngine aCapEngine)
|
||||||
{
|
{
|
||||||
LOG((__PRETTY_FUNCTION__));
|
LOG((__PRETTY_FUNCTION__));
|
||||||
|
RefPtr<CamerasChild> deathGrip = this;
|
||||||
nsCOMPtr<nsIRunnable> runnable =
|
nsCOMPtr<nsIRunnable> runnable =
|
||||||
mozilla::NewNonOwningRunnableMethod<CaptureEngine>
|
mozilla::NewNonOwningRunnableMethod<CaptureEngine>
|
||||||
(this, &CamerasChild::SendEnsureInitialized, aCapEngine);
|
(this, &CamerasChild::SendEnsureInitialized, aCapEngine);
|
||||||
|
|
@ -336,6 +340,7 @@ CamerasChild::GetCaptureCapability(CaptureEngine aCapEngine,
|
||||||
webrtc::CaptureCapability& capability)
|
webrtc::CaptureCapability& capability)
|
||||||
{
|
{
|
||||||
LOG(("GetCaptureCapability: %s %d", unique_idUTF8, capability_number));
|
LOG(("GetCaptureCapability: %s %d", unique_idUTF8, capability_number));
|
||||||
|
RefPtr<CamerasChild> deathGrip = this;
|
||||||
nsCString unique_id(unique_idUTF8);
|
nsCString unique_id(unique_idUTF8);
|
||||||
nsCOMPtr<nsIRunnable> runnable =
|
nsCOMPtr<nsIRunnable> runnable =
|
||||||
mozilla::NewNonOwningRunnableMethod<CaptureEngine, nsCString, unsigned int>
|
mozilla::NewNonOwningRunnableMethod<CaptureEngine, nsCString, unsigned int>
|
||||||
|
|
@ -374,6 +379,7 @@ CamerasChild::GetCaptureDevice(CaptureEngine aCapEngine,
|
||||||
bool* scary)
|
bool* scary)
|
||||||
{
|
{
|
||||||
LOG((__PRETTY_FUNCTION__));
|
LOG((__PRETTY_FUNCTION__));
|
||||||
|
RefPtr<CamerasChild> deathGrip = this;
|
||||||
nsCOMPtr<nsIRunnable> runnable =
|
nsCOMPtr<nsIRunnable> runnable =
|
||||||
mozilla::NewNonOwningRunnableMethod<CaptureEngine, unsigned int>
|
mozilla::NewNonOwningRunnableMethod<CaptureEngine, unsigned int>
|
||||||
(this, &CamerasChild::SendGetCaptureDevice, aCapEngine, list_number);
|
(this, &CamerasChild::SendGetCaptureDevice, aCapEngine, list_number);
|
||||||
|
|
@ -413,6 +419,7 @@ CamerasChild::AllocateCaptureDevice(CaptureEngine aCapEngine,
|
||||||
const nsACString& aOrigin)
|
const nsACString& aOrigin)
|
||||||
{
|
{
|
||||||
LOG((__PRETTY_FUNCTION__));
|
LOG((__PRETTY_FUNCTION__));
|
||||||
|
RefPtr<CamerasChild> deathGrip = this;
|
||||||
nsCString unique_id(unique_idUTF8);
|
nsCString unique_id(unique_idUTF8);
|
||||||
nsCString origin(aOrigin);
|
nsCString origin(aOrigin);
|
||||||
nsCOMPtr<nsIRunnable> runnable =
|
nsCOMPtr<nsIRunnable> runnable =
|
||||||
|
|
@ -444,6 +451,7 @@ CamerasChild::ReleaseCaptureDevice(CaptureEngine aCapEngine,
|
||||||
const int capture_id)
|
const int capture_id)
|
||||||
{
|
{
|
||||||
LOG((__PRETTY_FUNCTION__));
|
LOG((__PRETTY_FUNCTION__));
|
||||||
|
RefPtr<CamerasChild> deathGrip = this;
|
||||||
nsCOMPtr<nsIRunnable> runnable =
|
nsCOMPtr<nsIRunnable> runnable =
|
||||||
mozilla::NewNonOwningRunnableMethod<CaptureEngine, int>
|
mozilla::NewNonOwningRunnableMethod<CaptureEngine, int>
|
||||||
(this, &CamerasChild::SendReleaseCaptureDevice, aCapEngine, capture_id);
|
(this, &CamerasChild::SendReleaseCaptureDevice, aCapEngine, capture_id);
|
||||||
|
|
@ -491,6 +499,7 @@ CamerasChild::StartCapture(CaptureEngine aCapEngine,
|
||||||
webrtcCaps.rawType,
|
webrtcCaps.rawType,
|
||||||
webrtcCaps.codecType,
|
webrtcCaps.codecType,
|
||||||
webrtcCaps.interlaced);
|
webrtcCaps.interlaced);
|
||||||
|
RefPtr<CamerasChild> deathGrip = this;
|
||||||
nsCOMPtr<nsIRunnable> runnable =
|
nsCOMPtr<nsIRunnable> runnable =
|
||||||
mozilla::NewNonOwningRunnableMethod<CaptureEngine, int, CaptureCapability>
|
mozilla::NewNonOwningRunnableMethod<CaptureEngine, int, CaptureCapability>
|
||||||
(this, &CamerasChild::SendStartCapture, aCapEngine, capture_id, capCap);
|
(this, &CamerasChild::SendStartCapture, aCapEngine, capture_id, capCap);
|
||||||
|
|
@ -502,6 +511,7 @@ int
|
||||||
CamerasChild::StopCapture(CaptureEngine aCapEngine, const int capture_id)
|
CamerasChild::StopCapture(CaptureEngine aCapEngine, const int capture_id)
|
||||||
{
|
{
|
||||||
LOG((__PRETTY_FUNCTION__));
|
LOG((__PRETTY_FUNCTION__));
|
||||||
|
RefPtr<CamerasChild> deathGrip = this;
|
||||||
nsCOMPtr<nsIRunnable> runnable =
|
nsCOMPtr<nsIRunnable> runnable =
|
||||||
mozilla::NewNonOwningRunnableMethod<CaptureEngine, int>
|
mozilla::NewNonOwningRunnableMethod<CaptureEngine, int>
|
||||||
(this, &CamerasChild::SendStopCapture, aCapEngine, capture_id);
|
(this, &CamerasChild::SendStopCapture, aCapEngine, capture_id);
|
||||||
|
|
@ -567,6 +577,7 @@ CamerasChild::ShutdownParent()
|
||||||
// Delete the parent actor.
|
// Delete the parent actor.
|
||||||
// CamerasChild (this) will remain alive and is only deleted by the
|
// CamerasChild (this) will remain alive and is only deleted by the
|
||||||
// IPC layer when SendAllDone returns.
|
// IPC layer when SendAllDone returns.
|
||||||
|
RefPtr<CamerasChild> deathGrip = this;
|
||||||
nsCOMPtr<nsIRunnable> deleteRunnable =
|
nsCOMPtr<nsIRunnable> deleteRunnable =
|
||||||
mozilla::NewNonOwningRunnableMethod(this, &CamerasChild::SendAllDone);
|
mozilla::NewNonOwningRunnableMethod(this, &CamerasChild::SendAllDone);
|
||||||
CamerasSingleton::Thread()->Dispatch(deleteRunnable, NS_DISPATCH_NORMAL);
|
CamerasSingleton::Thread()->Dispatch(deleteRunnable, NS_DISPATCH_NORMAL);
|
||||||
|
|
@ -695,7 +706,7 @@ CamerasChild::~CamerasChild()
|
||||||
{
|
{
|
||||||
LOG(("~CamerasChild: %p", this));
|
LOG(("~CamerasChild: %p", this));
|
||||||
|
|
||||||
{
|
if (!CamerasSingleton::InShutdown()) {
|
||||||
OffTheBooksMutexAutoLock lock(CamerasSingleton::Mutex());
|
OffTheBooksMutexAutoLock lock(CamerasSingleton::Mutex());
|
||||||
// In normal circumstances we've already shut down and the
|
// In normal circumstances we've already shut down and the
|
||||||
// following does nothing. But on fatal IPC errors we will
|
// following does nothing. But on fatal IPC errors we will
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,14 @@ public:
|
||||||
return gTheInstance.get()->mFakeDeviceChangeEventThread;
|
return gTheInstance.get()->mFakeDeviceChangeEventThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool InShutdown() {
|
||||||
|
return gTheInstance.get()->mInShutdown;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void StartShutdown() {
|
||||||
|
gTheInstance.get()->mInShutdown = true;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Singleton<CamerasSingleton> gTheInstance;
|
static Singleton<CamerasSingleton> gTheInstance;
|
||||||
|
|
||||||
|
|
@ -106,6 +114,7 @@ private:
|
||||||
CamerasChild* mCameras;
|
CamerasChild* mCameras;
|
||||||
nsCOMPtr<nsIThread> mCamerasChildThread;
|
nsCOMPtr<nsIThread> mCamerasChildThread;
|
||||||
nsCOMPtr<nsIThread> mFakeDeviceChangeEventThread;
|
nsCOMPtr<nsIThread> mFakeDeviceChangeEventThread;
|
||||||
|
Atomic<bool> mInShutdown;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get a pointer to a CamerasChild object we can use to do IPC with.
|
// Get a pointer to a CamerasChild object we can use to do IPC with.
|
||||||
|
|
@ -145,7 +154,7 @@ class CamerasChild final : public PCamerasChild
|
||||||
public:
|
public:
|
||||||
// We are owned by the PBackground thread only. CamerasSingleton
|
// We are owned by the PBackground thread only. CamerasSingleton
|
||||||
// takes a non-owning reference.
|
// takes a non-owning reference.
|
||||||
NS_INLINE_DECL_REFCOUNTING(CamerasChild)
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CamerasChild)
|
||||||
|
|
||||||
// IPC messages recevied, received on the PBackground thread
|
// IPC messages recevied, received on the PBackground thread
|
||||||
// these are the actual callbacks with data
|
// these are the actual callbacks with data
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue