LockManagerChild.h (2384B)
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 file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef DOM_LOCKS_LOCKMANAGERCHILD_H_ 8 #define DOM_LOCKS_LOCKMANAGERCHILD_H_ 9 10 #include "mozilla/dom/Promise.h" 11 #include "mozilla/dom/WorkerRef.h" 12 #include "mozilla/dom/locks/PLockManagerChild.h" 13 #include "nsIUUIDGenerator.h" 14 15 namespace mozilla::dom::locks { 16 17 struct LockRequest; 18 19 class LockManagerChild final : public PLockManagerChild { 20 public: 21 NS_INLINE_DECL_REFCOUNTING(LockManagerChild) 22 23 static void NotifyBFCacheOnMainThread(nsPIDOMWindowInner* aInner, 24 bool aCreated); 25 26 explicit LockManagerChild(nsIGlobalObject* aOwner); 27 28 nsIGlobalObject* GetParentObject() const { return mOwner; }; 29 30 void RequestLock(const LockRequest& aRequest, const LockOptions& aOptions); 31 32 void NotifyRequestDestroy() const; 33 34 void NotifyToWindow(bool aCreated) const; 35 36 private: 37 ~LockManagerChild() = default; 38 39 nsCOMPtr<nsIGlobalObject> mOwner; 40 41 // This WorkerRef is deleted by destructor. 42 // 43 // Here we want to make sure the IPC layer deletes the actor before allowing 44 // WorkerPrivate deletion, since managed LockRequestChild holds a reference to 45 // global object (currently via mRequest member variable) and thus deleting 46 // the worker first causes an assertion failure. Having this ensures that all 47 // LockRequestChild instances must first have been deleted. 48 // 49 // (Because each LockRequestChild's ActorLifecycleProxy will hold 50 // a strong reference to its manager LockManagerChild's ActorLifecycleProxy, 51 // which means that the LockManagerChild will only be destroyed once all 52 // LockRequestChild instances have been destroyed. At that point, all 53 // references to the global should have been dropped, and then the 54 // LockManagerChild IPCWorkerRef will be dropped and the worker will be able 55 // to transition to the Killing state.) 56 // 57 // ActorDestroy can't release this since it does not guarantee to destruct and 58 // GC the managees (LockRequestChild) immediately. 59 RefPtr<IPCWorkerRef> mWorkerRef; 60 }; 61 62 } // namespace mozilla::dom::locks 63 64 #endif // DOM_LOCKS_LOCKMANAGERCHILD_H_