Backed out 24 changesets (bug 1824465) for causing failures in nsISupportsImpl.cpp CLOSED TREE

Backed out changeset a5c8f22b7170 (bug 1824465)
Backed out changeset b551b655ac72 (bug 1824465)
Backed out changeset 0e6768a6419c (bug 1824465)
Backed out changeset fb115ebb7fe0 (bug 1824465)
Backed out changeset aaa7a2c8aa3b (bug 1824465)
Backed out changeset 7ef94bfa90b3 (bug 1824465)
Backed out changeset a4238fd6b86f (bug 1824465)
Backed out changeset 3a88e4cfbe45 (bug 1824465)
Backed out changeset 40c2467d3162 (bug 1824465)
Backed out changeset 8f900395c72c (bug 1824465)
Backed out changeset 92e4c6e4d73c (bug 1824465)
Backed out changeset 445c5d5d9661 (bug 1824465)
Backed out changeset de51ed5389d9 (bug 1824465)
Backed out changeset 72049d72bcb6 (bug 1824465)
Backed out changeset 126773c2427a (bug 1824465)
Backed out changeset 886e76bc80be (bug 1824465)
Backed out changeset a69a851411f0 (bug 1824465)
Backed out changeset 703599cf6189 (bug 1824465)
Backed out changeset 11ecb78ebc15 (bug 1824465)
Backed out changeset 563255aaa1e1 (bug 1824465)
Backed out changeset d1bf32c2a6c6 (bug 1824465)
Backed out changeset ef28b2777487 (bug 1824465)
Backed out changeset a2015d354bb1 (bug 1824465)
Backed out changeset 31d6b53fdc6a (bug 1824465)
This commit is contained in:
Noemi Erli 2023-04-06 01:50:55 +03:00
parent 4edd0c2cff
commit d637b3f05e
126 changed files with 467 additions and 337 deletions

View file

@ -2090,6 +2090,8 @@ void ContentParent::ProcessingError(Result aCode, const char* aReason) {
}
void ContentParent::ActorDestroy(ActorDestroyReason why) {
MOZ_RELEASE_ASSERT(mSelfRef);
if (mForceKillTimer) {
mForceKillTimer->Cancel();
mForceKillTimer = nullptr;
@ -2259,6 +2261,8 @@ void ContentParent::ActorDestroy(ActorDestroyReason why) {
mPendingLoadStates.Clear();
}
void ContentParent::ActorDealloc() { mSelfRef = nullptr; }
bool ContentParent::TryToRecycleE10SOnly() {
// Only try to recycle "web" content processes, as other remote types are
// generally more unique, and cannot be effectively re-used. This is disabled
@ -2697,6 +2701,8 @@ bool ContentParent::BeginSubprocessLaunch(ProcessPriority aPriority) {
}
#endif
// See also ActorDealloc.
mSelfRef = this;
mLaunchYieldTS = TimeStamp::Now();
return mSubprocess->AsyncLaunch(std::move(extraArgs));
}
@ -2865,7 +2871,8 @@ RefPtr<ContentParent::LaunchPromise> ContentParent::LaunchSubprocessAsync(
}
ContentParent::ContentParent(const nsACString& aRemoteType, int32_t aJSPluginID)
: mSubprocess(nullptr),
: mSelfRef(nullptr),
mSubprocess(nullptr),
mLaunchTS(TimeStamp::Now()),
mLaunchYieldTS(mLaunchTS),
mActivateTS(mLaunchTS),
@ -3759,7 +3766,7 @@ class RequestContentJSInterruptRunnable final : public Runnable {
// executed. So the runnable needs not to care about keeping it alive,
// as it is surely dispatched earlier than the
// HangMonitorParent::ShutdownOnThread.
RefPtr<PProcessHangMonitorParent> mHangMonitorActor;
PProcessHangMonitorParent* mHangMonitorActor;
};
void ContentParent::SignalImpendingShutdownToContentJS() {

View file

@ -685,6 +685,7 @@ class ContentParent final : public PContentParent,
const char* aOperation) const;
void ActorDestroy(ActorDestroyReason why) override;
void ActorDealloc() override;
bool ShouldContinueFromReplyTimeout() override;
@ -1485,6 +1486,9 @@ class ContentParent final : public PContentParent,
void AssertAlive();
private:
// Released in ActorDealloc; deliberately not exposed to the CC.
RefPtr<ContentParent> mSelfRef;
// If you add strong pointers to cycle collected objects here, be sure to
// release these objects in ShutDownProcess. See the comment there for more
// details.
@ -1583,7 +1587,7 @@ class ContentParent final : public PContentParent,
ScopedClose mChildXSocketFdDup;
#endif
RefPtr<PProcessHangMonitorParent> mHangMonitorActor;
PProcessHangMonitorParent* mHangMonitorActor;
UniquePtr<gfx::DriverCrashGuard> mDriverCrashGuard;
UniquePtr<MemoryReportRequestHost> mMemoryReportRequest;

View file

@ -469,7 +469,7 @@ union IPCDataTransferOrError {
* and a content process. There is exactly one PContentParent/PContentChild pair
* for each content process.
*/
[NestedUpTo=inside_cpow, NeedsOtherPid]
[ManualDealloc, NestedUpTo=inside_cpow, NeedsOtherPid]
sync protocol PContent
{
manages PBrowser;

View file

@ -23,7 +23,7 @@ struct SlowScriptData
double duration;
};
[ChildImpl=virtual, ParentImpl=virtual]
[ManualDealloc, ChildImpl=virtual, ParentImpl=virtual]
protocol PProcessHangMonitor
{
parent:

View file

@ -26,14 +26,11 @@
#include "mozilla/ipc/TaskFactory.h"
#include "mozilla/Monitor.h"
#include "mozilla/Preferences.h"
#include "mozilla/StaticMonitor.h"
#include "mozilla/StaticPrefs_browser.h"
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/Unused.h"
#include "mozilla/WeakPtr.h"
#include "MainThreadUtils.h"
#include "nsExceptionHandler.h"
#include "nsFrameLoader.h"
#include "nsIHangReport.h"
@ -87,8 +84,8 @@ namespace {
class HangMonitorChild : public PProcessHangMonitorChild,
public BackgroundHangAnnotator {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING_WITH_DELETE_ON_MAIN_THREAD(
HangMonitorChild, override)
explicit HangMonitorChild(ProcessHangMonitor* aMonitor);
~HangMonitorChild() override;
void Bind(Endpoint<PProcessHangMonitorChild>&& aEndpoint);
@ -135,12 +132,7 @@ class HangMonitorChild : public PProcessHangMonitorChild,
bool InterruptCallback();
void Shutdown();
static HangMonitorChild* Get() MOZ_REQUIRES(sMainThreadCapability) {
return sInstance;
}
static void CreateAndBind(ProcessHangMonitor* aMonitor,
Endpoint<PProcessHangMonitorChild>&& aEndpoint);
static HangMonitorChild* Get() { return sInstance; }
void Dispatch(already_AddRefed<nsIRunnable> aRunnable) {
mHangMonitor->Dispatch(std::move(aRunnable));
@ -151,15 +143,14 @@ class HangMonitorChild : public PProcessHangMonitorChild,
protected:
friend class mozilla::ProcessHangMonitor;
static Maybe<Monitor> sMonitor;
static Atomic<bool, SequentiallyConsistent> sInitializing;
private:
explicit HangMonitorChild(ProcessHangMonitor* aMonitor);
~HangMonitorChild() override;
void ShutdownOnThread();
static StaticRefPtr<HangMonitorChild> sInstance
MOZ_GUARDED_BY(sMainThreadCapability);
static Atomic<HangMonitorChild*, SequentiallyConsistent> sInstance;
const RefPtr<ProcessHangMonitor> mHangMonitor;
Monitor mMonitor;
@ -199,7 +190,11 @@ class HangMonitorChild : public PProcessHangMonitorChild,
Atomic<bool> mPaintWhileInterruptingJSActive;
};
StaticRefPtr<HangMonitorChild> HangMonitorChild::sInstance;
Maybe<Monitor> HangMonitorChild::sMonitor;
Atomic<bool, SequentiallyConsistent> HangMonitorChild::sInitializing;
Atomic<HangMonitorChild*, SequentiallyConsistent> HangMonitorChild::sInstance;
/* Parent process objects */
@ -247,12 +242,11 @@ class HangMonitoredProcess final : public nsIHangReport {
nsAutoString mDumpId;
};
class HangMonitorParent : public PProcessHangMonitorParent {
class HangMonitorParent : public PProcessHangMonitorParent,
public SupportsWeakPtr {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING_WITH_DELETE_ON_MAIN_THREAD(
HangMonitorParent, override)
explicit HangMonitorParent(ProcessHangMonitor* aMonitor);
~HangMonitorParent() override;
void Bind(Endpoint<PProcessHangMonitorParent>&& aEndpoint);
@ -286,8 +280,6 @@ class HangMonitorParent : public PProcessHangMonitorParent {
bool IsOnThread() { return mHangMonitor->IsOnThread(); }
private:
~HangMonitorParent() override;
void SendHangNotification(const SlowScriptData& aSlowScriptData,
const nsString& aBrowserDumpId);
@ -340,30 +332,25 @@ HangMonitorChild::HangMonitorChild(ProcessHangMonitor* aMonitor)
mShutdownDone(false),
mIPCOpen(true),
mPaintWhileInterruptingJSActive(false) {
ReleaseAssertIsOnMainThread();
MOZ_RELEASE_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!sInstance);
mContext = danger::GetJSContext();
BackgroundHangMonitor::RegisterAnnotator(*this);
MOZ_ASSERT(!sMonitor.isSome());
sMonitor.emplace("HangMonitorChild::sMonitor");
MonitorAutoLock mal(*sMonitor);
MOZ_ASSERT(!sInitializing);
sInitializing = true;
}
HangMonitorChild::~HangMonitorChild() {
ReleaseAssertIsOnMainThread();
MOZ_ASSERT(sInstance != this);
}
void HangMonitorChild::CreateAndBind(
ProcessHangMonitor* aMonitor,
Endpoint<PProcessHangMonitorChild>&& aEndpoint) {
ReleaseAssertIsOnMainThread();
MOZ_ASSERT(!sInstance);
sInstance = new HangMonitorChild(aMonitor);
BackgroundHangMonitor::RegisterAnnotator(*sInstance);
aMonitor->Dispatch(NewRunnableMethod<Endpoint<PProcessHangMonitorChild>&&>(
"HangMonitorChild::Bind", sInstance.get(), &HangMonitorChild::Bind,
std::move(aEndpoint)));
MOZ_RELEASE_ASSERT(NS_IsMainThread());
MOZ_ASSERT(sInstance == this);
sInstance = nullptr;
}
bool HangMonitorChild::InterruptCallback() {
@ -499,19 +486,14 @@ void HangMonitorChild::AnnotateHang(BackgroundHangAnnotations& aAnnotations) {
}
void HangMonitorChild::Shutdown() {
ReleaseAssertIsOnMainThread();
MOZ_RELEASE_ASSERT(NS_IsMainThread());
BackgroundHangMonitor::UnregisterAnnotator(*this);
{
MonitorAutoLock lock(mMonitor);
while (!mShutdownDone) {
mMonitor.Wait();
}
MonitorAutoLock lock(mMonitor);
while (!mShutdownDone) {
mMonitor.Wait();
}
MOZ_ASSERT(sInstance == this);
sInstance = nullptr;
}
void HangMonitorChild::ShutdownOnThread() {
@ -645,8 +627,16 @@ mozilla::ipc::IPCResult HangMonitorChild::RecvCancelContentJSExecutionIfRunning(
void HangMonitorChild::Bind(Endpoint<PProcessHangMonitorChild>&& aEndpoint) {
MOZ_RELEASE_ASSERT(IsOnThread());
MonitorAutoLock mal(*sMonitor);
MOZ_ASSERT(!sInstance);
sInstance = this;
DebugOnly<bool> ok = aEndpoint.Bind(this);
MOZ_ASSERT(ok);
sInitializing = false;
mal.Notify();
}
void HangMonitorChild::NotifySlowScriptAsync(TabId aTabId,
@ -1115,7 +1105,6 @@ HangMonitoredProcess::GetChildID(uint64_t* aChildID) {
}
static bool InterruptCallback(JSContext* cx) {
AssertIsOnMainThread();
if (HangMonitorChild* child = HangMonitorChild::Get()) {
return child->InterruptCallback();
}
@ -1161,11 +1150,20 @@ NS_IMPL_ISUPPORTS(ProcessHangMonitor, nsIObserver)
NS_IMETHODIMP
ProcessHangMonitor::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData) {
ReleaseAssertIsOnMainThread();
MOZ_RELEASE_ASSERT(NS_IsMainThread());
if (!strcmp(aTopic, "xpcom-shutdown")) {
if (RefPtr<HangMonitorChild> child = HangMonitorChild::Get()) {
child->Shutdown();
if (HangMonitorChild::sMonitor) {
MonitorAutoLock mal(*HangMonitorChild::sMonitor);
if (HangMonitorChild::sInitializing) {
mal.Wait();
}
if (HangMonitorChild* child = HangMonitorChild::Get()) {
child->Shutdown();
delete child;
}
}
HangMonitorChild::sMonitor.reset();
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
obs->RemoveObserver(this, "xpcom-shutdown");
@ -1176,13 +1174,13 @@ ProcessHangMonitor::Observe(nsISupports* aSubject, const char* aTopic,
ProcessHangMonitor::SlowScriptAction ProcessHangMonitor::NotifySlowScript(
nsIBrowserChild* aBrowserChild, const char* aFileName,
const nsString& aAddonId, const double aDuration) {
ReleaseAssertIsOnMainThread();
MOZ_RELEASE_ASSERT(NS_IsMainThread());
return HangMonitorChild::Get()->NotifySlowScript(aBrowserChild, aFileName,
aAddonId, aDuration);
}
bool ProcessHangMonitor::IsDebuggerStartupComplete() {
ReleaseAssertIsOnMainThread();
MOZ_RELEASE_ASSERT(NS_IsMainThread());
return HangMonitorChild::Get()->IsDebuggerStartupComplete();
}
@ -1201,13 +1199,13 @@ void ProcessHangMonitor::InitiateCPOWTimeout() {
mCPOWTimeout = true;
}
static already_AddRefed<PProcessHangMonitorParent> CreateHangMonitorParent(
static PProcessHangMonitorParent* CreateHangMonitorParent(
ContentParent* aContentParent,
Endpoint<PProcessHangMonitorParent>&& aEndpoint) {
MOZ_RELEASE_ASSERT(NS_IsMainThread());
ProcessHangMonitor* monitor = ProcessHangMonitor::GetOrCreate();
RefPtr<HangMonitorParent> parent = new HangMonitorParent(monitor);
auto* parent = new HangMonitorParent(monitor);
auto* process = new HangMonitoredProcess(parent, aContentParent);
parent->SetProcess(process);
@ -1217,18 +1215,23 @@ static already_AddRefed<PProcessHangMonitorParent> CreateHangMonitorParent(
"HangMonitorParent::Bind", parent, &HangMonitorParent::Bind,
std::move(aEndpoint)));
return parent.forget();
return parent;
}
void mozilla::CreateHangMonitorChild(
Endpoint<PProcessHangMonitorChild>&& aEndpoint) {
ReleaseAssertIsOnMainThread();
MOZ_RELEASE_ASSERT(NS_IsMainThread());
JSContext* cx = danger::GetJSContext();
JS_AddInterruptCallback(cx, InterruptCallback);
ProcessHangMonitor* monitor = ProcessHangMonitor::GetOrCreate();
HangMonitorChild::CreateAndBind(monitor, std::move(aEndpoint));
auto* child = new HangMonitorChild(monitor);
monitor->Dispatch(
NewNonOwningRunnableMethod<Endpoint<PProcessHangMonitorChild>&&>(
"HangMonitorChild::Bind", child, &HangMonitorChild::Bind,
std::move(aEndpoint)));
}
nsresult ProcessHangMonitor::Dispatch(already_AddRefed<nsIRunnable> aRunnable) {
@ -1242,7 +1245,7 @@ bool ProcessHangMonitor::IsOnThread() {
}
/* static */
already_AddRefed<PProcessHangMonitorParent> ProcessHangMonitor::AddProcess(
PProcessHangMonitorParent* ProcessHangMonitor::AddProcess(
ContentParent* aContentParent) {
MOZ_RELEASE_ASSERT(NS_IsMainThread());
@ -1272,11 +1275,12 @@ void ProcessHangMonitor::RemoveProcess(PProcessHangMonitorParent* aParent) {
MOZ_RELEASE_ASSERT(NS_IsMainThread());
auto parent = static_cast<HangMonitorParent*>(aParent);
parent->Shutdown();
delete parent;
}
/* static */
void ProcessHangMonitor::ClearHang() {
AssertIsOnMainThread();
MOZ_ASSERT(NS_IsMainThread());
if (HangMonitorChild* child = HangMonitorChild::Get()) {
child->ClearHang();
}
@ -1303,7 +1307,7 @@ void ProcessHangMonitor::UnloadLayersWhileInterruptingJS(
/* static */
void ProcessHangMonitor::ClearPaintWhileInterruptingJS(
const layers::LayersObserverEpoch& aEpoch) {
ReleaseAssertIsOnMainThread();
MOZ_RELEASE_ASSERT(NS_IsMainThread());
MOZ_RELEASE_ASSERT(XRE_IsContentProcess());
if (HangMonitorChild* child = HangMonitorChild::Get()) {
@ -1313,7 +1317,7 @@ void ProcessHangMonitor::ClearPaintWhileInterruptingJS(
/* static */
void ProcessHangMonitor::MaybeStartPaintWhileInterruptingJS() {
ReleaseAssertIsOnMainThread();
MOZ_RELEASE_ASSERT(NS_IsMainThread());
MOZ_RELEASE_ASSERT(XRE_IsContentProcess());
if (HangMonitorChild* child = HangMonitorChild::Get()) {
@ -1326,7 +1330,7 @@ void ProcessHangMonitor::CancelContentJSExecutionIfRunning(
PProcessHangMonitorParent* aParent, dom::BrowserParent* aBrowserParent,
nsIRemoteTab::NavigationType aNavigationType,
const dom::CancelContentJSOptions& aCancelContentJSOptions) {
ReleaseAssertIsOnMainThread();
MOZ_RELEASE_ASSERT(NS_IsMainThread());
auto* parent = static_cast<HangMonitorParent*>(aParent);
parent->CancelContentJSExecutionIfRunning(aBrowserParent, aNavigationType,
aCancelContentJSOptions);

View file

@ -44,7 +44,7 @@ class ProcessHangMonitor final : public nsIObserver {
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
static already_AddRefed<PProcessHangMonitorParent> AddProcess(
static PProcessHangMonitorParent* AddProcess(
dom::ContentParent* aContentParent);
static void RemoveProcess(PProcessHangMonitorParent* aParent);

View file

@ -25,9 +25,8 @@ class GMPChild : public PGMPChild {
friend class PGMPChild;
public:
NS_INLINE_DECL_REFCOUNTING(GMPChild, override)
GMPChild();
virtual ~GMPChild();
bool Init(const nsAString& aPluginPath,
mozilla::ipc::UntypedEndpoint&& aEndpoint);
@ -44,8 +43,6 @@ class GMPChild : public PGMPChild {
private:
friend class GMPContentChild;
virtual ~GMPChild();
bool GetUTF8LibPath(nsACString& aOutLibPath);
mozilla::ipc::IPCResult RecvProvideStorageId(const nsCString& aStorageId);

View file

@ -73,6 +73,7 @@ GMPParent::GMPParent()
mCanDecrypt(false),
mGMPContentChildCount(0),
mChildPid(0),
mHoldingSelfRef(false),
#ifdef ALLOW_GECKO_CHILD_PROCESS_ARCH
mChildLaunchArch(base::PROCESS_ARCH_INVALID),
#endif
@ -399,6 +400,13 @@ nsresult GMPParent::LoadProcess() {
mState = GMPStateLoaded;
// Hold a self ref while the child process is alive. This ensures that
// during shutdown the GMPParent stays alive long enough to
// terminate the child process.
MOZ_ASSERT(!mHoldingSelfRef);
mHoldingSelfRef = true;
AddRef();
return NS_OK;
}
@ -560,6 +568,11 @@ void GMPParent::DeleteProcess() {
nsCOMPtr<nsIRunnable> r =
new NotifyGMPShutdownTask(NS_ConvertUTF8toUTF16(mNodeId));
mMainThread->Dispatch(r.forget());
if (mHoldingSelfRef) {
Release();
mHoldingSelfRef = false;
}
}
GMPState GMPParent::State() const { return mState; }

View file

@ -58,7 +58,7 @@ class GMPParent final
friend class PGMPParent;
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GMPParent, final)
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GMPParent)
GMPParent();
@ -228,6 +228,12 @@ class GMPParent final
int mChildPid;
// We hold a self reference to ourself while the child process is alive.
// This ensures that if the GMPService tries to shut us down and drops
// its reference to us, we stay alive long enough for the child process
// to terminate gracefully.
bool mHoldingSelfRef;
#ifdef ALLOW_GECKO_CHILD_PROCESS_ARCH
// The child process architecture to use.
uint32_t mChildLaunchArch;

View file

@ -37,7 +37,7 @@ bool GMPProcessChild::Init(int aArgc, char* aArgv[]) {
BackgroundHangMonitor::Startup();
return mPlugin->Init(pluginFilename, TakeInitialEndpoint());
return mPlugin.Init(pluginFilename, TakeInitialEndpoint());
}
void GMPProcessChild::CleanUp() { BackgroundHangMonitor::Shutdown(); }

View file

@ -25,7 +25,7 @@ class GMPProcessChild final : public mozilla::ipc::ProcessChild {
void CleanUp() override;
private:
const RefPtr<GMPChild> mPlugin = new GMPChild;
GMPChild mPlugin;
};
} // namespace mozilla::gmp

View file

@ -17,7 +17,7 @@ using mozilla::dom::NativeThreadId from "mozilla/dom/NativeThreadId.h";
namespace mozilla {
namespace gmp {
[NeedsOtherPid, NestedUpTo=inside_sync, ChildImpl="GMPChild", ParentImpl="GMPParent"]
[ManualDealloc, NeedsOtherPid, NestedUpTo=inside_sync, ChildImpl="GMPChild", ParentImpl="GMPParent"]
sync protocol PGMP
{
manages PGMPTimer;

View file

@ -40,7 +40,7 @@ namespace mozilla {
// (RemoteDataDecoder) process. There is one instance of this protocol,
// with the RDDParent living on the main thread of the RDD process and
// the RDDChild living on the main thread of the UI process.
[NeedsOtherPid]
[ManualDealloc, NeedsOtherPid]
protocol PRDD
{
parent:

View file

@ -38,7 +38,7 @@ union RemoteDecoderInfoIPDL
VideoDecoderInfoIPDL;
};
[NeedsOtherPid]
[ManualDealloc, NeedsOtherPid]
sync protocol PRemoteDecoderManager
{
manages PRemoteDecoder;

View file

@ -34,9 +34,11 @@ namespace mozilla {
using namespace layers;
using namespace gfx;
RDDChild::RDDChild(RDDProcessHost* aHost) : mHost(aHost) {}
RDDChild::RDDChild(RDDProcessHost* aHost) : mHost(aHost) {
MOZ_COUNT_CTOR(RDDChild);
}
RDDChild::~RDDChild() = default;
RDDChild::~RDDChild() { MOZ_COUNT_DTOR(RDDChild); }
bool RDDChild::Init() {
Maybe<FileDescriptor> brokerFd;
@ -208,17 +210,17 @@ void RDDChild::ActorDestroy(ActorDestroyReason aWhy) {
class DeferredDeleteRDDChild : public Runnable {
public:
explicit DeferredDeleteRDDChild(RefPtr<RDDChild>&& aChild)
explicit DeferredDeleteRDDChild(UniquePtr<RDDChild>&& aChild)
: Runnable("gfx::DeferredDeleteRDDChild"), mChild(std::move(aChild)) {}
NS_IMETHODIMP Run() override { return NS_OK; }
private:
RefPtr<RDDChild> mChild;
UniquePtr<RDDChild> mChild;
};
/* static */
void RDDChild::Destroy(RefPtr<RDDChild>&& aChild) {
void RDDChild::Destroy(UniquePtr<RDDChild>&& aChild) {
NS_DispatchToMainThread(new DeferredDeleteRDDChild(std::move(aChild)));
}

View file

@ -30,9 +30,8 @@ class RDDChild final : public PRDDChild,
typedef mozilla::dom::MemoryReportRequestHost MemoryReportRequestHost;
public:
NS_INLINE_DECL_REFCOUNTING(RDDChild, final)
explicit RDDChild(RDDProcessHost* aHost);
~RDDChild();
bool Init();
@ -69,11 +68,9 @@ class RDDChild final : public PRDDChild,
const bool& aMinimizeMemoryUsage,
const Maybe<ipc::FileDescriptor>& aDMDFile);
static void Destroy(RefPtr<RDDChild>&& aChild);
static void Destroy(UniquePtr<RDDChild>&& aChild);
private:
~RDDChild();
RDDProcessHost* mHost;
UniquePtr<MemoryReportRequestHost> mMemoryReportRequest;
#if defined(XP_LINUX) && defined(MOZ_SANDBOX)

View file

@ -17,9 +17,8 @@ class ChildProfilerController;
class RDDParent final : public PRDDParent {
public:
NS_INLINE_DECL_REFCOUNTING(RDDParent, final)
RDDParent();
~RDDParent();
static RDDParent* GetSingleton();
@ -68,8 +67,6 @@ class RDDParent final : public PRDDParent {
mozilla::ipc::IPCResult RecvTestTelemetryProbes();
private:
~RDDParent();
const TimeStamp mLaunchTime;
RefPtr<ChildProfilerController> mProfilerController;
ipc::AsyncBlockers mShutdownBlockers;

View file

@ -168,7 +168,7 @@ void RDDProcessHost::InitAfterConnect(bool aSucceeded) {
return;
}
mProcessToken = ++sRDDProcessTokenCounter;
mRDDChild = MakeRefPtr<RDDChild>(this);
mRDDChild = MakeUnique<RDDChild>(this);
DebugOnly<bool> rv = TakeInitialEndpoint().Bind(mRDDChild.get());
MOZ_ASSERT(rv);

View file

@ -129,7 +129,7 @@ class RDDProcessHost final : public mozilla::ipc::GeckoChildProcessHost {
enum class LaunchPhase { Unlaunched, Waiting, Complete };
LaunchPhase mLaunchPhase = LaunchPhase::Unlaunched;
RefPtr<RDDChild> mRDDChild;
UniquePtr<RDDChild> mRDDChild;
uint64_t mProcessToken = 0;
UniquePtr<ipc::SharedPreferenceSerializer> mPrefSerializer;

View file

@ -43,7 +43,7 @@ bool RDDProcessImpl::Init(int aArgc, char* aArgv[]) {
return false;
}
return mRDD->Init(TakeInitialEndpoint(), *parentBuildID);
return mRDD.Init(TakeInitialEndpoint(), *parentBuildID);
}
void RDDProcessImpl::CleanUp() { NS_ShutdownXPCOM(nullptr); }

View file

@ -26,7 +26,7 @@ class RDDProcessImpl final : public ipc::ProcessChild {
void CleanUp() override;
private:
RefPtr<RDDParent> mRDD = new RDDParent;
RDDParent mRDD;
#if defined(XP_WIN)
// This object initializes and configures COM.

View file

@ -768,10 +768,15 @@ void RemoteDecoderManagerChild::OpenRemoteDecoderManagerChildForProcess(
new RemoteDecoderManagerChild(aLocation);
if (aEndpoint.Bind(manager)) {
remoteDecoderManagerChild = manager;
manager->InitIPDL();
}
}
}
void RemoteDecoderManagerChild::InitIPDL() { mIPDLSelfRef = this; }
void RemoteDecoderManagerChild::ActorDealloc() { mIPDLSelfRef = nullptr; }
bool RemoteDecoderManagerChild::DeallocShmem(mozilla::ipc::Shmem& aShmem) {
nsCOMPtr<nsISerialEventTarget> managerThread = GetManagerThread();
if (!managerThread) {

View file

@ -107,6 +107,10 @@ class RemoteDecoderManagerChild final
RemoteDecodeIn aLocation);
protected:
void InitIPDL();
void ActorDealloc() override;
void HandleFatalError(const char* aMsg) const override;
PRemoteDecoderChild* AllocPRemoteDecoderChild(
@ -136,6 +140,7 @@ class RemoteDecoderManagerChild final
// A thread-safe method to launch the RDD process if it hasn't launched yet.
static RefPtr<GenericNonExclusivePromise> LaunchRDDProcessIfNeeded();
RefPtr<RemoteDecoderManagerChild> mIPDLSelfRef;
// The location for decoding, Rdd or Gpu process.
const RemoteDecodeIn mLocation;
};

View file

@ -277,8 +277,11 @@ void RemoteDecoderManagerParent::Open(
// We can't recover from this.
MOZ_CRASH("Failed to bind RemoteDecoderManagerParent to endpoint");
}
AddRef();
}
void RemoteDecoderManagerParent::ActorDealloc() { Release(); }
mozilla::ipc::IPCResult RemoteDecoderManagerParent::RecvReadback(
const SurfaceDescriptorGPUVideo& aSD, SurfaceDescriptor* aResult) {
const SurfaceDescriptorRemoteDecoder& sd = aSD;

View file

@ -76,6 +76,7 @@ class RemoteDecoderManagerParent final
const SurfaceDescriptorGPUVideo& aSD);
void ActorDestroy(mozilla::ipc::IProtocol::ActorDestroyReason) override;
void ActorDealloc() override;
private:
explicit RemoteDecoderManagerParent(nsISerialEventTarget* aThread);

View file

@ -41,9 +41,11 @@ namespace gfx {
using namespace layers;
GPUChild::GPUChild(GPUProcessHost* aHost) : mHost(aHost), mGPUReady(false) {}
GPUChild::GPUChild(GPUProcessHost* aHost) : mHost(aHost), mGPUReady(false) {
MOZ_COUNT_CTOR(GPUChild);
}
GPUChild::~GPUChild() = default;
GPUChild::~GPUChild() { MOZ_COUNT_DTOR(GPUChild); }
void GPUChild::Init() {
nsTArray<GfxVarUpdate> updates = gfxVars::FetchNonDefaultVars();
@ -348,17 +350,17 @@ mozilla::ipc::IPCResult GPUChild::RecvFOGData(ByteBuf&& aBuf) {
class DeferredDeleteGPUChild : public Runnable {
public:
explicit DeferredDeleteGPUChild(RefPtr<GPUChild>&& aChild)
explicit DeferredDeleteGPUChild(UniquePtr<GPUChild>&& aChild)
: Runnable("gfx::DeferredDeleteGPUChild"), mChild(std::move(aChild)) {}
NS_IMETHODIMP Run() override { return NS_OK; }
private:
RefPtr<GPUChild> mChild;
UniquePtr<GPUChild> mChild;
};
/* static */
void GPUChild::Destroy(RefPtr<GPUChild>&& aChild) {
void GPUChild::Destroy(UniquePtr<GPUChild>&& aChild) {
NS_DispatchToMainThread(new DeferredDeleteGPUChild(std::move(aChild)));
}

View file

@ -27,9 +27,8 @@ class GPUChild final : public ipc::CrashReporterHelper<GeckoProcessType_GPU>,
typedef mozilla::dom::MemoryReportRequestHost MemoryReportRequestHost;
public:
NS_INLINE_DECL_REFCOUNTING(GPUChild, final)
explicit GPUChild(GPUProcessHost* aHost);
virtual ~GPUChild();
void Init();
@ -89,11 +88,9 @@ class GPUChild final : public ipc::CrashReporterHelper<GeckoProcessType_GPU>,
const bool& aMinimizeMemoryUsage,
const Maybe<ipc::FileDescriptor>& aDMDFile);
static void Destroy(RefPtr<GPUChild>&& aChild);
static void Destroy(UniquePtr<GPUChild>&& aChild);
private:
virtual ~GPUChild();
GPUProcessHost* mHost;
UniquePtr<MemoryReportRequestHost> mMemoryReportRequest;
bool mGPUReady;

View file

@ -678,15 +678,15 @@ void GPUParent::ActorDestroy(ActorDestroyReason aWhy) {
// Wait until all RemoteDecoderManagerParent have closed.
mShutdownBlockers.WaitUntilClear(10 * 1000 /* 10s timeout*/)
->Then(GetCurrentSerialEventTarget(), __func__, [self = RefPtr{this}]() {
if (self->mProfilerController) {
self->mProfilerController->Shutdown();
self->mProfilerController = nullptr;
->Then(GetCurrentSerialEventTarget(), __func__, [this]() {
if (mProfilerController) {
mProfilerController->Shutdown();
mProfilerController = nullptr;
}
if (self->mVsyncBridge) {
self->mVsyncBridge->Shutdown();
self->mVsyncBridge = nullptr;
if (mVsyncBridge) {
mVsyncBridge->Shutdown();
mVsyncBridge = nullptr;
}
VideoBridgeParent::Shutdown();
// This could be running on either the Compositor or the Renderer

View file

@ -21,9 +21,8 @@ class VsyncBridgeParent;
class GPUParent final : public PGPUParent {
public:
NS_INLINE_DECL_REFCOUNTING(GPUParent, final)
GPUParent();
~GPUParent();
static GPUParent* GetSingleton();
@ -112,8 +111,6 @@ class GPUParent final : public PGPUParent {
void ActorDestroy(ActorDestroyReason aWhy) override;
private:
~GPUParent();
const TimeStamp mLaunchTime;
RefPtr<VsyncBridgeParent> mVsyncBridge;
RefPtr<ChildProfilerController> mProfilerController;

View file

@ -143,7 +143,7 @@ void GPUProcessHost::InitAfterConnect(bool aSucceeded) {
if (aSucceeded) {
mProcessToken = ++sProcessTokenCounter;
mGPUChild = MakeRefPtr<GPUChild>(this);
mGPUChild = MakeUnique<GPUChild>(this);
DebugOnly<bool> rv = TakeInitialEndpoint().Bind(mGPUChild.get());
MOZ_ASSERT(rv);

View file

@ -141,7 +141,7 @@ class GPUProcessHost final : public mozilla::ipc::GeckoChildProcessHost {
enum class LaunchPhase { Unlaunched, Waiting, Complete };
LaunchPhase mLaunchPhase;
RefPtr<GPUChild> mGPUChild;
UniquePtr<GPUChild> mGPUChild;
uint64_t mProcessToken;
UniquePtr<mozilla::ipc::SharedPreferenceSerializer> mPrefSerializer;

View file

@ -39,7 +39,7 @@ bool GPUProcessImpl::Init(int aArgc, char* aArgv[]) {
return false;
}
return mGPU->Init(TakeInitialEndpoint(), *parentBuildID);
return mGPU.Init(TakeInitialEndpoint(), *parentBuildID);
}
void GPUProcessImpl::CleanUp() { NS_ShutdownXPCOM(nullptr); }

View file

@ -27,7 +27,7 @@ class GPUProcessImpl final : public ipc::ProcessChild {
void CleanUp() override;
private:
RefPtr<GPUParent> mGPU = new GPUParent;
GPUParent mGPU;
#if defined(XP_WIN)
// This object initializes and configures COM.

View file

@ -52,7 +52,7 @@ struct LayerTreeIdMapping {
// This protocol allows the UI process to talk to the GPU process. There is one
// instance of this protocol, with the GPUParent living on the main thread of
// the GPU process and the GPUChild living on the main thread of the UI process.
[NeedsOtherPid]
[ManualDealloc, NeedsOtherPid]
sync protocol PGPU
{
parent:

View file

@ -16,7 +16,7 @@ namespace gfx {
// dedicated thread in the UI process to the compositor thread in the
// compositor process. The child side exists in the UI process, and the
// parent side in the GPU process.
[NeedsOtherPid]
[ManualDealloc, NeedsOtherPid]
sync protocol PVsyncBridge
{
parent:

View file

@ -40,6 +40,9 @@ void VsyncBridgeChild::Open(Endpoint<PVsyncBridgeChild>&& aEndpoint) {
gpm->NotifyRemoteActorDestroyed(mProcessToken);
return;
}
// Last reference is freed in DeallocPVsyncBridgeChild.
AddRef();
}
class NotifyVsyncTask : public Runnable {
@ -114,6 +117,8 @@ void VsyncBridgeChild::ActorDestroy(ActorDestroyReason aWhy) {
}
}
void VsyncBridgeChild::ActorDealloc() { Release(); }
void VsyncBridgeChild::ProcessingError(Result aCode, const char* aReason) {
MOZ_RELEASE_ASSERT(aCode == MsgDropped,
"Processing error in VsyncBridgeChild");

View file

@ -18,7 +18,7 @@ class VsyncBridgeChild final : public PVsyncBridgeChild {
friend class NotifyVsyncTask;
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VsyncBridgeChild, final)
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VsyncBridgeChild)
static RefPtr<VsyncBridgeChild> Create(
RefPtr<VsyncIOThreadHolder> aThread, const uint64_t& aProcessToken,
@ -27,6 +27,7 @@ class VsyncBridgeChild final : public PVsyncBridgeChild {
void Close();
void ActorDestroy(ActorDestroyReason aWhy) override;
void ActorDealloc() override;
void ProcessingError(Result aCode, const char* aReason) override;
void NotifyVsync(const VsyncEvent& aVsync, const layers::LayersId& aLayersId);

View file

@ -38,6 +38,7 @@ void VsyncBridgeParent::Open(Endpoint<PVsyncBridgeParent>&& aEndpoint) {
// We can't recover from this.
MOZ_CRASH("Failed to bind VsyncBridgeParent to endpoint");
}
AddRef();
mOpen = true;
}
@ -70,5 +71,7 @@ void VsyncBridgeParent::ActorDestroy(ActorDestroyReason aWhy) {
mCompositorThreadRef = nullptr;
}
void VsyncBridgeParent::ActorDealloc() { Release(); }
} // namespace gfx
} // namespace mozilla

View file

@ -18,7 +18,7 @@ namespace gfx {
class VsyncBridgeParent final : public PVsyncBridgeParent {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VsyncBridgeParent, final)
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VsyncBridgeParent)
static RefPtr<VsyncBridgeParent> Start(
Endpoint<PVsyncBridgeParent>&& aEndpoint);
@ -26,6 +26,7 @@ class VsyncBridgeParent final : public PVsyncBridgeParent {
mozilla::ipc::IPCResult RecvNotifyVsync(const VsyncEvent& aVsync,
const LayersId& aLayersId);
void ActorDestroy(ActorDestroyReason aWhy) override;
void ActorDealloc() override;
void Shutdown();

View file

@ -185,6 +185,7 @@ CompositorManagerChild::CompositorManagerChild(CompositorManagerParent* aParent,
}
mCanSend = true;
AddRef();
SetReplyTimeout();
}
@ -201,9 +202,15 @@ CompositorManagerChild::CompositorManagerChild(
}
mCanSend = true;
AddRef();
SetReplyTimeout();
}
void CompositorManagerChild::ActorDealloc() {
MOZ_ASSERT(!mCanSend);
Release();
}
void CompositorManagerChild::ActorDestroy(ActorDestroyReason aReason) {
mCanSend = false;
if (sInstance == this) {

View file

@ -23,7 +23,7 @@ class CompositorManagerParent;
class WebRenderLayerManager;
class CompositorManagerChild : public PCompositorManagerChild {
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CompositorManagerChild, override)
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CompositorManagerChild)
public:
static bool IsInitialized(uint64_t aProcessToken);
@ -104,6 +104,8 @@ class CompositorManagerChild : public PCompositorManagerChild {
virtual ~CompositorManagerChild() = default;
void ActorDealloc() override;
void SetReplyTimeout();
uint64_t mProcessToken;

View file

@ -134,6 +134,10 @@ void CompositorManagerParent::BindComplete(bool aIsRoot) {
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread() ||
NS_IsMainThread());
// Add the IPDL reference to ourself, so we can't get freed until IPDL is
// done with us.
AddRef();
StaticMutexAutoLock lock(sMutex);
if (aIsRoot) {
sInstance = this;
@ -150,20 +154,24 @@ void CompositorManagerParent::BindComplete(bool aIsRoot) {
void CompositorManagerParent::ActorDestroy(ActorDestroyReason aReason) {
SharedSurfacesParent::DestroyProcess(OtherPid());
GetCurrentSerialEventTarget()->Dispatch(
NewRunnableMethod("layers::CompositorManagerParent::DeferredDestroy",
this, &CompositorManagerParent::DeferredDestroy));
StaticMutexAutoLock lock(sMutex);
if (sInstance == this) {
sInstance = nullptr;
}
}
void CompositorManagerParent::ActorDealloc() {
GetCurrentSerialEventTarget()->Dispatch(
NewRunnableMethod("layers::CompositorManagerParent::DeferredDestroy",
this, &CompositorManagerParent::DeferredDestroy));
#ifdef COMPOSITOR_MANAGER_PARENT_EXPLICIT_SHUTDOWN
StaticMutexAutoLock lock(sMutex);
if (sActiveActors) {
sActiveActors->RemoveElement(this);
}
#endif
Release();
}
void CompositorManagerParent::DeferredDestroy() {

View file

@ -26,7 +26,7 @@ class CompositorThreadHolder;
#endif
class CompositorManagerParent final : public PCompositorManagerParent {
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CompositorManagerParent, final)
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CompositorManagerParent)
public:
static already_AddRefed<CompositorManagerParent> CreateSameProcess();
@ -77,6 +77,8 @@ class CompositorManagerParent final : public PCompositorManagerParent {
void Bind(Endpoint<PCompositorManagerParent>&& aEndpoint, bool aIsRoot);
void ActorDealloc() override;
void DeferredDestroy();
RefPtr<CompositorThreadHolder> mCompositorThreadHolder;

View file

@ -234,6 +234,8 @@ void ImageBridgeChild::ActorDestroy(ActorDestroyReason aWhy) {
}
}
void ImageBridgeChild::ActorDealloc() { this->Release(); }
void ImageBridgeChild::CreateImageClientSync(SynchronousTask* aTask,
RefPtr<ImageClient>* result,
CompositableType aType,
@ -483,12 +485,18 @@ void ImageBridgeChild::Bind(Endpoint<PImageBridgeChild>&& aEndpoint) {
return;
}
// This reference is dropped in DeallocPImageBridgeChild.
this->AddRef();
mCanSend = true;
}
void ImageBridgeChild::BindSameProcess(RefPtr<ImageBridgeParent> aParent) {
Open(aParent, aParent->GetThread(), mozilla::ipc::ChildSide);
// This reference is dropped in DeallocPImageBridgeChild.
this->AddRef();
mCanSend = true;
}

View file

@ -331,6 +331,7 @@ class ImageBridgeChild final : public PImageBridgeChild,
void MarkShutDown();
void ActorDestroy(ActorDestroyReason aWhy) override;
void ActorDealloc() override;
bool CanSend() const;
bool CanPostTask() const;

View file

@ -77,6 +77,7 @@ ImageBridgeParent* ImageBridgeParent::CreateSameProcess() {
base::ProcessId pid = base::GetCurrentProcId();
RefPtr<ImageBridgeParent> parent =
new ImageBridgeParent(CompositorThread(), pid);
parent->mSelfRef = parent;
{
MonitorAutoLock lock(*sImageBridgesLock);
@ -154,11 +155,10 @@ void ImageBridgeParent::ActorDestroy(ActorDestroyReason aWhy) {
// It is very important that this method gets called at shutdown (be it a
// clean or an abnormal shutdown), because DeferredDestroy is what clears
// mCompositorThreadHolder. If mCompositorThreadHolder is not null and
// ActorDestroy is not called, the ImageBridgeParent is leaked which causes
// the CompositorThreadHolder to be leaked and CompsoitorParent's shutdown
// ends up spinning the event loop forever, waiting for the compositor thread
// to terminate.
// mSelfRef. If mSelfRef is not null and ActorDestroy is not called, the
// ImageBridgeParent is leaked which causes the CompositorThreadHolder to be
// leaked and CompsoitorParent's shutdown ends up spinning the event loop
// forever, waiting for the compositor thread to terminate.
}
class MOZ_STACK_CLASS AutoImageBridgeParentAsyncMessageSender final {
@ -232,6 +232,7 @@ bool ImageBridgeParent::CreateForContent(
void ImageBridgeParent::Bind(Endpoint<PImageBridgeParent>&& aEndpoint) {
if (!aEndpoint.Bind(this)) return;
mSelfRef = this;
// If the child process ID was reused by the OS before the ImageBridgeParent
// object was destroyed, we need to clean it up first.
@ -362,7 +363,10 @@ bool ImageBridgeParent::NotifyImageComposites(
return ok;
}
void ImageBridgeParent::DeferredDestroy() { mCompositorThreadHolder = nullptr; }
void ImageBridgeParent::DeferredDestroy() {
mCompositorThreadHolder = nullptr;
mSelfRef = nullptr; // "this" ImageBridge may get deleted here.
}
already_AddRefed<ImageBridgeParent> ImageBridgeParent::GetInstance(
ProcessId aId) {

View file

@ -42,8 +42,7 @@ class ImageBridgeParent final : public PImageBridgeParent,
ImageBridgeParent(nsISerialEventTarget* aThread, ProcessId aChildProcessId);
public:
NS_INLINE_DECL_REFCOUNTING_INHERITED(ImageBridgeParent,
CompositableParentManager)
virtual ~ImageBridgeParent();
/**
* Creates the globals of ImageBridgeParent.
@ -117,12 +116,13 @@ class ImageBridgeParent final : public PImageBridgeParent,
void Bind(Endpoint<PImageBridgeParent>&& aEndpoint);
private:
virtual ~ImageBridgeParent();
static void ShutdownInternal();
void DeferredDestroy();
nsCOMPtr<nsISerialEventTarget> mThread;
// This keeps us alive until ActorDestroy(), at which point we do a
// deferred destruction of ourselves.
RefPtr<ImageBridgeParent> mSelfRef;
bool mClosed;

View file

@ -60,7 +60,7 @@ union CompositorBridgeOptions {
* compositor thread for compositor data that is only shared once, rather than
* per PCompositorBridge instance.
*/
[NeedsOtherPid]
[ManualDealloc, NeedsOtherPid]
sync protocol PCompositorManager
{
manages PCompositorBridge;

View file

@ -26,7 +26,7 @@ namespace layers {
* frames directly to the compositor thread/process without relying on the main thread
* which might be too busy dealing with content script.
*/
[NeedsOtherPid]
[ManualDealloc, NeedsOtherPid]
sync protocol PImageBridge
{
manages PTexture;

View file

@ -20,7 +20,7 @@ namespace layers {
* compositor from the UI thread. Primarily used on Android to coordinate registering and
* releasing the surface with the compositor.
*/
[NeedsOtherPid]
[ManualDealloc, NeedsOtherPid]
sync protocol PUiCompositorController
{

View file

@ -19,7 +19,7 @@ namespace layers {
* The PVideoBridge protocol is used to share textures from the video decoders
* to the compositor.
*/
[NeedsOtherPid]
[ManualDealloc, NeedsOtherPid]
sync protocol PVideoBridge
{
manages PTexture;

View file

@ -200,6 +200,13 @@ void UiCompositorControllerChild::ActorDestroy(ActorDestroyReason aWhy) {
}
}
void UiCompositorControllerChild::ActorDealloc() {
if (mParent) {
mParent = nullptr;
}
Release();
}
void UiCompositorControllerChild::ProcessingError(Result aCode,
const char* aReason) {
if (aCode != MsgDropped) {
@ -265,6 +272,7 @@ void UiCompositorControllerChild::OpenForSameProcess() {
}
mParent->InitializeForSameProcess();
AddRef();
SendCachedValues();
// Let Ui thread know the connection is open;
RecvToolbarAnimatorMessageFromCompositor(COMPOSITOR_CONTROLLER_OPEN);
@ -285,6 +293,7 @@ void UiCompositorControllerChild::OpenForGPUProcess(
return;
}
AddRef();
SendCachedValues();
// Let Ui thread know the connection is open;
RecvToolbarAnimatorMessageFromCompositor(COMPOSITOR_CONTROLLER_OPEN);

View file

@ -29,7 +29,7 @@ class UiCompositorControllerChild final
friend class PUiCompositorControllerChild;
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(UiCompositorControllerChild, final)
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(UiCompositorControllerChild)
static RefPtr<UiCompositorControllerChild> CreateForSameProcess(
const LayersId& aRootLayerTreeId, nsBaseWidget* aWidget);
@ -76,6 +76,7 @@ class UiCompositorControllerChild final
protected:
void ActorDestroy(ActorDestroyReason aWhy) override;
void ActorDealloc() override;
void ProcessingError(Result aCode, const char* aReason) override;
void HandleFatalError(const char* aMsg) const override;
mozilla::ipc::IPCResult RecvToolbarAnimatorMessageFromCompositor(

View file

@ -163,9 +163,12 @@ UiCompositorControllerParent::RecvEnableLayerUpdateNotifications(
return IPC_OK();
}
void UiCompositorControllerParent::ActorDestroy(ActorDestroyReason aWhy) {
void UiCompositorControllerParent::ActorDestroy(ActorDestroyReason aWhy) {}
void UiCompositorControllerParent::ActorDealloc() {
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
Shutdown();
Release(); // For AddRef in Initialize()
}
void UiCompositorControllerParent::ToolbarAnimatorMessageFromCompositor(
@ -260,6 +263,7 @@ void UiCompositorControllerParent::InitializeForOutOfProcess() {
void UiCompositorControllerParent::Initialize() {
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
AddRef();
LayerTreeState* state =
CompositorBridgeParent::GetIndirectShadowTree(mRootLayerTreeId);
MOZ_ASSERT(state);

View file

@ -23,7 +23,7 @@ class UiCompositorControllerParent final
friend class UiCompositorControllerChild;
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(UiCompositorControllerParent, final)
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(UiCompositorControllerParent)
static RefPtr<UiCompositorControllerParent> GetFromRootLayerTreeId(
const LayersId& aRootLayerTreeId);
@ -46,6 +46,7 @@ class UiCompositorControllerParent final
mozilla::ipc::IPCResult RecvEnableLayerUpdateNotifications(
const bool& aEnable);
void ActorDestroy(ActorDestroyReason aWhy) override;
void ActorDealloc() override;
// Class specific functions
void ToolbarAnimatorMessageFromCompositor(int32_t aMessage);

View file

@ -49,7 +49,9 @@ void VideoBridgeChild::Shutdown() {
}
VideoBridgeChild::VideoBridgeChild()
: mThread(GetCurrentSerialEventTarget()), mCanSend(true) {}
: mIPDLSelfRef(this),
mThread(GetCurrentSerialEventTarget()),
mCanSend(true) {}
VideoBridgeChild::~VideoBridgeChild() = default;
@ -153,6 +155,8 @@ void VideoBridgeChild::ActorDestroy(ActorDestroyReason aWhy) {
mCanSend = false;
}
void VideoBridgeChild::ActorDealloc() { mIPDLSelfRef = nullptr; }
PTextureChild* VideoBridgeChild::CreateTexture(
const SurfaceDescriptor& aSharedData, ReadLockDescriptor&& aReadLock,
LayersBackend aLayersBackend, TextureFlags aFlags, uint64_t aSerial,

View file

@ -36,6 +36,7 @@ class VideoBridgeChild final : public PVideoBridgeChild,
bool DeallocPTextureChild(PTextureChild* actor);
void ActorDestroy(ActorDestroyReason aWhy) override;
void ActorDealloc() override;
// ISurfaceAllocator
bool AllocUnsafeShmem(size_t aSize, mozilla::ipc::Shmem* aShmem) override;
@ -76,6 +77,7 @@ class VideoBridgeChild final : public PVideoBridgeChild,
VideoBridgeChild();
virtual ~VideoBridgeChild();
RefPtr<VideoBridgeChild> mIPDLSelfRef;
nsCOMPtr<nsISerialEventTarget> mThread;
bool mCanSend;
};

View file

@ -29,6 +29,7 @@ static Atomic<bool> sVideoBridgeParentShutDown(false);
VideoBridgeParent::VideoBridgeParent(VideoBridgeSource aSource)
: mCompositorThreadHolder(CompositorThreadHolder::GetSingleton()),
mClosed(false) {
mSelfRef = this;
auto videoBridgeFromProcess = sVideoBridgeFromProcess.Lock();
switch (aSource) {
case VideoBridgeSource::RddProcess:
@ -99,9 +100,6 @@ void VideoBridgeParent::ActorDestroy(ActorDestroyReason aWhy) {
}
// Can't alloc/dealloc shmems from now on.
mClosed = true;
mCompositorThreadHolder = nullptr;
ReleaseCompositorThread();
}
/* static */
@ -143,6 +141,12 @@ void VideoBridgeParent::ReleaseCompositorThread() {
mCompositorThreadHolder = nullptr;
}
void VideoBridgeParent::ActorDealloc() {
mCompositorThreadHolder = nullptr;
ReleaseCompositorThread();
mSelfRef = nullptr;
}
PTextureParent* VideoBridgeParent::AllocPTextureParent(
const SurfaceDescriptor& aSharedData, ReadLockDescriptor& aReadLock,
const LayersBackend& aLayersBackend, const TextureFlags& aFlags,

View file

@ -20,7 +20,7 @@ class VideoBridgeParent final : public PVideoBridgeParent,
public HostIPCAllocator,
public mozilla::ipc::IShmemAllocator {
public:
NS_INLINE_DECL_REFCOUNTING_INHERITED(VideoBridgeParent, HostIPCAllocator)
~VideoBridgeParent();
static VideoBridgeParent* GetSingleton(
const Maybe<VideoBridgeSource>& aSource);
@ -63,14 +63,16 @@ class VideoBridgeParent final : public PVideoBridgeParent,
void OnChannelError() override;
private:
~VideoBridgeParent();
explicit VideoBridgeParent(VideoBridgeSource aSource);
void Bind(Endpoint<PVideoBridgeParent>&& aEndpoint);
void ActorDealloc() override;
void ReleaseCompositorThread();
void DoUnregisterExternalImages();
// This keeps us alive until ActorDestroy(), at which point we do a
// deferred destruction of ourselves.
RefPtr<VideoBridgeParent> mSelfRef;
RefPtr<CompositorThreadHolder> mCompositorThreadHolder;
std::map<uint64_t, PTextureParent*> mTextureMap;

View file

@ -18,7 +18,7 @@ include protocol PVRGPU;
namespace mozilla {
namespace gfx {
[NeedsOtherPid, ChildImpl="VRChild", ParentImpl="VRParent"]
[ManualDealloc, NeedsOtherPid, ChildImpl="VRChild", ParentImpl="VRParent"]
async protocol PVR
{
parent:

View file

@ -11,7 +11,7 @@ namespace gfx {
// The parent process is the VR process.
// The child process is the GPU process.
[NeedsOtherPid, ChildImpl="VRGPUChild", ParentImpl="VRGPUParent"]
[ManualDealloc, NeedsOtherPid, ChildImpl="VRGPUChild", ParentImpl="VRGPUParent"]
async protocol PVRGPU
{
parent:

View file

@ -34,7 +34,7 @@ namespace gfx {
* enumeration and sensor state between the compositor thread and
* content threads/processes.
*/
[NeedsOtherPid, ChildImpl="VRManagerChild", ParentImpl="VRManagerParent"]
[ManualDealloc, NeedsOtherPid, ChildImpl="VRManagerChild", ParentImpl="VRManagerParent"]
sync protocol PVRManager
{
manages PVRLayer;

View file

@ -74,8 +74,6 @@ VRChild::VRChild(VRProcessParent* aHost) : mHost(aHost), mVRReady(false) {
MOZ_ASSERT(XRE_IsParentProcess());
}
VRChild::~VRChild() = default;
mozilla::ipc::IPCResult VRChild::RecvAddMemoryReport(
const MemoryReport& aReport) {
if (mMemoryReportRequest) {
@ -196,17 +194,17 @@ void VRChild::OnVarChanged(const GfxVarUpdate& aVar) { SendUpdateVar(aVar); }
class DeferredDeleteVRChild : public Runnable {
public:
explicit DeferredDeleteVRChild(RefPtr<VRChild>&& aChild)
explicit DeferredDeleteVRChild(UniquePtr<VRChild>&& aChild)
: Runnable("gfx::DeferredDeleteVRChild"), mChild(std::move(aChild)) {}
NS_IMETHODIMP Run() override { return NS_OK; }
private:
RefPtr<VRChild> mChild;
UniquePtr<VRChild> mChild;
};
/* static */
void VRChild::Destroy(RefPtr<VRChild>&& aChild) {
void VRChild::Destroy(UniquePtr<VRChild>&& aChild) {
NS_DispatchToMainThread(new DeferredDeleteVRChild(std::move(aChild)));
}

View file

@ -29,11 +29,10 @@ class VRChild final : public PVRChild,
friend class PVRChild;
public:
NS_INLINE_DECL_REFCOUNTING(VRChild, final)
explicit VRChild(VRProcessParent* aHost);
~VRChild() = default;
static void Destroy(RefPtr<VRChild>&& aChild);
static void Destroy(UniquePtr<VRChild>&& aChild);
void Init();
bool EnsureVRReady();
virtual void OnVarChanged(const GfxVarUpdate& aVar) override;
@ -53,8 +52,6 @@ class VRChild final : public PVRChild,
mozilla::ipc::IPCResult RecvAddMemoryReport(const MemoryReport& aReport);
private:
~VRChild();
VRProcessParent* mHost;
UniquePtr<MemoryReportRequestHost> mMemoryReportRequest;
bool mVRReady;

View file

@ -14,7 +14,7 @@ namespace gfx {
class VRGPUChild final : public PVRGPUChild {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRGPUChild, final);
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRGPUChild);
static VRGPUChild* Get();
static bool InitForGPUProcess(Endpoint<PVRGPUChild>&& aEndpoint);

View file

@ -17,12 +17,13 @@ namespace gfx {
using namespace ipc;
VRGPUParent::VRGPUParent(ProcessId aChildProcessId) : mClosed(false) {
MOZ_COUNT_CTOR(VRGPUParent);
MOZ_ASSERT(NS_IsMainThread());
SetOtherProcessId(aChildProcessId);
}
VRGPUParent::~VRGPUParent() = default;
VRGPUParent::~VRGPUParent() { MOZ_COUNT_DTOR(VRGPUParent); }
void VRGPUParent::ActorDestroy(ActorDestroyReason aWhy) {
#if !defined(MOZ_WIDGET_ANDROID)
@ -33,8 +34,13 @@ void VRGPUParent::ActorDestroy(ActorDestroyReason aWhy) {
#endif
mClosed = true;
GetCurrentSerialEventTarget()->Dispatch(
NewRunnableMethod("gfx::VRGPUParent::DeferredDestroy", this,
&VRGPUParent::DeferredDestroy));
}
void VRGPUParent::DeferredDestroy() { mSelfRef = nullptr; }
/* static */
RefPtr<VRGPUParent> VRGPUParent::CreateForGPU(
Endpoint<PVRGPUParent>&& aEndpoint) {
@ -55,6 +61,8 @@ void VRGPUParent::Bind(Endpoint<PVRGPUParent>&& aEndpoint) {
if (!aEndpoint.Bind(this)) {
return;
}
mSelfRef = this;
}
mozilla::ipc::IPCResult VRGPUParent::RecvStartVRService() {

View file

@ -14,7 +14,7 @@ namespace mozilla {
namespace gfx {
class VRGPUParent final : public PVRGPUParent {
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRGPUParent, final)
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRGPUParent)
friend class PVRGPUParent;
@ -37,6 +37,7 @@ class VRGPUParent final : public PVRGPUParent {
void DeferredDestroy();
RefPtr<VRGPUParent> mSelfRef;
#if !defined(MOZ_WIDGET_ANDROID)
RefPtr<VRService> mVRService;
#endif

View file

@ -53,6 +53,7 @@ VRManagerChild::VRManagerChild()
MOZ_ASSERT(NS_IsMainThread());
mStartTimeStamp = TimeStamp::Now();
AddRef();
}
VRManagerChild::~VRManagerChild() { MOZ_ASSERT(NS_IsMainThread()); }
@ -148,6 +149,8 @@ void VRManagerChild::ShutDown() {
sVRManagerChildSingleton = nullptr;
}
void VRManagerChild::ActorDealloc() { Release(); }
void VRManagerChild::ActorDestroy(ActorDestroyReason aReason) {
if (sVRManagerChildSingleton == this) {
sVRManagerChildSingleton = nullptr;

View file

@ -50,7 +50,7 @@ class VRManagerChild : public PVRManagerChild {
friend class PVRManagerChild;
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRManagerChild, override);
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRManagerChild);
static VRManagerChild* Get();
@ -117,6 +117,8 @@ class VRManagerChild : public PVRManagerChild {
const uint32_t& aGroup);
bool DeallocPVRLayerChild(PVRLayerChild* actor);
void ActorDealloc() override;
// MOZ_CAN_RUN_SCRIPT_BOUNDARY until we can mark ipdl-generated things as
// MOZ_CAN_RUN_SCRIPT.
MOZ_CAN_RUN_SCRIPT_BOUNDARY

View file

@ -96,7 +96,7 @@ void VRManagerParent::Bind(Endpoint<PVRManagerParent>&& aEndpoint) {
if (!aEndpoint.Bind(this)) {
return;
}
mCompositorThreadHolder = CompositorThreadHolder::GetSingleton();
mSelfRef = this;
RegisterWithManager();
}
@ -108,14 +108,15 @@ void VRManagerParent::RegisterVRManagerInCompositorThread(
}
/*static*/
already_AddRefed<VRManagerParent> VRManagerParent::CreateSameProcess() {
VRManagerParent* VRManagerParent::CreateSameProcess() {
RefPtr<VRManagerParent> vmp =
new VRManagerParent(base::GetCurrentProcId(), false);
vmp->mCompositorThreadHolder = CompositorThreadHolder::GetSingleton();
vmp->mSelfRef = vmp;
CompositorThread()->Dispatch(
NewRunnableFunction("RegisterVRManagerIncompositorThreadRunnable",
RegisterVRManagerInCompositorThread, vmp.get()));
return vmp.forget();
return vmp.get();
}
bool VRManagerParent::CreateForGPUProcess(
@ -123,6 +124,7 @@ bool VRManagerParent::CreateForGPUProcess(
RefPtr<VRManagerParent> vmp =
new VRManagerParent(aEndpoint.OtherPid(), false);
vmp->mCompositorThreadHolder = CompositorThreadHolder::GetSingleton();
vmp->mSelfRef = vmp;
CompositorThread()->Dispatch(NewRunnableMethod<Endpoint<PVRManagerParent>&&>(
"gfx::VRManagerParent::Bind", vmp, &VRManagerParent::Bind,
std::move(aEndpoint)));
@ -146,9 +148,20 @@ void VRManagerParent::Shutdown() {
}));
}
void VRManagerParent::ActorDestroy(ActorDestroyReason why) {
void VRManagerParent::ActorDestroy(ActorDestroyReason why) {}
void VRManagerParent::ActorAlloc() {
// FIXME: This actor should probably use proper refcounting instead of manual
// reference management, and probably shouldn't manage
// `mCompositorThreadHolder` in the alloc/dealloc methods.
PVRManagerParent::ActorAlloc();
mCompositorThreadHolder = CompositorThreadHolder::GetSingleton();
}
void VRManagerParent::ActorDealloc() {
UnregisterFromManager();
mCompositorThreadHolder = nullptr;
mSelfRef = nullptr;
}
mozilla::ipc::IPCResult VRManagerParent::RecvDetectRuntimes() {

View file

@ -22,14 +22,14 @@ namespace gfx {
class VRManager;
class VRManagerParent final : public PVRManagerParent {
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRManagerParent, final);
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRManagerParent);
friend class PVRManagerParent;
public:
explicit VRManagerParent(ProcessId aChildProcessId, bool aIsContentChild);
static already_AddRefed<VRManagerParent> CreateSameProcess();
static VRManagerParent* CreateSameProcess();
static bool CreateForGPUProcess(Endpoint<PVRManagerParent>&& aEndpoint);
static bool CreateForContent(Endpoint<PVRManagerParent>&& aEndpoint);
static void Shutdown();
@ -73,6 +73,8 @@ class VRManagerParent final : public PVRManagerParent {
mozilla::ipc::IPCResult RecvResetPuppet();
private:
void ActorAlloc() override;
void ActorDealloc() override;
void RegisterWithManager();
void UnregisterFromManager();
@ -80,6 +82,9 @@ class VRManagerParent final : public PVRManagerParent {
static void RegisterVRManagerInCompositorThread(VRManagerParent* aVRManager);
// This keeps us alive until ActorDestroy(), at which point we do a
// deferred destruction of ourselves.
RefPtr<VRManagerParent> mSelfRef;
// Keep the compositor thread alive, until we have destroyed ourselves.
RefPtr<CompositorThreadHolder> mCompositorThreadHolder;

View file

@ -17,7 +17,7 @@ class VRService;
class VRSystemManagerExternal;
class VRParent final : public PVRParent {
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRParent, final);
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRParent);
friend class PVRParent;

View file

@ -39,9 +39,11 @@ VRProcessParent::VRProcessParent(Listener* aListener)
mListener(aListener),
mLaunchPhase(LaunchPhase::Unlaunched),
mChannelClosed(false),
mShutdownRequested(false) {}
mShutdownRequested(false) {
MOZ_COUNT_CTOR(VRProcessParent);
}
VRProcessParent::~VRProcessParent() = default;
VRProcessParent::~VRProcessParent() { MOZ_COUNT_DTOR(VRProcessParent); }
bool VRProcessParent::Launch() {
MOZ_ASSERT(mLaunchPhase == LaunchPhase::Unlaunched);
@ -159,7 +161,7 @@ bool VRProcessParent::InitAfterConnect(bool aSucceeded) {
return false;
}
mVRChild = MakeRefPtr<VRChild>(this);
mVRChild = MakeUnique<VRChild>(this);
DebugOnly<bool> rv = TakeInitialEndpoint().Bind(mVRChild.get());
MOZ_ASSERT(rv);

View file

@ -69,7 +69,7 @@ class VRProcessParent final : public mozilla::ipc::GeckoChildProcessHost {
bool InitAfterConnect(bool aSucceeded);
void KillHard(const char* aReason);
RefPtr<VRChild> mVRChild;
UniquePtr<VRChild> mVRChild;
mozilla::ipc::TaskFactory<VRProcessParent> mTaskFactory;
nsCOMPtr<nsIThread> mLaunchThread;
Listener* mListener;

View file

@ -385,9 +385,6 @@ class IToplevelProtocol : public IProtocol {
~IToplevelProtocol() = default;
public:
// All top-level protocols are refcounted.
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
// Shadow methods on IProtocol which are implemented directly on toplevel
// actors.
int32_t Register(IProtocol* aRouted);

View file

@ -3838,12 +3838,11 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
self.cls.addstmts([dtor, Whitespace.NL])
if ptype.isRefcounted():
if not ptype.isToplevel():
self.cls.addcode(
"""
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
"""
)
self.cls.addcode(
"""
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
"""
)
self.cls.addstmt(Label.PROTECTED)
self.cls.addcode(
"""

View file

@ -1278,9 +1278,6 @@ class GatherDecls(TcheckVisitor):
if not p.decl.type.isToplevel() and p.decl.type.needsotherpid:
self.error(p.loc, "[NeedsOtherPid] only applies to toplevel protocols")
if p.decl.type.isToplevel() and not p.decl.type.isRefcounted():
self.error(p.loc, "Toplevel protocols cannot be [ManualDealloc]")
# FIXME/cjones declare all the little C++ thingies that will
# be generated. they're not relevant to IPDL itself, but
# those ("invisible") symbols can clash with others in the

View file

@ -1,6 +0,0 @@
//error: Toplevel protocols cannot be [ManualDealloc]
[ManualDealloc] async protocol PToplevelManualDealloc {
child:
async __delete__();
};

View file

@ -1,4 +1,4 @@
[NestedUpTo=inside_sync, NeedsOtherPid] async protocol PExtendedAttrMultipleAttributes {
[NestedUpTo=inside_sync, ManualDealloc] async protocol PExtendedAttrMultipleAttributes {
parent:
async Msg();
};

View file

@ -1,8 +1,4 @@
include protocol PManualDealloc_manager;
[ManualDealloc] async protocol PManualDealloc {
manager PManualDealloc_manager;
child:
async __delete__();
};

View file

@ -1,7 +0,0 @@
include protocol PManualDealloc;
// [ManualDealloc] types must have a manager, as all toplevel protocols are
// refcounted.
async protocol PManualDealloc_manager {
manages PManualDealloc;
};

View file

@ -7,6 +7,7 @@
namespace mozilla {
namespace net {
[ManualDealloc]
sync protocol PProxyAutoConfig
{
child:

View file

@ -88,7 +88,7 @@ struct SocketPorcessInitAttributes {
FileDescriptor? mSandboxBroker;
};
[NeedsOtherPid]
[ManualDealloc, NeedsOtherPid]
sync protocol PSocketProcess
{
manages PDNSRequest;

View file

@ -17,7 +17,7 @@ namespace net {
* content process and PSocketProcessBridgeParent lives in
* socket process.
*/
[NeedsOtherPid]
[ManualDealloc, NeedsOtherPid]
sync protocol PSocketProcessBridge
{

View file

@ -18,7 +18,7 @@ class ProxyAutoConfig;
class ProxyAutoConfigChild final : public PProxyAutoConfigChild {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ProxyAutoConfigChild, final)
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ProxyAutoConfigChild)
static bool Create(Endpoint<PProxyAutoConfigChild>&& aEndpoint);
static bool CreatePACThread();

View file

@ -13,7 +13,7 @@ namespace net {
class ProxyAutoConfigParent final : public PProxyAutoConfigParent {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ProxyAutoConfigParent, final)
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ProxyAutoConfigParent)
ProxyAutoConfigParent();
void Init(Endpoint<PProxyAutoConfigParent>&& aEndpoint);

View file

@ -32,24 +32,16 @@ bool SocketProcessBridgeChild::Create(
Endpoint<PSocketProcessBridgeChild>&& aEndpoint) {
MOZ_ASSERT(NS_IsMainThread());
sSocketProcessBridgeChild = new SocketProcessBridgeChild();
if (!aEndpoint.Bind(sSocketProcessBridgeChild)) {
MOZ_ASSERT(false, "Bind failed!");
sSocketProcessBridgeChild = nullptr;
return false;
sSocketProcessBridgeChild =
new SocketProcessBridgeChild(std::move(aEndpoint));
if (sSocketProcessBridgeChild->Inited()) {
mozilla::ipc::BackgroundChild::InitSocketBridgeStarter(
sSocketProcessBridgeChild);
return true;
}
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) {
os->AddObserver(sSocketProcessBridgeChild, "content-child-shutdown", false);
}
sSocketProcessBridgeChild->mSocketProcessPid = aEndpoint.OtherPid();
mozilla::ipc::BackgroundChild::InitSocketBridgeStarter(
sSocketProcessBridgeChild);
return true;
sSocketProcessBridgeChild = nullptr;
return false;
}
// static
@ -123,8 +115,23 @@ SocketProcessBridgeChild::GetSocketProcessBridge() {
});
}
SocketProcessBridgeChild::SocketProcessBridgeChild() : mShuttingDown(false) {
SocketProcessBridgeChild::SocketProcessBridgeChild(
Endpoint<PSocketProcessBridgeChild>&& aEndpoint)
: mShuttingDown(false) {
LOG(("CONSTRUCT SocketProcessBridgeChild::SocketProcessBridgeChild\n"));
mInited = aEndpoint.Bind(this);
if (!mInited) {
MOZ_ASSERT(false, "Bind failed!");
return;
}
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) {
os->AddObserver(this, "content-child-shutdown", false);
}
mSocketProcessPid = aEndpoint.OtherPid();
}
SocketProcessBridgeChild::~SocketProcessBridgeChild() {

View file

@ -31,16 +31,19 @@ class SocketProcessBridgeChild final : public PSocketProcessBridgeChild,
void ActorDestroy(ActorDestroyReason aWhy) override;
void DeferredDestroy();
bool IsShuttingDown() const { return mShuttingDown; };
bool Inited() const { return mInited; };
ProcessId SocketProcessPid() const { return mSocketProcessPid; };
private:
DISALLOW_COPY_AND_ASSIGN(SocketProcessBridgeChild);
static bool Create(Endpoint<PSocketProcessBridgeChild>&& aEndpoint);
explicit SocketProcessBridgeChild();
explicit SocketProcessBridgeChild(
Endpoint<PSocketProcessBridgeChild>&& aEndpoint);
virtual ~SocketProcessBridgeChild();
static StaticRefPtr<SocketProcessBridgeChild> sSocketProcessBridgeChild;
bool mShuttingDown;
bool mInited = false;
ProcessId mSocketProcessPid;
};

View file

@ -13,13 +13,16 @@
namespace mozilla {
namespace net {
SocketProcessBridgeParent::SocketProcessBridgeParent(ProcessId aId)
SocketProcessBridgeParent::SocketProcessBridgeParent(
ProcessId aId, Endpoint<PSocketProcessBridgeParent>&& aEndpoint)
: mId(aId), mClosed(false) {
LOG(
("CONSTRUCT SocketProcessBridgeParent::SocketProcessBridgeParent "
"mId=%" PRIPID "\n",
mId));
MOZ_COUNT_CTOR(SocketProcessBridgeParent);
DebugOnly<bool> ok = aEndpoint.Bind(this);
MOZ_ASSERT(ok);
}
SocketProcessBridgeParent::~SocketProcessBridgeParent() {

View file

@ -17,9 +17,10 @@ namespace net {
// called to destroy this actor.
class SocketProcessBridgeParent final : public PSocketProcessBridgeParent {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SocketProcessBridgeParent, final)
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SocketProcessBridgeParent)
explicit SocketProcessBridgeParent(ProcessId aId);
explicit SocketProcessBridgeParent(
ProcessId aId, Endpoint<PSocketProcessBridgeParent>&& aEndpoint);
mozilla::ipc::IPCResult RecvTest();
mozilla::ipc::IPCResult RecvInitBackground(

View file

@ -295,15 +295,9 @@ mozilla::ipc::IPCResult SocketProcessChild::RecvInitSocketProcessBridgeParent(
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!mSocketProcessBridgeParentMap.Contains(aContentProcessId));
if (NS_WARN_IF(!aEndpoint.IsValid())) {
return IPC_FAIL(this, "invalid endpoint");
}
auto bridge = MakeRefPtr<SocketProcessBridgeParent>(aContentProcessId);
MOZ_ALWAYS_TRUE(aEndpoint.Bind(bridge));
mSocketProcessBridgeParentMap.InsertOrUpdate(aContentProcessId,
std::move(bridge));
mSocketProcessBridgeParentMap.InsertOrUpdate(
aContentProcessId, MakeRefPtr<SocketProcessBridgeParent>(
aContentProcessId, std::move(aEndpoint)));
return IPC_OK();
}

View file

@ -27,7 +27,7 @@ class BackgroundDataBridgeParent;
// This is allocated and kept alive by SocketProcessImpl.
class SocketProcessChild final : public PSocketProcessChild {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SocketProcessChild, final)
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SocketProcessChild)
SocketProcessChild();

View file

@ -165,7 +165,7 @@ void SocketProcessHost::InitAfterConnect(bool aSucceeded) {
return;
}
mSocketProcessParent = MakeRefPtr<SocketProcessParent>(this);
mSocketProcessParent = MakeUnique<SocketProcessParent>(this);
DebugOnly<bool> rv = TakeInitialEndpoint().Bind(mSocketProcessParent.get());
MOZ_ASSERT(rv);

View file

@ -115,7 +115,7 @@ class SocketProcessHost final : public mozilla::ipc::GeckoChildProcessHost {
enum class LaunchPhase { Unlaunched, Waiting, Complete };
LaunchPhase mLaunchPhase;
RefPtr<SocketProcessParent> mSocketProcessParent;
UniquePtr<SocketProcessParent> mSocketProcessParent;
// mShutdownRequested is set to true only when Shutdown() is called.
// If mShutdownRequested is false and the IPC channel is closed,
// OnProcessUnexpectedShutdown will be invoked.

View file

@ -67,10 +67,10 @@ bool SocketProcessImpl::Init(int aArgc, char* aArgv[]) {
return false;
}
return mSocketProcessChild->Init(TakeInitialEndpoint(), *parentBuildID);
return mSocketProcessChild.Init(TakeInitialEndpoint(), *parentBuildID);
}
void SocketProcessImpl::CleanUp() { mSocketProcessChild->CleanUp(); }
void SocketProcessImpl::CleanUp() { mSocketProcessChild.CleanUp(); }
} // namespace net
} // namespace mozilla

View file

@ -26,7 +26,7 @@ class SocketProcessImpl final : public mozilla::ipc::ProcessChild {
void CleanUp() override;
private:
RefPtr<SocketProcessChild> mSocketProcessChild = new SocketProcessChild;
SocketProcessChild mSocketProcessChild;
};
} // namespace net

View file

@ -293,18 +293,18 @@ mozilla::ipc::IPCResult SocketProcessParent::RecvCachePushCheck(
class DeferredDeleteSocketProcessParent : public Runnable {
public:
explicit DeferredDeleteSocketProcessParent(
RefPtr<SocketProcessParent>&& aParent)
UniquePtr<SocketProcessParent>&& aParent)
: Runnable("net::DeferredDeleteSocketProcessParent"),
mParent(std::move(aParent)) {}
NS_IMETHODIMP Run() override { return NS_OK; }
private:
RefPtr<SocketProcessParent> mParent;
UniquePtr<SocketProcessParent> mParent;
};
/* static */
void SocketProcessParent::Destroy(RefPtr<SocketProcessParent>&& aParent) {
void SocketProcessParent::Destroy(UniquePtr<SocketProcessParent>&& aParent) {
NS_DispatchToMainThread(
new DeferredDeleteSocketProcessParent(std::move(aParent)));
}

View file

@ -31,9 +31,8 @@ class SocketProcessParent final
public:
friend class SocketProcessHost;
NS_INLINE_DECL_REFCOUNTING(SocketProcessParent, final)
explicit SocketProcessParent(SocketProcessHost* aHost);
~SocketProcessParent();
static SocketProcessParent* GetSingleton();
@ -113,12 +112,10 @@ class SocketProcessParent final
#endif // defined(XP_WIN)
private:
~SocketProcessParent();
SocketProcessHost* mHost;
UniquePtr<dom::MemoryReportRequestHost> mMemoryReportRequest;
static void Destroy(RefPtr<SocketProcessParent>&& aParent);
static void Destroy(UniquePtr<SocketProcessParent>&& aParent);
};
} // namespace net

View file

@ -6,6 +6,7 @@
namespace mozilla {
[ManualDealloc]
sync protocol PSandboxTesting {
parent:
async ReportTestResults(nsCString testName, bool passed, nsCString message);

View file

@ -287,8 +287,8 @@ SandboxTest::StartTests(const nsTArray<nsCString>& aProcessesList) {
RefPtr<ProcessPromise> aPromise(processPromise);
aPromise->Then(
GetMainThreadSerialEventTarget(), __func__,
[self](RefPtr<SandboxTestingParent> aValue) {
self->mSandboxTestingParents.AppendElement(std::move(aValue));
[self](SandboxTestingParent* aValue) {
self->mSandboxTestingParents.AppendElement(aValue);
return NS_OK;
},
[](nsresult aError) {

Some files were not shown because too many files have changed in this diff Show more