Skip to content

Commit

Permalink
Backed out changeset 097bdc2f5cd5 (bug 1753266) for causing build bus…
Browse files Browse the repository at this point in the history
…tages on Logging.h CLOSED TREE
  • Loading branch information
Norisz Fay committed Mar 16, 2022
1 parent e8e7c6a commit 2eed6a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 58 deletions.
65 changes: 8 additions & 57 deletions dom/media/systemservices/CamerasParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "MediaUtils.h"
#include "VideoFrameUtils.h"

#include "mozilla/AppShutdown.h"
#include "mozilla/Assertions.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/Unused.h"
Expand Down Expand Up @@ -228,12 +227,14 @@ void CamerasParent::StopVideoCapture() {
thread->Stop();
delete thread;
}
// May fail if already removed after RecvPCamerasConstructor().
(void)MustGetShutdownBarrier()->RemoveBlocker(self);
nsresult rv = MustGetShutdownBarrier()->RemoveBlocker(self);
MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
Unused << rv;
return NS_OK;
}));
MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv),
"dispatch for video thread shutdown");
if (NS_FAILED(rv)) {
LOG("Could not dispatch VideoCaptureThread destruction");
}
return rv;
}));
#ifdef DEBUG
Expand Down Expand Up @@ -1082,7 +1083,7 @@ CamerasParent::CamerasParent()
mPBackgroundEventTarget(GetCurrentSerialEventTarget()),
mChildIsAlive(true),
mDestroyed(false),
mWebRTCAlive(false) {
mWebRTCAlive(true) {
MOZ_ASSERT(mPBackgroundEventTarget != nullptr,
"GetCurrentThreadEventTarget failed");
LOG("CamerasParent: %p", this);
Expand All @@ -1093,68 +1094,19 @@ CamerasParent::CamerasParent()
}
}

// RecvPCamerasConstructor() is used because IPC messages, for
// Send__delete__(), cannot be sent from AllocPCamerasParent().
ipc::IPCResult CamerasParent::RecvPCamerasConstructor() {
ipc::AssertIsOnBackgroundThread();

// A shutdown blocker must be added if sNumOfOpenCamerasParentEngines might
// be incremented to indicate ownership of an sVideoCaptureThread.
// If this task were queued after checking !IsInOrBeyond(AppShutdown), then
// shutdown may have proceeded on the main thread and so the task may run
// too late to add the blocker.
// Don't dispatch from the constructor a runnable that may toggle the
// reference count, because the IPC thread does not get a reference until
// after the constructor returns.
NS_DispatchToMainThread(
NS_NewRunnableFunction(__func__, [self = RefPtr(this)]() {
nsresult rv = MustGetShutdownBarrier()->AddBlocker(
self, NS_LITERAL_STRING_FROM_CSTRING(__FILE__), __LINE__, u""_ns);
LOG("AddBlocker returned 0x%" PRIx32, rv);
// AddBlocker() will fail if called after all
// AsyncShutdown.profileBeforeChange conditions have resolved or been
// removed.
//
// The success of this AddBlocker() call is expected when an
// sVideoCaptureThread is created based on the assumption that at
// least one condition (e.g. nsIAsyncShutdownBlocker) added with
// AsyncShutdown.profileBeforeChange.addBlocker() will not resolve or
// be removed until it has queued a task and that task has run.
// (AyncShutdown.jsm's Spinner#observe() makes a similar assumption
// when it calls processNextEvent(), assuming that there will be some
// other event generated, before checking whether its Barrier.wait()
// promise has resolved.)
//
// If AppShutdown::IsInOrBeyond(AppShutdown) returned false,
// then this main thread task was queued before AppShutdown's
// sCurrentShutdownPhase is set to AppShutdown,
// which is before profile-before-change is notified,
// which is when AsyncShutdown conditions are run,
// which is when one condition would queue a task to resolve the
// condition or remove the blocker.
// That task runs after this task and before AsyncShutdown prevents
// further conditions being added through AddBlocker().
MOZ_ASSERT(NS_SUCCEEDED(rv) || !self->mWebRTCAlive);
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
}));

// AsyncShutdown barriers are available only for ShutdownPhases as late as
// XPCOMWillShutdown. The IPC background thread shuts down during
// XPCOMShutdownThreads, so actors may be created when AsyncShutdown
// barriers are no longer available.
// IsInOrBeyond() checks sCurrentShutdownPhase, which is atomic.
// ShutdownPhase::AppShutdown corresponds to profileBeforeChange used by
// MustGetShutdownBarrier() in the parent process.
if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdown)) {
// The usual blocker removal path depends on the existence of the
// `sVideoCaptureThread`, which is not ensured. Queue removal now.
NS_DispatchToMainThread(
NS_NewRunnableFunction(__func__, [self = RefPtr(this)]() {
// May fail if AddBlocker() failed.
(void)MustGetShutdownBarrier()->RemoveBlocker(self);
}));
return Send__delete__(this) ? IPC_OK() : IPC_FAIL(this, "Failed to send");
}

LOG("Spinning up WebRTC Cameras Thread");
MonitorAutoLock lock(*sThreadMonitor);
if (sVideoCaptureThread == nullptr) {
Expand All @@ -1170,7 +1122,6 @@ ipc::IPCResult CamerasParent::RecvPCamerasConstructor() {
MOZ_CRASH();
}
}
mWebRTCAlive = true;
sNumOfOpenCamerasParentEngines++;
return IPC_OK();
}
Expand Down
1 change: 0 additions & 1 deletion dom/media/systemservices/CamerasParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ class CamerasParent final : public PCamerasParent,
// sNumOfOpenCamerasParentEngines and sVideoCaptureThread are protected by
// sThreadMonitor
static StaticRefPtr<VideoEngine> sEngines[CaptureEngine::MaxEngine];
// Number of CamerasParents for which mWebRTCAlive is true.
static int32_t sNumOfOpenCamerasParentEngines;
static int32_t sNumOfCamerasParents;
static StaticMutex sMutex;
Expand Down

0 comments on commit 2eed6a1

Please sign in to comment.