LockManager.h (2211B)
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/. */ 6 7 #ifndef mozilla_dom_LockManager_h 8 #define mozilla_dom_LockManager_h 9 10 #include "js/TypeDecls.h" 11 #include "mozilla/ErrorResult.h" 12 #include "mozilla/dom/BindingDeclarations.h" 13 #include "mozilla/dom/Lock.h" 14 #include "mozilla/dom/LockManagerBinding.h" 15 #include "mozilla/dom/WorkerRef.h" 16 #include "nsCycleCollectionParticipant.h" 17 #include "nsHashKeys.h" 18 #include "nsTHashMap.h" 19 #include "nsTHashSet.h" 20 #include "nsWrapperCache.h" 21 22 class nsIGlobalObject; 23 24 namespace mozilla::dom { 25 26 class LockGrantedCallback; 27 struct LockOptions; 28 29 namespace locks { 30 class LockManagerChild; 31 } 32 33 class LockManager final : public nsISupports, public nsWrapperCache { 34 public: 35 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 36 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(LockManager) 37 38 private: 39 explicit LockManager(nsIGlobalObject* aGlobal); 40 41 public: 42 static already_AddRefed<LockManager> Create(nsIGlobalObject& aGlobal); 43 44 nsIGlobalObject* GetParentObject() const { return mOwner; } 45 46 JSObject* WrapObject(JSContext* aCx, 47 JS::Handle<JSObject*> aGivenProto) override; 48 49 already_AddRefed<Promise> Request(const nsAString& aName, 50 LockGrantedCallback& aCallback, 51 ErrorResult& aRv); 52 already_AddRefed<Promise> Request(const nsAString& aName, 53 const LockOptions& aOptions, 54 LockGrantedCallback& aCallback, 55 ErrorResult& aRv); 56 57 already_AddRefed<Promise> Query(ErrorResult& aRv); 58 59 void Shutdown(); 60 61 private: 62 ~LockManager() = default; 63 64 nsCOMPtr<nsIGlobalObject> mOwner; 65 RefPtr<locks::LockManagerChild> mActor; 66 67 // Revokes itself and triggers LockManagerChild deletion on worker shutdown 68 // callback. 69 RefPtr<WeakWorkerRef> mWorkerRef; 70 }; 71 72 } // namespace mozilla::dom 73 74 #endif // mozilla_dom_LockManager_h