Line data Source code
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 {
13 : namespace dom {
14 : namespace cache {
15 :
16 : // Declared in ActorUtils.h
17 : void
18 0 : DeallocPCacheParent(PCacheParent* aActor)
19 : {
20 0 : delete aActor;
21 0 : }
22 :
23 0 : CacheParent::CacheParent(cache::Manager* aManager, CacheId aCacheId)
24 : : mManager(aManager)
25 0 : , mCacheId(aCacheId)
26 : {
27 0 : MOZ_COUNT_CTOR(cache::CacheParent);
28 0 : MOZ_DIAGNOSTIC_ASSERT(mManager);
29 0 : mManager->AddRefCacheId(mCacheId);
30 0 : }
31 :
32 0 : CacheParent::~CacheParent()
33 : {
34 0 : MOZ_COUNT_DTOR(cache::CacheParent);
35 0 : MOZ_DIAGNOSTIC_ASSERT(!mManager);
36 0 : }
37 :
38 : void
39 0 : CacheParent::ActorDestroy(ActorDestroyReason aReason)
40 : {
41 0 : MOZ_DIAGNOSTIC_ASSERT(mManager);
42 0 : mManager->ReleaseCacheId(mCacheId);
43 0 : mManager = nullptr;
44 0 : }
45 :
46 : PCacheOpParent*
47 0 : CacheParent::AllocPCacheOpParent(const CacheOpArgs& aOpArgs)
48 : {
49 0 : if (aOpArgs.type() != CacheOpArgs::TCacheMatchArgs &&
50 0 : aOpArgs.type() != CacheOpArgs::TCacheMatchAllArgs &&
51 0 : aOpArgs.type() != CacheOpArgs::TCachePutAllArgs &&
52 0 : aOpArgs.type() != CacheOpArgs::TCacheDeleteArgs &&
53 0 : aOpArgs.type() != CacheOpArgs::TCacheKeysArgs)
54 : {
55 0 : MOZ_CRASH("Invalid operation sent to Cache actor!");
56 : }
57 :
58 0 : return new CacheOpParent(Manager(), mCacheId, aOpArgs);
59 : }
60 :
61 : bool
62 0 : CacheParent::DeallocPCacheOpParent(PCacheOpParent* aActor)
63 : {
64 0 : delete aActor;
65 0 : return true;
66 : }
67 :
68 : mozilla::ipc::IPCResult
69 0 : CacheParent::RecvPCacheOpConstructor(PCacheOpParent* aActor,
70 : const CacheOpArgs& aOpArgs)
71 : {
72 0 : auto actor = static_cast<CacheOpParent*>(aActor);
73 0 : actor->Execute(mManager);
74 0 : return IPC_OK();
75 : }
76 :
77 : mozilla::ipc::IPCResult
78 0 : CacheParent::RecvTeardown()
79 : {
80 0 : if (!Send__delete__(this)) {
81 : // child process is gone, warn and allow actor to clean up normally
82 0 : NS_WARNING("Cache failed to send delete.");
83 : }
84 0 : return IPC_OK();
85 : }
86 :
87 : } // namespace cache
88 : } // namespace dom
89 : } // namespace mozilla
|