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_CacheWorkerRef_h
8 #define mozilla_dom_cache_CacheWorkerRef_h
9 
10 #include "mozilla/dom/SafeRefPtr.h"
11 #include "nsISupportsImpl.h"
12 #include "nsTArray.h"
13 
14 namespace mozilla {
15 namespace dom {
16 
17 class IPCWorkerRef;
18 class StrongWorkerRef;
19 class WorkerPrivate;
20 
21 namespace cache {
22 
23 class ActorChild;
24 
25 class CacheWorkerRef final : public SafeRefCounted<CacheWorkerRef> {
26  public:
27   enum Behavior {
28     eStrongWorkerRef,
29     eIPCWorkerRef,
30   };
31 
32   static SafeRefPtr<CacheWorkerRef> Create(WorkerPrivate* aWorkerPrivate,
33                                            Behavior aBehavior);
34 
35   static SafeRefPtr<CacheWorkerRef> PreferBehavior(
36       SafeRefPtr<CacheWorkerRef> aCurrentRef, Behavior aBehavior);
37 
38   void AddActor(ActorChild& aActor);
39   void RemoveActor(ActorChild& aActor);
40 
41   bool Notified() const;
42 
43  private:
44   struct ConstructorGuard {};
45 
46   void Notify();
47 
48   nsTArray<NotNull<ActorChild*>> mActorList;
49 
50   Behavior mBehavior;
51   bool mNotified;
52 
53   RefPtr<StrongWorkerRef> mStrongWorkerRef;
54   RefPtr<IPCWorkerRef> mIPCWorkerRef;
55 
56  public:
57   CacheWorkerRef(Behavior aBehavior, ConstructorGuard);
58 
59   ~CacheWorkerRef();
60 
61   NS_DECL_OWNINGTHREAD
62   MOZ_DECLARE_REFCOUNTED_TYPENAME(mozilla::dom::cache::CacheWorkerRef)
63 };
64 
65 }  // namespace cache
66 }  // namespace dom
67 }  // namespace mozilla
68 
69 #endif  // mozilla_dom_cache_CacheWorkerRef_h
70