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 : #ifndef mozilla_dom_cache_CacheChild_h
8 : #define mozilla_dom_cache_CacheChild_h
9 :
10 : #include "mozilla/dom/cache/ActorChild.h"
11 : #include "mozilla/dom/cache/PCacheChild.h"
12 :
13 : class nsIAsyncInputStream;
14 : class nsIGlobalObject;
15 :
16 : namespace mozilla {
17 : namespace dom {
18 :
19 : class Promise;
20 :
21 : namespace cache {
22 :
23 : class Cache;
24 : class CacheOpArgs;
25 :
26 : class CacheChild final : public PCacheChild
27 : , public ActorChild
28 : {
29 : public:
30 : class MOZ_RAII AutoLock final
31 : {
32 : CacheChild* mActor;
33 :
34 : public:
35 0 : explicit AutoLock(CacheChild* aActor)
36 0 : : mActor(aActor)
37 : {
38 0 : MOZ_DIAGNOSTIC_ASSERT(mActor);
39 0 : mActor->Lock();
40 0 : }
41 :
42 0 : ~AutoLock()
43 0 : {
44 0 : mActor->Unlock();
45 0 : }
46 : };
47 :
48 : CacheChild();
49 : ~CacheChild();
50 :
51 : void SetListener(Cache* aListener);
52 :
53 : // Must be called by the associated Cache listener in its DestroyInternal()
54 : // method. Also, Cache must call StartDestroyFromListener() on the actor in
55 : // its destructor to trigger ActorDestroy() if it has not been called yet.
56 : void ClearListener();
57 :
58 : void
59 : ExecuteOp(nsIGlobalObject* aGlobal, Promise* aPromise,
60 : nsISupports* aParent, const CacheOpArgs& aArgs);
61 :
62 : // Our parent Listener object has gone out of scope and is being destroyed.
63 : void StartDestroyFromListener();
64 :
65 : private:
66 : // ActorChild methods
67 :
68 : // WorkerHolder is trying to destroy due to worker shutdown.
69 : virtual void StartDestroy() override;
70 :
71 : // PCacheChild methods
72 : virtual void
73 : ActorDestroy(ActorDestroyReason aReason) override;
74 :
75 : virtual PCacheOpChild*
76 : AllocPCacheOpChild(const CacheOpArgs& aOpArgs) override;
77 :
78 : virtual bool
79 : DeallocPCacheOpChild(PCacheOpChild* aActor) override;
80 :
81 : // utility methods
82 : void
83 : NoteDeletedActor();
84 :
85 : void
86 : MaybeFlushDelayedDestroy();
87 :
88 : // Methods used to temporarily force the actor alive. Only called from
89 : // AutoLock.
90 : void
91 : Lock();
92 :
93 : void
94 : Unlock();
95 :
96 : // Use a weak ref so actor does not hold DOM object alive past content use.
97 : // The Cache object must call ClearListener() to null this before its
98 : // destroyed.
99 : Cache* MOZ_NON_OWNING_REF mListener;
100 : uint32_t mNumChildActors;
101 : bool mDelayedDestroy;
102 : bool mLocked;
103 :
104 : NS_DECL_OWNINGTHREAD
105 : };
106 :
107 : } // namespace cache
108 : } // namespace dom
109 : } // namespace mozilla
110 :
111 : #endif // mozilla_dom_cache_CacheChild_h
|