зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1806495
- Make PMIDIPort refcounted. r=nika
Differential Revision: https://phabricator.services.mozilla.com/D165437
This commit is contained in:
Родитель
30a62f613b
Коммит
d506fc3130
|
@ -58,8 +58,6 @@ MIDIPort::~MIDIPort() {
|
|||
// probably CC'ing this port object. Send the shutdown message to also clean
|
||||
// up the IPC channel.
|
||||
Port()->SendShutdown();
|
||||
// This will unset the IPC Port pointer. Don't call anything after this.
|
||||
Port()->Teardown();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,9 +84,6 @@ bool MIDIPort::Initialize(const MIDIPortInfo& aPortInfo, bool aSysexEnabled) {
|
|||
LOG("MIDIPort::Initialize (%s, %s)",
|
||||
NS_ConvertUTF16toUTF8(Port()->Name()).get(),
|
||||
MIDIPortTypeValues::strings[uint32_t(Port()->Type())].value);
|
||||
// Make sure to increase the ref count for the port, so it can be cleaned up
|
||||
// by the IPC manager.
|
||||
Port()->SetActorAlive();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,11 +14,9 @@ using namespace mozilla::dom;
|
|||
|
||||
MIDIPortChild::MIDIPortChild(const MIDIPortInfo& aPortInfo, bool aSysexEnabled,
|
||||
MIDIPort* aPort)
|
||||
: MIDIPortInterface(aPortInfo, aSysexEnabled),
|
||||
mDOMPort(aPort),
|
||||
mActorWasAlive(false) {}
|
||||
: MIDIPortInterface(aPortInfo, aSysexEnabled), mDOMPort(aPort) {}
|
||||
|
||||
void MIDIPortChild::Teardown() {
|
||||
void MIDIPortChild::ActorDestroy(ActorDestroyReason aWhy) {
|
||||
if (mDOMPort) {
|
||||
mDOMPort->UnsetIPCPort();
|
||||
MOZ_ASSERT(!mDOMPort);
|
||||
|
@ -26,8 +24,6 @@ void MIDIPortChild::Teardown() {
|
|||
MIDIPortInterface::Shutdown();
|
||||
}
|
||||
|
||||
void MIDIPortChild::ActorDestroy(ActorDestroyReason aWhy) {}
|
||||
|
||||
mozilla::ipc::IPCResult MIDIPortChild::RecvReceive(
|
||||
nsTArray<MIDIMessage>&& aMsgs) {
|
||||
if (mDOMPort) {
|
||||
|
@ -51,12 +47,6 @@ mozilla::ipc::IPCResult MIDIPortChild::RecvUpdateStatus(
|
|||
return IPC_OK();
|
||||
}
|
||||
|
||||
void MIDIPortChild::SetActorAlive() {
|
||||
MOZ_ASSERT(!mActorWasAlive);
|
||||
mActorWasAlive = true;
|
||||
AddRef();
|
||||
}
|
||||
|
||||
nsresult MIDIPortChild::GenerateStableId(const nsACString& aOrigin) {
|
||||
const size_t kIdLength = 64;
|
||||
mStableId.SetCapacity(kIdLength);
|
||||
|
|
|
@ -23,7 +23,7 @@ class MIDIPortInfo;
|
|||
*/
|
||||
class MIDIPortChild final : public PMIDIPortChild, public MIDIPortInterface {
|
||||
public:
|
||||
NS_INLINE_DECL_REFCOUNTING(MIDIPortChild);
|
||||
NS_INLINE_DECL_REFCOUNTING(MIDIPortChild, override);
|
||||
mozilla::ipc::IPCResult RecvReceive(nsTArray<MIDIMessage>&& aMsgs);
|
||||
|
||||
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
|
||||
|
@ -35,10 +35,6 @@ class MIDIPortChild final : public PMIDIPortChild, public MIDIPortInterface {
|
|||
MIDIPort* aPort);
|
||||
nsresult GenerateStableId(const nsACString& aOrigin);
|
||||
const nsString& StableId() { return mStableId; };
|
||||
// virtual void Shutdown() override;
|
||||
void SetActorAlive();
|
||||
|
||||
void Teardown();
|
||||
|
||||
void DetachOwner() { mDOMPort = nullptr; }
|
||||
|
||||
|
@ -48,7 +44,6 @@ class MIDIPortChild final : public PMIDIPortChild, public MIDIPortInterface {
|
|||
// the DOM object.
|
||||
MIDIPort* mDOMPort;
|
||||
nsString mStableId;
|
||||
bool mActorWasAlive;
|
||||
};
|
||||
} // namespace mozilla::dom
|
||||
|
||||
|
|
|
@ -58,12 +58,11 @@ mozilla::ipc::IPCResult MIDIPortParent::RecvShutdown() {
|
|||
if (mShuttingDown) {
|
||||
return IPC_OK();
|
||||
}
|
||||
Teardown();
|
||||
Unused << Send__delete__(this);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
void MIDIPortParent::Teardown() {
|
||||
void MIDIPortParent::ActorDestroy(ActorDestroyReason) {
|
||||
mMessageQueue.Clear();
|
||||
MIDIPortInterface::Shutdown();
|
||||
if (MIDIPlatformService::IsRunning()) {
|
||||
|
@ -71,8 +70,6 @@ void MIDIPortParent::Teardown() {
|
|||
}
|
||||
}
|
||||
|
||||
void MIDIPortParent::ActorDestroy(ActorDestroyReason) {}
|
||||
|
||||
bool MIDIPortParent::SendUpdateStatus(
|
||||
const MIDIPortDeviceState& aDeviceState,
|
||||
const MIDIPortConnectionState& aConnectionState) {
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace mozilla::dom {
|
|||
*/
|
||||
class MIDIPortParent final : public PMIDIPortParent, public MIDIPortInterface {
|
||||
public:
|
||||
NS_INLINE_DECL_REFCOUNTING(MIDIPortParent);
|
||||
NS_INLINE_DECL_REFCOUNTING(MIDIPortParent, override);
|
||||
void ActorDestroy(ActorDestroyReason) override;
|
||||
mozilla::ipc::IPCResult RecvSend(nsTArray<MIDIMessage>&& aMsg);
|
||||
mozilla::ipc::IPCResult RecvOpen();
|
||||
|
@ -34,7 +34,6 @@ class MIDIPortParent final : public PMIDIPortParent, public MIDIPortInterface {
|
|||
bool SendUpdateStatus(const MIDIPortDeviceState& aDeviceState,
|
||||
const MIDIPortConnectionState& aConnectionState);
|
||||
uint32_t GetInternalId() const { return mInternalId; }
|
||||
void Teardown();
|
||||
|
||||
protected:
|
||||
~MIDIPortParent() = default;
|
||||
|
|
|
@ -10,7 +10,6 @@ include MIDITypes;
|
|||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
[ManualDealloc]
|
||||
async protocol PMIDIPort
|
||||
{
|
||||
manager PBackground;
|
||||
|
|
|
@ -480,26 +480,6 @@ bool BackgroundChildImpl::DeallocPQuotaChild(PQuotaChild* aActor) {
|
|||
return true;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// WebMIDI API
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
PMIDIPortChild* BackgroundChildImpl::AllocPMIDIPortChild(
|
||||
const MIDIPortInfo& aPortInfo, const bool& aSysexEnabled) {
|
||||
MOZ_CRASH("Should be created manually");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool BackgroundChildImpl::DeallocPMIDIPortChild(PMIDIPortChild* aActor) {
|
||||
MOZ_ASSERT(aActor);
|
||||
// The reference is increased in dom/midi/MIDIPort.cpp. We should
|
||||
// decrease it after IPC.
|
||||
RefPtr<dom::MIDIPortChild> child =
|
||||
dont_AddRef(static_cast<dom::MIDIPortChild*>(aActor));
|
||||
child->Teardown();
|
||||
return true;
|
||||
}
|
||||
|
||||
mozilla::dom::PClientManagerChild*
|
||||
BackgroundChildImpl::AllocPClientManagerChild() {
|
||||
return mozilla::dom::AllocClientManagerChild();
|
||||
|
|
|
@ -195,10 +195,6 @@ class BackgroundChildImpl : public PBackgroundChild {
|
|||
virtual bool DeallocPWebAuthnTransactionChild(
|
||||
PWebAuthnTransactionChild* aActor) override;
|
||||
|
||||
virtual PMIDIPortChild* AllocPMIDIPortChild(
|
||||
const MIDIPortInfo& aPortInfo, const bool& aSysexEnabled) override;
|
||||
virtual bool DeallocPMIDIPortChild(PMIDIPortChild*) override;
|
||||
|
||||
already_AddRefed<PServiceWorkerChild> AllocPServiceWorkerChild(
|
||||
const IPCServiceWorkerDescriptor&);
|
||||
|
||||
|
|
|
@ -1229,24 +1229,13 @@ BackgroundParentImpl::RecvPHttpBackgroundChannelConstructor(
|
|||
return IPC_OK();
|
||||
}
|
||||
|
||||
PMIDIPortParent* BackgroundParentImpl::AllocPMIDIPortParent(
|
||||
already_AddRefed<PMIDIPortParent> BackgroundParentImpl::AllocPMIDIPortParent(
|
||||
const MIDIPortInfo& aPortInfo, const bool& aSysexEnabled) {
|
||||
AssertIsInMainOrSocketProcess();
|
||||
AssertIsOnBackgroundThread();
|
||||
|
||||
RefPtr<MIDIPortParent> result = new MIDIPortParent(aPortInfo, aSysexEnabled);
|
||||
return result.forget().take();
|
||||
}
|
||||
|
||||
bool BackgroundParentImpl::DeallocPMIDIPortParent(PMIDIPortParent* aActor) {
|
||||
MOZ_ASSERT(aActor);
|
||||
AssertIsInMainOrSocketProcess();
|
||||
AssertIsOnBackgroundThread();
|
||||
|
||||
RefPtr<MIDIPortParent> parent =
|
||||
dont_AddRef(static_cast<MIDIPortParent*>(aActor));
|
||||
parent->Teardown();
|
||||
return true;
|
||||
return result.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<PMIDIManagerParent>
|
||||
|
|
|
@ -345,10 +345,8 @@ class BackgroundParentImpl : public PBackgroundParent {
|
|||
mozilla::ipc::IPCResult RecvPClientManagerConstructor(
|
||||
PClientManagerParent* aActor) override;
|
||||
|
||||
PMIDIPortParent* AllocPMIDIPortParent(const MIDIPortInfo& aPortInfo,
|
||||
const bool& aSysexEnabled) override;
|
||||
|
||||
bool DeallocPMIDIPortParent(PMIDIPortParent* aActor) override;
|
||||
already_AddRefed<PMIDIPortParent> AllocPMIDIPortParent(
|
||||
const MIDIPortInfo& aPortInfo, const bool& aSysexEnabled) override;
|
||||
|
||||
already_AddRefed<PMIDIManagerParent> AllocPMIDIManagerParent() override;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче