Skip to content

Commit 0dad4f6

Browse files
committed
Bug 1874739 - Part 10: Make PTestShell refcounted, r=ipc-reviewers,mccr8
This is part of removing [ManualDealloc] from all protocols which manage other protocols. Differential Revision: https://phabricator.services.mozilla.com/D198620
1 parent d780b66 commit 0dad4f6

7 files changed

+17
-25
lines changed

dom/ipc/ContentChild.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -1914,13 +1914,8 @@ bool ContentChild::DeallocPHeapSnapshotTempFileHelperChild(
19141914
return true;
19151915
}
19161916

1917-
PTestShellChild* ContentChild::AllocPTestShellChild() {
1918-
return new TestShellChild();
1919-
}
1920-
1921-
bool ContentChild::DeallocPTestShellChild(PTestShellChild* shell) {
1922-
delete shell;
1923-
return true;
1917+
already_AddRefed<PTestShellChild> ContentChild::AllocPTestShellChild() {
1918+
return MakeAndAddRef<TestShellChild>();
19241919
}
19251920

19261921
mozilla::ipc::IPCResult ContentChild::RecvPTestShellConstructor(

dom/ipc/ContentChild.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,7 @@ class ContentChild final : public PContentChild,
213213
bool DeallocPWebBrowserPersistDocumentChild(
214214
PWebBrowserPersistDocumentChild* aActor);
215215

216-
PTestShellChild* AllocPTestShellChild();
217-
218-
bool DeallocPTestShellChild(PTestShellChild*);
216+
already_AddRefed<PTestShellChild> AllocPTestShellChild();
219217

220218
virtual mozilla::ipc::IPCResult RecvPTestShellConstructor(
221219
PTestShellChild*) override;

dom/ipc/ContentParent.cpp

+5-10
Original file line numberDiff line numberDiff line change
@@ -2493,7 +2493,11 @@ void ContentParent::NotifyTabDestroyed(const TabId& aTabId,
24932493
}
24942494

24952495
TestShellParent* ContentParent::CreateTestShell() {
2496-
return static_cast<TestShellParent*>(SendPTestShellConstructor());
2496+
RefPtr<TestShellParent> actor = new TestShellParent();
2497+
if (!SendPTestShellConstructor(actor)) {
2498+
return nullptr;
2499+
}
2500+
return actor;
24972501
}
24982502

24992503
bool ContentParent::DestroyTestShell(TestShellParent* aTestShell) {
@@ -4673,15 +4677,6 @@ bool ContentParent::CycleCollectWithLogs(
46734677
this, aDumpAllTraces, aSink, aCallback);
46744678
}
46754679

4676-
PTestShellParent* ContentParent::AllocPTestShellParent() {
4677-
return new TestShellParent();
4678-
}
4679-
4680-
bool ContentParent::DeallocPTestShellParent(PTestShellParent* shell) {
4681-
delete shell;
4682-
return true;
4683-
}
4684-
46854680
PScriptCacheParent* ContentParent::AllocPScriptCacheParent(
46864681
const FileDescOrError& cacheFile, const bool& wantCacheData) {
46874682
return new loader::ScriptCacheParent(wantCacheData);

dom/ipc/ContentParent.h

-4
Original file line numberDiff line numberDiff line change
@@ -923,10 +923,6 @@ class ContentParent final : public PContentParent,
923923

924924
bool DeallocPCycleCollectWithLogsParent(PCycleCollectWithLogsParent* aActor);
925925

926-
PTestShellParent* AllocPTestShellParent();
927-
928-
bool DeallocPTestShellParent(PTestShellParent* shell);
929-
930926
PScriptCacheParent* AllocPScriptCacheParent(const FileDescOrError& cacheFile,
931927
const bool& wantCacheData);
932928

ipc/testshell/PTestShell.ipdl

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ include protocol PTestShellCommand;
99
namespace mozilla {
1010
namespace ipc {
1111

12-
[ManualDealloc]
1312
async protocol PTestShell
1413
{
1514
manager PContent;

ipc/testshell/TestShellChild.h

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class XPCShellEnvironment;
1818

1919
class TestShellChild : public PTestShellChild {
2020
public:
21+
NS_INLINE_DECL_REFCOUNTING(TestShellChild, override)
22+
2123
TestShellChild();
2224

2325
mozilla::ipc::IPCResult RecvExecuteCommand(const nsAString& aCommand);
@@ -31,6 +33,8 @@ class TestShellChild : public PTestShellChild {
3133
bool DeallocPTestShellCommandChild(PTestShellCommandChild* aCommand);
3234

3335
private:
36+
~TestShellChild() = default;
37+
3438
UniquePtr<XPCShellEnvironment> mXPCShell;
3539
};
3640

ipc/testshell/TestShellParent.h

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class TestShellParent : public PTestShellParent {
2525
friend class PTestShellParent;
2626

2727
public:
28+
NS_INLINE_DECL_REFCOUNTING(TestShellParent, override)
29+
2830
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
2931

3032
PTestShellCommandParent* AllocPTestShellCommandParent(
@@ -33,6 +35,9 @@ class TestShellParent : public PTestShellParent {
3335
bool DeallocPTestShellCommandParent(PTestShellCommandParent* aActor);
3436

3537
bool CommandDone(TestShellCommandParent* aActor, const nsAString& aResponse);
38+
39+
private:
40+
~TestShellParent() = default;
3641
};
3742

3843
class TestShellCommandParent : public PTestShellCommandParent {

0 commit comments

Comments
 (0)