/src/mozilla-central/dom/cache/CacheStorageChild.cpp
Line | Count | Source (jump to first uncovered line) |
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/CacheStorageChild.h" |
8 | | |
9 | | #include "mozilla/Unused.h" |
10 | | #include "mozilla/dom/cache/CacheChild.h" |
11 | | #include "mozilla/dom/cache/CacheOpChild.h" |
12 | | #include "mozilla/dom/cache/CacheStorage.h" |
13 | | |
14 | | namespace mozilla { |
15 | | namespace dom { |
16 | | namespace cache { |
17 | | |
18 | | // declared in ActorUtils.h |
19 | | void |
20 | | DeallocPCacheStorageChild(PCacheStorageChild* aActor) |
21 | 0 | { |
22 | 0 | delete aActor; |
23 | 0 | } |
24 | | |
25 | | CacheStorageChild::CacheStorageChild(CacheStorage* aListener, |
26 | | CacheWorkerHolder* aWorkerHolder) |
27 | | : mListener(aListener) |
28 | | , mNumChildActors(0) |
29 | | , mDelayedDestroy(false) |
30 | 0 | { |
31 | 0 | MOZ_COUNT_CTOR(cache::CacheStorageChild); |
32 | 0 | MOZ_DIAGNOSTIC_ASSERT(mListener); |
33 | 0 |
|
34 | 0 | SetWorkerHolder(aWorkerHolder); |
35 | 0 | } |
36 | | |
37 | | CacheStorageChild::~CacheStorageChild() |
38 | 0 | { |
39 | 0 | MOZ_COUNT_DTOR(cache::CacheStorageChild); |
40 | 0 | NS_ASSERT_OWNINGTHREAD(CacheStorageChild); |
41 | 0 | MOZ_DIAGNOSTIC_ASSERT(!mListener); |
42 | 0 | } |
43 | | |
44 | | void |
45 | | CacheStorageChild::ClearListener() |
46 | 0 | { |
47 | 0 | NS_ASSERT_OWNINGTHREAD(CacheStorageChild); |
48 | 0 | MOZ_DIAGNOSTIC_ASSERT(mListener); |
49 | 0 | mListener = nullptr; |
50 | 0 | } |
51 | | |
52 | | void |
53 | | CacheStorageChild::ExecuteOp(nsIGlobalObject* aGlobal, Promise* aPromise, |
54 | | nsISupports* aParent, const CacheOpArgs& aArgs) |
55 | 0 | { |
56 | 0 | mNumChildActors += 1; |
57 | 0 | Unused << SendPCacheOpConstructor( |
58 | 0 | new CacheOpChild(GetWorkerHolder(), aGlobal, aParent, aPromise), aArgs); |
59 | 0 | } |
60 | | |
61 | | void |
62 | | CacheStorageChild::StartDestroyFromListener() |
63 | 0 | { |
64 | 0 | NS_ASSERT_OWNINGTHREAD(CacheStorageChild); |
65 | 0 |
|
66 | 0 | // The listener should be held alive by any async operations, so if it |
67 | 0 | // is going away then there must not be any child actors. This in turn |
68 | 0 | // ensures that StartDestroy() will not trigger the delayed path. |
69 | 0 | MOZ_DIAGNOSTIC_ASSERT(!mNumChildActors); |
70 | 0 |
|
71 | 0 | StartDestroy(); |
72 | 0 | } |
73 | | |
74 | | void |
75 | | CacheStorageChild::StartDestroy() |
76 | 0 | { |
77 | 0 | NS_ASSERT_OWNINGTHREAD(CacheStorageChild); |
78 | 0 |
|
79 | 0 | // If we have outstanding child actors, then don't destroy ourself yet. |
80 | 0 | // The child actors should be short lived and we should allow them to complete |
81 | 0 | // if possible. NoteDeletedActor() will call back into this Shutdown() |
82 | 0 | // method when the last child actor is gone. |
83 | 0 | if (mNumChildActors) { |
84 | 0 | mDelayedDestroy = true; |
85 | 0 | return; |
86 | 0 | } |
87 | 0 | |
88 | 0 | RefPtr<CacheStorage> listener = mListener; |
89 | 0 |
|
90 | 0 | // StartDestroy() can get called from either CacheStorage or the |
91 | 0 | // CacheWorkerHolder. |
92 | 0 | // Theoretically we can get double called if the right race happens. Handle |
93 | 0 | // that by just ignoring the second StartDestroy() call. |
94 | 0 | if (!listener) { |
95 | 0 | return; |
96 | 0 | } |
97 | 0 | |
98 | 0 | listener->DestroyInternal(this); |
99 | 0 |
|
100 | 0 | // CacheStorage listener should call ClearListener() in DestroyInternal() |
101 | 0 | MOZ_DIAGNOSTIC_ASSERT(!mListener); |
102 | 0 |
|
103 | 0 | // Start actor destruction from parent process |
104 | 0 | Unused << SendTeardown(); |
105 | 0 | } |
106 | | |
107 | | void |
108 | | CacheStorageChild::ActorDestroy(ActorDestroyReason aReason) |
109 | 0 | { |
110 | 0 | NS_ASSERT_OWNINGTHREAD(CacheStorageChild); |
111 | 0 | RefPtr<CacheStorage> listener = mListener; |
112 | 0 | if (listener) { |
113 | 0 | listener->DestroyInternal(this); |
114 | 0 | // CacheStorage listener should call ClearListener() in DestroyInternal() |
115 | 0 | MOZ_DIAGNOSTIC_ASSERT(!mListener); |
116 | 0 | } |
117 | 0 |
|
118 | 0 | RemoveWorkerHolder(); |
119 | 0 | } |
120 | | |
121 | | PCacheOpChild* |
122 | | CacheStorageChild::AllocPCacheOpChild(const CacheOpArgs& aOpArgs) |
123 | 0 | { |
124 | 0 | MOZ_CRASH("CacheOpChild should be manually constructed."); |
125 | 0 | return nullptr; |
126 | 0 | } |
127 | | |
128 | | bool |
129 | | CacheStorageChild::DeallocPCacheOpChild(PCacheOpChild* aActor) |
130 | 0 | { |
131 | 0 | delete aActor; |
132 | 0 | NoteDeletedActor(); |
133 | 0 | return true; |
134 | 0 | } |
135 | | |
136 | | void |
137 | | CacheStorageChild::NoteDeletedActor() |
138 | 0 | { |
139 | 0 | MOZ_DIAGNOSTIC_ASSERT(mNumChildActors); |
140 | 0 | mNumChildActors -= 1; |
141 | 0 | if (!mNumChildActors && mDelayedDestroy) { |
142 | 0 | StartDestroy(); |
143 | 0 | } |
144 | 0 | } |
145 | | |
146 | | } // namespace cache |
147 | | } // namespace dom |
148 | | } // namespace mozilla |