Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / locks / LockManager.h
blob19313ef6b87efb0ca31577406e05d3acedea0186
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;
28 struct LockOptions;
30 namespace locks {
31 class LockManagerChild;
34 class LockManager final : public nsISupports, public nsWrapperCache {
35 public:
36 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
37 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(LockManager)
39 private:
40 explicit LockManager(nsIGlobalObject* aGlobal);
42 public:
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,
52 ErrorResult& aRv);
53 already_AddRefed<Promise> Request(const nsAString& aName,
54 const LockOptions& aOptions,
55 LockGrantedCallback& aCallback,
56 ErrorResult& aRv);
58 already_AddRefed<Promise> Query(ErrorResult& aRv);
60 void Shutdown();
62 private:
63 ~LockManager() = default;
65 nsCOMPtr<nsIGlobalObject> mOwner;
66 RefPtr<locks::LockManagerChild> mActor;
68 // Revokes itself and triggers LockManagerChild deletion on worker shutdown
69 // callback.
70 RefPtr<WeakWorkerRef> mWorkerRef;
73 } // namespace mozilla::dom
75 #endif // mozilla_dom_LockManager_h