tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

LockRequestChild.h (2123B)


      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_LOCKREQUESTCHILD_H_
      8 #define DOM_LOCKS_LOCKREQUESTCHILD_H_
      9 
     10 #include "LockManagerChild.h"
     11 #include "mozilla/dom/Lock.h"
     12 #include "mozilla/dom/WorkerRef.h"
     13 #include "mozilla/dom/locks/PLockRequestChild.h"
     14 #include "nsISupportsImpl.h"
     15 
     16 namespace mozilla::dom::locks {
     17 
     18 struct LockRequest {
     19  nsString mName;
     20  RefPtr<Promise> mPromise;
     21  RefPtr<LockGrantedCallback> mCallback;
     22 };
     23 
     24 class LockRequestChild final : public PLockRequestChild,
     25                               public AbortFollower,
     26                               public SupportsWeakPtr {
     27  using IPCResult = mozilla::ipc::IPCResult;
     28 
     29  NS_DECL_ISUPPORTS
     30 
     31 public:
     32  explicit LockRequestChild(
     33      const LockRequest& aRequest,
     34      const Optional<OwningNonNull<AbortSignal>>& aSignal);
     35 
     36  void MaybeSetWorkerRef();
     37 
     38  // TODO: Use MOZ_CAN_RUN_SCRIPT when it gains IPDL support (bug 1539864)
     39  MOZ_CAN_RUN_SCRIPT_BOUNDARY IPCResult RecvResolve(const LockMode& aLockMode,
     40                                                    bool aIsAvailable);
     41  IPCResult Recv__delete__(bool aAborted);
     42 
     43  void ActorDestroy(ActorDestroyReason aReason) final;
     44 
     45  void RunAbortAlgorithm() final;
     46 
     47 private:
     48  ~LockRequestChild() = default;
     49 
     50  LockManagerChild* CastedManager() const;
     51 
     52  const LockRequest mRequest;
     53 
     54  // This prevents the worker from being GC'ed when the caller is waiting to
     55  // acquire the lock and when the lock is held.
     56  //
     57  // The StrongWorkerRef is dropped immediately in the shutdown notification
     58  // callback, and thus does not ensure any cleanup before the worker advances
     59  // to the Killing state. That is ensured instead by
     60  // LockManagerChild::mWorkerRef, see also the details there.
     61  RefPtr<StrongWorkerRef> mWorkerRef;
     62 };
     63 
     64 }  // namespace mozilla::dom::locks
     65 
     66 #endif  // DOM_LOCKS_LOCKREQUESTCHILD_H_