CacheParent.cpp (2184B)
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 "mozilla/dom/cache/CacheParent.h" 8 9 #include "mozilla/dom/cache/CacheOpParent.h" 10 #include "nsCOMPtr.h" 11 12 namespace mozilla::dom::cache { 13 14 // Declared in ActorUtils.h 15 void DeallocPCacheParent(PCacheParent* aActor) { delete aActor; } 16 17 CacheParent::CacheParent(const WeakRefParentType& aManagingActor, 18 SafeRefPtr<cache::Manager> aManager, CacheId aCacheId) 19 : mManagingActor(aManagingActor), 20 mManager(std::move(aManager)), 21 mCacheId(aCacheId) { 22 MOZ_COUNT_CTOR(cache::CacheParent); 23 MOZ_DIAGNOSTIC_ASSERT(mManager); 24 mManager->AddRefCacheId(mCacheId); 25 } 26 27 CacheParent::~CacheParent() { 28 MOZ_COUNT_DTOR(cache::CacheParent); 29 MOZ_DIAGNOSTIC_ASSERT(!mManager); 30 } 31 32 void CacheParent::ActorDestroy(ActorDestroyReason aReason) { 33 MOZ_DIAGNOSTIC_ASSERT(mManager); 34 mManager->ReleaseCacheId(mCacheId); 35 mManager = nullptr; 36 } 37 38 already_AddRefed<PCacheOpParent> CacheParent::AllocPCacheOpParent( 39 const CacheOpArgs& aOpArgs) { 40 if (aOpArgs.type() != CacheOpArgs::TCacheMatchArgs && 41 aOpArgs.type() != CacheOpArgs::TCacheMatchAllArgs && 42 aOpArgs.type() != CacheOpArgs::TCachePutAllArgs && 43 aOpArgs.type() != CacheOpArgs::TCacheDeleteArgs && 44 aOpArgs.type() != CacheOpArgs::TCacheKeysArgs) { 45 MOZ_CRASH("Invalid operation sent to Cache actor!"); 46 } 47 48 return MakeAndAddRef<CacheOpParent>(mManagingActor, aOpArgs, mCacheId); 49 } 50 51 mozilla::ipc::IPCResult CacheParent::RecvPCacheOpConstructor( 52 PCacheOpParent* aActor, const CacheOpArgs& aOpArgs) { 53 auto* actor = static_cast<CacheOpParent*>(aActor); 54 actor->Execute(mManager.clonePtr()); 55 return IPC_OK(); 56 } 57 58 mozilla::ipc::IPCResult CacheParent::RecvTeardown() { 59 // If child process is gone, warn and allow actor to clean up normally 60 QM_WARNONLY_TRY(OkIf(Send__delete__(this))); 61 return IPC_OK(); 62 } 63 64 } // namespace mozilla::dom::cache