Skip to content

Commit

Permalink
Bug 1824465 - Part 18: Make PSocketProcess refcounted, r=necko-review…
Browse files Browse the repository at this point in the history
…ers,kershaw

Differential Revision: https://phabricator.services.mozilla.com/D173733
  • Loading branch information
mystor committed Apr 19, 2023
1 parent 9082d1b commit 633e8f7
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion netwerk/ipc/PSocketProcess.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ struct SocketPorcessInitAttributes {
FileDescriptor? mSandboxBroker;
};

[ManualDealloc, NeedsOtherPid]
[NeedsOtherPid]
sync protocol PSocketProcess
{
manages PDNSRequest;
Expand Down
12 changes: 9 additions & 3 deletions netwerk/ipc/SocketProcessChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,15 @@ mozilla::ipc::IPCResult SocketProcessChild::RecvInitSocketProcessBridgeParent(
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!mSocketProcessBridgeParentMap.Contains(aContentProcessId));

mSocketProcessBridgeParentMap.InsertOrUpdate(
aContentProcessId, MakeRefPtr<SocketProcessBridgeParent>(
aContentProcessId, std::move(aEndpoint)));
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));
return IPC_OK();
}

Expand Down
2 changes: 1 addition & 1 deletion netwerk/ipc/SocketProcessChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SocketProcessChild, final)

SocketProcessChild();

Expand Down
2 changes: 1 addition & 1 deletion netwerk/ipc/SocketProcessHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void SocketProcessHost::InitAfterConnect(bool aSucceeded) {
return;
}

mSocketProcessParent = MakeUnique<SocketProcessParent>(this);
mSocketProcessParent = MakeRefPtr<SocketProcessParent>(this);
DebugOnly<bool> rv = TakeInitialEndpoint().Bind(mSocketProcessParent.get());
MOZ_ASSERT(rv);

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

UniquePtr<SocketProcessParent> mSocketProcessParent;
RefPtr<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.
Expand Down
4 changes: 2 additions & 2 deletions netwerk/ipc/SocketProcessImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion netwerk/ipc/SocketProcessImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SocketProcessImpl final : public mozilla::ipc::ProcessChild {
void CleanUp() override;

private:
SocketProcessChild mSocketProcessChild;
RefPtr<SocketProcessChild> mSocketProcessChild = new SocketProcessChild;
};

} // namespace net
Expand Down
6 changes: 3 additions & 3 deletions netwerk/ipc/SocketProcessParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,18 +293,18 @@ mozilla::ipc::IPCResult SocketProcessParent::RecvCachePushCheck(
class DeferredDeleteSocketProcessParent : public Runnable {
public:
explicit DeferredDeleteSocketProcessParent(
UniquePtr<SocketProcessParent>&& aParent)
RefPtr<SocketProcessParent>&& aParent)
: Runnable("net::DeferredDeleteSocketProcessParent"),
mParent(std::move(aParent)) {}

NS_IMETHODIMP Run() override { return NS_OK; }

private:
UniquePtr<SocketProcessParent> mParent;
RefPtr<SocketProcessParent> mParent;
};

/* static */
void SocketProcessParent::Destroy(UniquePtr<SocketProcessParent>&& aParent) {
void SocketProcessParent::Destroy(RefPtr<SocketProcessParent>&& aParent) {
NS_DispatchToMainThread(
new DeferredDeleteSocketProcessParent(std::move(aParent)));
}
Expand Down
7 changes: 5 additions & 2 deletions netwerk/ipc/SocketProcessParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ class SocketProcessParent final
public:
friend class SocketProcessHost;

NS_INLINE_DECL_REFCOUNTING(SocketProcessParent, final)

explicit SocketProcessParent(SocketProcessHost* aHost);
~SocketProcessParent();

static SocketProcessParent* GetSingleton();

Expand Down Expand Up @@ -112,10 +113,12 @@ class SocketProcessParent final
#endif // defined(XP_WIN)

private:
~SocketProcessParent();

SocketProcessHost* mHost;
UniquePtr<dom::MemoryReportRequestHost> mMemoryReportRequest;

static void Destroy(UniquePtr<SocketProcessParent>&& aParent);
static void Destroy(RefPtr<SocketProcessParent>&& aParent);
};

} // namespace net
Expand Down

0 comments on commit 633e8f7

Please sign in to comment.