Skip to content

Commit d780b66

Browse files
committed
Bug 1874739 - Part 9: Make PSpeechSynthesis refcounted, r=eeejay
This is part of removing [ManualDealloc] from all protocols which manage other protocols. Differential Revision: https://phabricator.services.mozilla.com/D198619
1 parent ec054c9 commit d780b66

9 files changed

+11
-32
lines changed

dom/ipc/ContentChild.cpp

-11
Original file line numberDiff line numberDiff line change
@@ -2013,17 +2013,6 @@ bool ContentChild::DeallocPBenchmarkStorageChild(
20132013
return true;
20142014
}
20152015

2016-
#ifdef MOZ_WEBSPEECH
2017-
PSpeechSynthesisChild* ContentChild::AllocPSpeechSynthesisChild() {
2018-
MOZ_CRASH("No one should be allocating PSpeechSynthesisChild actors");
2019-
}
2020-
2021-
bool ContentChild::DeallocPSpeechSynthesisChild(PSpeechSynthesisChild* aActor) {
2022-
delete aActor;
2023-
return true;
2024-
}
2025-
#endif
2026-
20272016
#ifdef MOZ_WEBRTC
20282017
PWebrtcGlobalChild* ContentChild::AllocPWebrtcGlobalChild() {
20292018
auto* child = new WebrtcGlobalChild();

dom/ipc/ContentChild.h

-5
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,6 @@ class ContentChild final : public PContentChild,
244244

245245
mozilla::ipc::IPCResult RecvNotifyEmptyHTTPCache();
246246

247-
#ifdef MOZ_WEBSPEECH
248-
PSpeechSynthesisChild* AllocPSpeechSynthesisChild();
249-
bool DeallocPSpeechSynthesisChild(PSpeechSynthesisChild* aActor);
250-
#endif
251-
252247
mozilla::ipc::IPCResult RecvRegisterChrome(
253248
nsTArray<ChromePackage>&& packages,
254249
nsTArray<SubstitutionMapping>&& resources,

dom/ipc/ContentParent.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -4781,17 +4781,13 @@ bool ContentParent::DeallocPBenchmarkStorageParent(
47814781
}
47824782

47834783
#ifdef MOZ_WEBSPEECH
4784-
PSpeechSynthesisParent* ContentParent::AllocPSpeechSynthesisParent() {
4784+
already_AddRefed<PSpeechSynthesisParent>
4785+
ContentParent::AllocPSpeechSynthesisParent() {
47854786
if (!StaticPrefs::media_webspeech_synth_enabled()) {
47864787
return nullptr;
47874788
}
4788-
return new mozilla::dom::SpeechSynthesisParent();
4789-
}
4790-
4791-
bool ContentParent::DeallocPSpeechSynthesisParent(
4792-
PSpeechSynthesisParent* aActor) {
4793-
delete aActor;
4794-
return true;
4789+
RefPtr<SpeechSynthesisParent> actor = new SpeechSynthesisParent();
4790+
return actor.forget();
47954791
}
47964792

47974793
mozilla::ipc::IPCResult ContentParent::RecvPSpeechSynthesisConstructor(

dom/ipc/ContentParent.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -962,8 +962,7 @@ class ContentParent final : public PContentParent,
962962
bool DeallocPBenchmarkStorageParent(PBenchmarkStorageParent* aActor);
963963

964964
#ifdef MOZ_WEBSPEECH
965-
PSpeechSynthesisParent* AllocPSpeechSynthesisParent();
966-
bool DeallocPSpeechSynthesisParent(PSpeechSynthesisParent* aActor);
965+
already_AddRefed<PSpeechSynthesisParent> AllocPSpeechSynthesisParent();
967966

968967
virtual mozilla::ipc::IPCResult RecvPSpeechSynthesisConstructor(
969968
PSpeechSynthesisParent* aActor) override;

dom/media/webspeech/synth/ipc/PSpeechSynthesis.ipdl

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ struct RemoteVoice {
1818
bool queued;
1919
};
2020

21-
[ManualDealloc]
2221
sync protocol PSpeechSynthesis
2322
{
2423
manager PContent;

dom/media/webspeech/synth/ipc/SpeechSynthesisChild.h

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class SpeechSynthesisChild : public PSpeechSynthesisChild {
2121
friend class PSpeechSynthesisChild;
2222

2323
public:
24+
NS_INLINE_DECL_REFCOUNTING(SpeechSynthesisChild, override)
25+
2426
mozilla::ipc::IPCResult RecvInitialVoicesAndState(
2527
nsTArray<RemoteVoice>&& aVoices, nsTArray<nsString>&& aDefaults,
2628
const bool& aIsSpeaking);

dom/media/webspeech/synth/ipc/SpeechSynthesisParent.h

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class SpeechSynthesisParent : public PSpeechSynthesisParent {
2121
friend class PSpeechSynthesisParent;
2222

2323
public:
24+
NS_INLINE_DECL_REFCOUNTING(SpeechSynthesisParent, override)
25+
2426
void ActorDestroy(ActorDestroyReason aWhy) override;
2527

2628
bool SendInit();

dom/media/webspeech/synth/nsSynthVoiceRegistry.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ NS_IMPL_ISUPPORTS(nsSynthVoiceRegistry, nsISynthVoiceRegistry)
146146
nsSynthVoiceRegistry::nsSynthVoiceRegistry()
147147
: mSpeechSynthChild(nullptr), mUseGlobalQueue(false), mIsSpeaking(false) {
148148
if (XRE_IsContentProcess()) {
149-
SpeechSynthesisChild* actor = new SpeechSynthesisChild();
149+
RefPtr<SpeechSynthesisChild> actor = new SpeechSynthesisChild();
150150
if (ContentChild::GetSingleton()->SendPSpeechSynthesisConstructor(actor)) {
151151
mSpeechSynthChild = actor;
152152
}
@@ -156,9 +156,6 @@ nsSynthVoiceRegistry::nsSynthVoiceRegistry()
156156
nsSynthVoiceRegistry::~nsSynthVoiceRegistry() {
157157
LOG(LogLevel::Debug, ("~nsSynthVoiceRegistry"));
158158

159-
// mSpeechSynthChild's lifecycle is managed by the Content protocol.
160-
mSpeechSynthChild = nullptr;
161-
162159
mUriVoiceMap.Clear();
163160
}
164161

dom/media/webspeech/synth/nsSynthVoiceRegistry.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class nsSynthVoiceRegistry final : public nsISynthVoiceRegistry {
8787

8888
nsRefPtrHashtable<nsStringHashKey, VoiceData> mUriVoiceMap;
8989

90-
SpeechSynthesisChild* mSpeechSynthChild;
90+
RefPtr<SpeechSynthesisChild> mSpeechSynthChild;
9191

9292
bool mUseGlobalQueue;
9393

0 commit comments

Comments
 (0)