2015-03-02 16:20:00 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/cache/ActorChild.h"
|
|
|
|
|
2019-07-12 14:17:59 +03:00
|
|
|
#include "mozilla/dom/cache/CacheWorkerRef.h"
|
2015-04-16 22:00:16 +03:00
|
|
|
#include "nsThreadUtils.h"
|
2015-03-02 16:20:00 +03:00
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
namespace mozilla::dom::cache {
|
2015-03-02 16:20:00 +03:00
|
|
|
|
2020-05-11 15:12:22 +03:00
|
|
|
void ActorChild::SetWorkerRef(SafeRefPtr<CacheWorkerRef> aWorkerRef) {
|
2015-03-04 17:14:25 +03:00
|
|
|
// Some of the Cache actors can have multiple DOM objects associated with
|
2019-07-12 14:17:59 +03:00
|
|
|
// them. In this case the workerRef will be added multiple times. This is
|
|
|
|
// permitted, but the workerRef should be the same each time.
|
|
|
|
if (mWorkerRef) {
|
2020-05-11 15:12:22 +03:00
|
|
|
// XXX Here, we don't use aWorkerRef, so we unnecessarily add-refed... This
|
|
|
|
// might be a case to show in the raw pointer guideline as a possible
|
|
|
|
// exception, if warranted by performance analyses.
|
|
|
|
|
2019-07-12 14:17:59 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mWorkerRef == aWorkerRef);
|
2015-03-04 17:14:25 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-11 15:12:22 +03:00
|
|
|
mWorkerRef = std::move(aWorkerRef);
|
2019-07-12 14:17:59 +03:00
|
|
|
if (mWorkerRef) {
|
2020-12-17 19:14:52 +03:00
|
|
|
mWorkerRef->AddActor(*this);
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-12 14:17:59 +03:00
|
|
|
void ActorChild::RemoveWorkerRef() {
|
|
|
|
MOZ_ASSERT_IF(!NS_IsMainThread(), mWorkerRef);
|
|
|
|
if (mWorkerRef) {
|
2020-12-17 19:14:52 +03:00
|
|
|
mWorkerRef->RemoveActor(*this);
|
2019-07-12 14:17:59 +03:00
|
|
|
mWorkerRef = nullptr;
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-11 15:12:22 +03:00
|
|
|
const SafeRefPtr<CacheWorkerRef>& ActorChild::GetWorkerRefPtr() const {
|
|
|
|
return mWorkerRef;
|
|
|
|
}
|
2015-03-02 16:20:00 +03:00
|
|
|
|
2019-07-12 14:17:59 +03:00
|
|
|
bool ActorChild::WorkerRefNotified() const {
|
|
|
|
return mWorkerRef && mWorkerRef->Notified();
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
|
2020-02-20 18:49:27 +03:00
|
|
|
ActorChild::ActorChild() = default;
|
2015-03-16 17:10:36 +03:00
|
|
|
|
2019-07-12 14:17:59 +03:00
|
|
|
ActorChild::~ActorChild() { MOZ_DIAGNOSTIC_ASSERT(!mWorkerRef); }
|
2015-03-02 16:20:00 +03:00
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
} // namespace mozilla::dom::cache
|