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/ActorChild.h"
8 
9 #include "mozilla/dom/cache/CacheWorkerHolder.h"
10 #include "nsThreadUtils.h"
11 
12 namespace mozilla {
13 namespace dom {
14 namespace cache {
15 
SetWorkerHolder(CacheWorkerHolder * aWorkerHolder)16 void ActorChild::SetWorkerHolder(CacheWorkerHolder* aWorkerHolder) {
17   // Some of the Cache actors can have multiple DOM objects associated with
18   // them.  In this case the workerHolder will be added multiple times.  This is
19   // permitted, but the workerHolder should be the same each time.
20   if (mWorkerHolder) {
21     MOZ_DIAGNOSTIC_ASSERT(mWorkerHolder == aWorkerHolder);
22     return;
23   }
24 
25   mWorkerHolder = aWorkerHolder;
26   if (mWorkerHolder) {
27     mWorkerHolder->AddActor(this);
28   }
29 }
30 
RemoveWorkerHolder()31 void ActorChild::RemoveWorkerHolder() {
32   MOZ_ASSERT_IF(!NS_IsMainThread(), mWorkerHolder);
33   if (mWorkerHolder) {
34     mWorkerHolder->RemoveActor(this);
35     mWorkerHolder = nullptr;
36   }
37 }
38 
GetWorkerHolder() const39 CacheWorkerHolder* ActorChild::GetWorkerHolder() const { return mWorkerHolder; }
40 
WorkerHolderNotified() const41 bool ActorChild::WorkerHolderNotified() const {
42   return mWorkerHolder && mWorkerHolder->Notified();
43 }
44 
ActorChild()45 ActorChild::ActorChild() {}
46 
~ActorChild()47 ActorChild::~ActorChild() { MOZ_DIAGNOSTIC_ASSERT(!mWorkerHolder); }
48 
49 }  // namespace cache
50 }  // namespace dom
51 }  // namespace mozilla
52