1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
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 #ifndef mozilla_dom_LockManager_h
8 #define mozilla_dom_LockManager_h
10 #include "js/TypeDecls.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/ErrorResult.h"
13 #include "mozilla/dom/BindingDeclarations.h"
14 #include "mozilla/dom/Lock.h"
15 #include "mozilla/dom/LockManagerBinding.h"
16 #include "mozilla/dom/WorkerRef.h"
17 #include "nsCycleCollectionParticipant.h"
18 #include "nsHashKeys.h"
19 #include "nsTHashMap.h"
20 #include "nsTHashSet.h"
21 #include "nsWrapperCache.h"
23 class nsIGlobalObject
;
25 namespace mozilla::dom
{
27 class LockGrantedCallback
;
31 class LockManagerChild
;
34 class LockManager final
: public nsISupports
, public nsWrapperCache
{
36 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
37 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(LockManager
)
40 explicit LockManager(nsIGlobalObject
* aGlobal
);
43 static already_AddRefed
<LockManager
> Create(nsIGlobalObject
& aGlobal
);
45 nsIGlobalObject
* GetParentObject() const { return mOwner
; }
47 JSObject
* WrapObject(JSContext
* aCx
,
48 JS::Handle
<JSObject
*> aGivenProto
) override
;
50 already_AddRefed
<Promise
> Request(const nsAString
& aName
,
51 LockGrantedCallback
& aCallback
,
53 already_AddRefed
<Promise
> Request(const nsAString
& aName
,
54 const LockOptions
& aOptions
,
55 LockGrantedCallback
& aCallback
,
58 already_AddRefed
<Promise
> Query(ErrorResult
& aRv
);
63 ~LockManager() = default;
65 nsCOMPtr
<nsIGlobalObject
> mOwner
;
66 RefPtr
<locks::LockManagerChild
> mActor
;
68 // Revokes itself and triggers LockManagerChild deletion on worker shutdown
70 RefPtr
<WeakWorkerRef
> mWorkerRef
;
73 } // namespace mozilla::dom
75 #endif // mozilla_dom_LockManager_h