Skip to content

Commit

Permalink
Bug 1824465 - Part 19: Make PSocketProcessBridge refcounted, r=necko-…
Browse files Browse the repository at this point in the history
…reviewers,kershaw

Differential Revision: https://phabricator.services.mozilla.com/D173734
  • Loading branch information
mystor committed Apr 5, 2023
1 parent 0132833 commit 69e132b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 36 deletions.
2 changes: 1 addition & 1 deletion netwerk/ipc/PSocketProcessBridge.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace net {
* content process and PSocketProcessBridgeParent lives in
* socket process.
*/
[ManualDealloc, NeedsOtherPid]
[NeedsOtherPid]
sync protocol PSocketProcessBridge
{

Expand Down
41 changes: 17 additions & 24 deletions netwerk/ipc/SocketProcessBridgeChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,24 @@ bool SocketProcessBridgeChild::Create(
Endpoint<PSocketProcessBridgeChild>&& aEndpoint) {
MOZ_ASSERT(NS_IsMainThread());

sSocketProcessBridgeChild =
new SocketProcessBridgeChild(std::move(aEndpoint));
if (sSocketProcessBridgeChild->Inited()) {
mozilla::ipc::BackgroundChild::InitSocketBridgeStarter(
sSocketProcessBridgeChild);
return true;
sSocketProcessBridgeChild = new SocketProcessBridgeChild();

if (!aEndpoint.Bind(sSocketProcessBridgeChild)) {
MOZ_ASSERT(false, "Bind failed!");
sSocketProcessBridgeChild = nullptr;
return false;
}

sSocketProcessBridgeChild = nullptr;
return false;
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;
}

// static
Expand Down Expand Up @@ -115,23 +123,8 @@ SocketProcessBridgeChild::GetSocketProcessBridge() {
});
}

SocketProcessBridgeChild::SocketProcessBridgeChild(
Endpoint<PSocketProcessBridgeChild>&& aEndpoint)
: mShuttingDown(false) {
SocketProcessBridgeChild::SocketProcessBridgeChild() : 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() {
Expand Down
5 changes: 1 addition & 4 deletions netwerk/ipc/SocketProcessBridgeChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,16 @@ 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(
Endpoint<PSocketProcessBridgeChild>&& aEndpoint);
explicit SocketProcessBridgeChild();
virtual ~SocketProcessBridgeChild();

static StaticRefPtr<SocketProcessBridgeChild> sSocketProcessBridgeChild;
bool mShuttingDown;
bool mInited = false;
ProcessId mSocketProcessPid;
};

Expand Down
5 changes: 1 addition & 4 deletions netwerk/ipc/SocketProcessBridgeParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@
namespace mozilla {
namespace net {

SocketProcessBridgeParent::SocketProcessBridgeParent(
ProcessId aId, Endpoint<PSocketProcessBridgeParent>&& aEndpoint)
SocketProcessBridgeParent::SocketProcessBridgeParent(ProcessId aId)
: 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() {
Expand Down
5 changes: 2 additions & 3 deletions netwerk/ipc/SocketProcessBridgeParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ namespace net {
// called to destroy this actor.
class SocketProcessBridgeParent final : public PSocketProcessBridgeParent {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SocketProcessBridgeParent)
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SocketProcessBridgeParent, final)

explicit SocketProcessBridgeParent(
ProcessId aId, Endpoint<PSocketProcessBridgeParent>&& aEndpoint);
explicit SocketProcessBridgeParent(ProcessId aId);

mozilla::ipc::IPCResult RecvTest();
mozilla::ipc::IPCResult RecvInitBackground(
Expand Down

0 comments on commit 69e132b

Please sign in to comment.