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/. */
7 #include "mozilla/dom/cache/CacheParent.h"
9 #include "mozilla/dom/cache/CacheOpParent.h"
12 namespace mozilla::dom::cache
{
14 // Declared in ActorUtils.h
15 void DeallocPCacheParent(PCacheParent
* aActor
) { delete aActor
; }
17 CacheParent::CacheParent(SafeRefPtr
<cache::Manager
> aManager
, CacheId aCacheId
)
18 : mManager(std::move(aManager
)), mCacheId(aCacheId
) {
19 MOZ_COUNT_CTOR(cache::CacheParent
);
20 MOZ_DIAGNOSTIC_ASSERT(mManager
);
21 mManager
->AddRefCacheId(mCacheId
);
24 CacheParent::~CacheParent() {
25 MOZ_COUNT_DTOR(cache::CacheParent
);
26 MOZ_DIAGNOSTIC_ASSERT(!mManager
);
29 void CacheParent::ActorDestroy(ActorDestroyReason aReason
) {
30 MOZ_DIAGNOSTIC_ASSERT(mManager
);
31 mManager
->ReleaseCacheId(mCacheId
);
35 already_AddRefed
<PCacheOpParent
> CacheParent::AllocPCacheOpParent(
36 const CacheOpArgs
& aOpArgs
) {
37 if (aOpArgs
.type() != CacheOpArgs::TCacheMatchArgs
&&
38 aOpArgs
.type() != CacheOpArgs::TCacheMatchAllArgs
&&
39 aOpArgs
.type() != CacheOpArgs::TCachePutAllArgs
&&
40 aOpArgs
.type() != CacheOpArgs::TCacheDeleteArgs
&&
41 aOpArgs
.type() != CacheOpArgs::TCacheKeysArgs
) {
42 MOZ_CRASH("Invalid operation sent to Cache actor!");
45 return MakeAndAddRef
<CacheOpParent
>(Manager(), mCacheId
, aOpArgs
);
48 mozilla::ipc::IPCResult
CacheParent::RecvPCacheOpConstructor(
49 PCacheOpParent
* aActor
, const CacheOpArgs
& aOpArgs
) {
50 auto actor
= static_cast<CacheOpParent
*>(aActor
);
51 actor
->Execute(mManager
.clonePtr());
55 mozilla::ipc::IPCResult
CacheParent::RecvTeardown() {
56 // If child process is gone, warn and allow actor to clean up normally
57 QM_WARNONLY_TRY(OkIf(Send__delete__(this)));
61 } // namespace mozilla::dom::cache