Skip to content

Commit

Permalink
Bug 1824465 - Part 6: Make PRDD refcounted, r=ipc-reviewers,mccr8
Browse files Browse the repository at this point in the history
  • Loading branch information
mystor committed Apr 19, 2023
1 parent 2ad2167 commit a838c2c
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion dom/media/ipc/PRDD.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
[ManualDealloc, NeedsOtherPid]
[NeedsOtherPid]
protocol PRDD
{
parent:
Expand Down
12 changes: 5 additions & 7 deletions dom/media/ipc/RDDChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ namespace mozilla {
using namespace layers;
using namespace gfx;

RDDChild::RDDChild(RDDProcessHost* aHost) : mHost(aHost) {
MOZ_COUNT_CTOR(RDDChild);
}
RDDChild::RDDChild(RDDProcessHost* aHost) : mHost(aHost) {}

RDDChild::~RDDChild() { MOZ_COUNT_DTOR(RDDChild); }
RDDChild::~RDDChild() = default;

bool RDDChild::Init() {
Maybe<FileDescriptor> brokerFd;
Expand Down Expand Up @@ -210,17 +208,17 @@ void RDDChild::ActorDestroy(ActorDestroyReason aWhy) {

class DeferredDeleteRDDChild : public Runnable {
public:
explicit DeferredDeleteRDDChild(UniquePtr<RDDChild>&& aChild)
explicit DeferredDeleteRDDChild(RefPtr<RDDChild>&& aChild)
: Runnable("gfx::DeferredDeleteRDDChild"), mChild(std::move(aChild)) {}

NS_IMETHODIMP Run() override { return NS_OK; }

private:
UniquePtr<RDDChild> mChild;
RefPtr<RDDChild> mChild;
};

/* static */
void RDDChild::Destroy(UniquePtr<RDDChild>&& aChild) {
void RDDChild::Destroy(RefPtr<RDDChild>&& aChild) {
NS_DispatchToMainThread(new DeferredDeleteRDDChild(std::move(aChild)));
}

Expand Down
7 changes: 5 additions & 2 deletions dom/media/ipc/RDDChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ class RDDChild final : public PRDDChild,
typedef mozilla::dom::MemoryReportRequestHost MemoryReportRequestHost;

public:
NS_INLINE_DECL_REFCOUNTING(RDDChild, final)

explicit RDDChild(RDDProcessHost* aHost);
~RDDChild();

bool Init();

Expand Down Expand Up @@ -68,9 +69,11 @@ class RDDChild final : public PRDDChild,
const bool& aMinimizeMemoryUsage,
const Maybe<ipc::FileDescriptor>& aDMDFile);

static void Destroy(UniquePtr<RDDChild>&& aChild);
static void Destroy(RefPtr<RDDChild>&& aChild);

private:
~RDDChild();

RDDProcessHost* mHost;
UniquePtr<MemoryReportRequestHost> mMemoryReportRequest;
#if defined(XP_LINUX) && defined(MOZ_SANDBOX)
Expand Down
5 changes: 4 additions & 1 deletion dom/media/ipc/RDDParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ class ChildProfilerController;

class RDDParent final : public PRDDParent {
public:
NS_INLINE_DECL_REFCOUNTING(RDDParent, final)

RDDParent();
~RDDParent();

static RDDParent* GetSingleton();

Expand Down Expand Up @@ -67,6 +68,8 @@ class RDDParent final : public PRDDParent {
mozilla::ipc::IPCResult RecvTestTelemetryProbes();

private:
~RDDParent();

const TimeStamp mLaunchTime;
RefPtr<ChildProfilerController> mProfilerController;
ipc::AsyncBlockers mShutdownBlockers;
Expand Down
2 changes: 1 addition & 1 deletion dom/media/ipc/RDDProcessHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void RDDProcessHost::InitAfterConnect(bool aSucceeded) {
return;
}
mProcessToken = ++sRDDProcessTokenCounter;
mRDDChild = MakeUnique<RDDChild>(this);
mRDDChild = MakeRefPtr<RDDChild>(this);
DebugOnly<bool> rv = TakeInitialEndpoint().Bind(mRDDChild.get());
MOZ_ASSERT(rv);

Expand Down
2 changes: 1 addition & 1 deletion dom/media/ipc/RDDProcessHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class RDDProcessHost final : public mozilla::ipc::GeckoChildProcessHost {
enum class LaunchPhase { Unlaunched, Waiting, Complete };
LaunchPhase mLaunchPhase = LaunchPhase::Unlaunched;

UniquePtr<RDDChild> mRDDChild;
RefPtr<RDDChild> mRDDChild;
uint64_t mProcessToken = 0;

UniquePtr<ipc::SharedPreferenceSerializer> mPrefSerializer;
Expand Down
2 changes: 1 addition & 1 deletion dom/media/ipc/RDDProcessImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down
2 changes: 1 addition & 1 deletion dom/media/ipc/RDDProcessImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RDDProcessImpl final : public ipc::ProcessChild {
void CleanUp() override;

private:
RDDParent mRDD;
RefPtr<RDDParent> mRDD = new RDDParent;

#if defined(XP_WIN)
// This object initializes and configures COM.
Expand Down

0 comments on commit a838c2c

Please sign in to comment.