tor-browser

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

WebTaskSchedulerWorker.h (2171B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim:expandtab:shiftwidth=2:tabstop=2:
      3 */
      4 /* This Source Code Form is subject to the terms of the Mozilla Public
      5 * License, v. 2.0. If a copy of the MPL was not distributed with this
      6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      7 
      8 #ifndef mozilla_dom_WebTaskSchedulerWorker_h
      9 #define mozilla_dom_WebTaskSchedulerWorker_h
     10 
     11 #include "WebTaskScheduler.h"
     12 #include "mozilla/dom/WebTaskSchedulingBinding.h"
     13 #include "mozilla/dom/WorkerPrivate.h"
     14 #include "mozilla/dom/WorkerRef.h"
     15 #include "mozilla/dom/WorkerRunnable.h"
     16 
     17 namespace mozilla::dom {
     18 
     19 class WebTaskWorkerRunnable final : public WorkerSameThreadRunnable {
     20 public:
     21  explicit WebTaskWorkerRunnable(WebTaskSchedulerWorker* aSchedulerWorker);
     22 
     23  MOZ_CAN_RUN_SCRIPT_BOUNDARY
     24  bool WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override;
     25 
     26 private:
     27  ~WebTaskWorkerRunnable() = default;
     28  WeakPtr<WebTaskSchedulerWorker> mSchedulerWorker;
     29 };
     30 
     31 class WebTaskSchedulerWorker final : public WebTaskScheduler {
     32 public:
     33  static RefPtr<WebTaskSchedulerWorker> Create(WorkerPrivate* aWorkerPrivate);
     34 
     35  explicit WebTaskSchedulerWorker(WorkerPrivate* aWorkerPrivate);
     36 
     37  void Disconnect() override;
     38 
     39  void IncreaseNumNormalOrHighPriorityQueuesHaveTaskScheduled() override;
     40  void DecreaseNumNormalOrHighPriorityQueuesHaveTaskScheduled() override;
     41 
     42  bool HasScheduledNormalOrHighPriorityWebTasks() const {
     43    return mNumHighPriorityQueuesHaveTaskScheduled;
     44  }
     45 
     46 private:
     47  ~WebTaskSchedulerWorker() = default;
     48 
     49  nsresult SetTimeoutForDelayedTask(WebTask* aTask, uint64_t aDelay,
     50                                    EventQueuePriority aPriority) override;
     51  bool DispatchEventLoopRunnable(EventQueuePriority aPriority) override;
     52 
     53  RefPtr<StrongWorkerRef> mWorkerRef;
     54  bool mWorkerIsShuttingDown{false};
     55 
     56  // Unlike window global where multiple globals can share the
     57  // same event loop, worker globals don't share event loops,
     58  // so it's okay to have this counter lives inside the
     59  // scheduler for workers.
     60  uint32_t mNumHighPriorityQueuesHaveTaskScheduled = 0;
     61 };
     62 }  // namespace mozilla::dom
     63 #endif