tor-browser

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

WorkerEventTarget.h (1708B)


      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
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_dom_WorkerEventTarget_h
      8 #define mozilla_dom_WorkerEventTarget_h
      9 
     10 #include "mozilla/Mutex.h"
     11 #include "mozilla/dom/WorkerPrivate.h"
     12 #include "nsISerialEventTarget.h"
     13 
     14 namespace mozilla::dom {
     15 
     16 class WorkerEventTarget final : public nsISerialEventTarget {
     17 public:
     18  // The WorkerEventTarget supports different dispatch behaviors:
     19  //
     20  // * Hybrid targets will attempt to dispatch as a normal runnable,
     21  //   but fallback to a control runnable if that fails.  This is
     22  //   often necessary for code that wants normal dispatch order, but
     23  //   also needs to execute while the worker is shutting down (possibly
     24  //   with a holder in place.)
     25  //
     26  // * ControlOnly targets will simply dispatch a control runnable.
     27  //
     28  // * DebuggerOnly targets will simply dispatch a debugger runnable.
     29  enum class Behavior : uint8_t { Hybrid, ControlOnly, DebuggerOnly };
     30 
     31 private:
     32  mozilla::Mutex mMutex;
     33  CheckedUnsafePtr<WorkerPrivate> mWorkerPrivate MOZ_GUARDED_BY(mMutex);
     34  const Behavior mBehavior MOZ_GUARDED_BY(mMutex);
     35 
     36  ~WorkerEventTarget() = default;
     37 
     38 public:
     39  WorkerEventTarget(WorkerPrivate* aWorkerPrivate, Behavior aBehavior);
     40 
     41  void ForgetWorkerPrivate(WorkerPrivate* aWorkerPrivate);
     42 
     43  NS_DECL_THREADSAFE_ISUPPORTS
     44  NS_DECL_NSIEVENTTARGET
     45  NS_DECL_NSISERIALEVENTTARGET
     46 };
     47 
     48 }  // namespace mozilla::dom
     49 
     50 #endif  // mozilla_dom_WorkerEventTarget_h