1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "ClientSourceChild.h" 8 9 #include "ClientSource.h" 10 #include "ClientSourceOpChild.h" 11 #include "mozilla/dom/ClientIPCTypes.h" 12 #include "mozilla/Unused.h" 13 14 namespace mozilla::dom { 15 16 using mozilla::ipc::IPCResult; 17 ActorDestroy(ActorDestroyReason aReason)18void ClientSourceChild::ActorDestroy(ActorDestroyReason aReason) { 19 if (mSource) { 20 mSource->RevokeActor(this); 21 22 // Revoking the actor link should automatically cause the owner 23 // to call RevokeOwner() as well. 24 MOZ_DIAGNOSTIC_ASSERT(!mSource); 25 } 26 } 27 AllocPClientSourceOpChild(const ClientOpConstructorArgs & aArgs)28PClientSourceOpChild* ClientSourceChild::AllocPClientSourceOpChild( 29 const ClientOpConstructorArgs& aArgs) { 30 return new ClientSourceOpChild(); 31 } 32 DeallocPClientSourceOpChild(PClientSourceOpChild * aActor)33bool ClientSourceChild::DeallocPClientSourceOpChild( 34 PClientSourceOpChild* aActor) { 35 static_cast<ClientSourceOpChild*>(aActor)->ScheduleDeletion(); 36 return true; 37 } 38 RecvPClientSourceOpConstructor(PClientSourceOpChild * aActor,const ClientOpConstructorArgs & aArgs)39IPCResult ClientSourceChild::RecvPClientSourceOpConstructor( 40 PClientSourceOpChild* aActor, const ClientOpConstructorArgs& aArgs) { 41 auto actor = static_cast<ClientSourceOpChild*>(aActor); 42 actor->Init(aArgs); 43 return IPC_OK(); 44 } 45 ClientSourceChild(const ClientSourceConstructorArgs & aArgs)46ClientSourceChild::ClientSourceChild(const ClientSourceConstructorArgs& aArgs) 47 : mSource(nullptr), mTeardownStarted(false) {} 48 SetOwner(ClientThing<ClientSourceChild> * aThing)49void ClientSourceChild::SetOwner(ClientThing<ClientSourceChild>* aThing) { 50 MOZ_DIAGNOSTIC_ASSERT(aThing); 51 MOZ_DIAGNOSTIC_ASSERT(!mSource); 52 mSource = static_cast<ClientSource*>(aThing); 53 } 54 RevokeOwner(ClientThing<ClientSourceChild> * aThing)55void ClientSourceChild::RevokeOwner(ClientThing<ClientSourceChild>* aThing) { 56 MOZ_DIAGNOSTIC_ASSERT(mSource); 57 MOZ_DIAGNOSTIC_ASSERT(mSource == static_cast<ClientSource*>(aThing)); 58 mSource = nullptr; 59 } 60 GetSource() const61ClientSource* ClientSourceChild::GetSource() const { return mSource; } 62 MaybeStartTeardown()63void ClientSourceChild::MaybeStartTeardown() { 64 if (mTeardownStarted) { 65 return; 66 } 67 mTeardownStarted = true; 68 Unused << SendTeardown(); 69 } 70 71 } // namespace mozilla::dom 72