Backed out changeset 9d8b4c0b99ed (bug 1945683) for causing btime failures. CLOSED...
[gecko.git] / dom / cache / CacheStorageChild.cpp
blobe344e2c27270490e0021bdaa79400c74cfcfbed2
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/CacheStorageChild.h"
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 #include "mozilla/dom/cache/CacheWorkerRef.h"
15 namespace mozilla::dom::cache {
17 // declared in ActorUtils.h
18 void DeallocPCacheStorageChild(PCacheStorageChild* aActor) { delete aActor; }
20 CacheStorageChild::CacheStorageChild(CacheStorage* aListener,
21 SafeRefPtr<CacheWorkerRef> aWorkerRef)
22 : mListener(aListener), mDelayedDestroy(false) {
23 MOZ_COUNT_CTOR(cache::CacheStorageChild);
24 MOZ_DIAGNOSTIC_ASSERT(mListener);
26 SetWorkerRef(std::move(aWorkerRef));
29 CacheStorageChild::~CacheStorageChild() {
30 MOZ_COUNT_DTOR(cache::CacheStorageChild);
31 NS_ASSERT_OWNINGTHREAD(CacheStorageChild);
32 MOZ_DIAGNOSTIC_ASSERT(!mListener);
35 void CacheStorageChild::ClearListener() {
36 NS_ASSERT_OWNINGTHREAD(CacheStorageChild);
37 MOZ_DIAGNOSTIC_ASSERT(mListener);
38 mListener = nullptr;
41 void CacheStorageChild::ExecuteOp(nsIGlobalObject* aGlobal, Promise* aPromise,
42 nsISupports* aParent,
43 const CacheOpArgs& aArgs) {
44 Unused << SendPCacheOpConstructor(
45 new CacheOpChild(GetWorkerRefPtr().clonePtr(), aGlobal, aParent, aPromise,
46 this),
47 aArgs);
50 void CacheStorageChild::StartDestroyFromListener() {
51 NS_ASSERT_OWNINGTHREAD(CacheStorageChild);
53 StartDestroy();
56 void CacheStorageChild::DestroyInternal() {
57 RefPtr<CacheStorage> listener = mListener;
59 // StartDestroy() can get called from either CacheStorage or the
60 // CacheWorkerRef.
61 // Theoretically we can get double called if the right race happens. Handle
62 // that by just ignoring the second StartDestroy() call.
63 if (!listener) {
64 return;
67 listener->DestroyInternal(this);
69 // CacheStorage listener should call ClearListener() in DestroyInternal()
70 MOZ_DIAGNOSTIC_ASSERT(!mListener);
72 // Start actor destruction from parent process
73 QM_WARNONLY_TRY(OkIf(SendTeardown()));
76 void CacheStorageChild::StartDestroy() {
77 NS_ASSERT_OWNINGTHREAD(CacheStorageChild);
79 if (NumChildActors() != 0) {
80 mDelayedDestroy = true;
81 return;
83 DestroyInternal();
86 void CacheStorageChild::NoteDeletedActor() {
87 // Check to see if DestroyInternal was delayed because of active CacheOpChilds
88 // when StartDestroy was called from WorkerRef notification. If the last
89 // CacheOpChild is getting destructed; it's the time for us to SendTearDown to
90 // the other side.
91 if (NumChildActors() == 0 && mDelayedDestroy) DestroyInternal();
94 void CacheStorageChild::ActorDestroy(ActorDestroyReason aReason) {
95 NS_ASSERT_OWNINGTHREAD(CacheStorageChild);
96 RefPtr<CacheStorage> listener = mListener;
97 if (listener) {
98 listener->DestroyInternal(this);
99 // CacheStorage listener should call ClearListener() in DestroyInternal()
100 MOZ_DIAGNOSTIC_ASSERT(!mListener);
103 RemoveWorkerRef();
106 PCacheOpChild* CacheStorageChild::AllocPCacheOpChild(
107 const CacheOpArgs& aOpArgs) {
108 MOZ_CRASH("CacheOpChild should be manually constructed.");
109 return nullptr;
111 } // namespace mozilla::dom::cache