1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=2:tabstop=2:
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/. */
8 #include "mozilla/TaskController.h"
9 #include "mozilla/dom/TimeoutManager.h"
11 #include "nsContentUtils.h"
12 #include "WebTaskSchedulerMainThread.h"
14 namespace mozilla::dom
{
16 NS_IMETHODIMP
WebTaskMainThreadRunnable::Run() {
18 RefPtr
<WebTask
> task
= mScheduler
->GetNextTask();
26 nsresult
WebTaskSchedulerMainThread::SetTimeoutForDelayedTask(WebTask
* aTask
,
28 JSContext
* cx
= nsContentUtils::GetCurrentJSContext();
30 return NS_ERROR_UNEXPECTED
;
32 nsIGlobalObject
* global
= GetParentObject();
35 RefPtr
<DelayedWebTaskHandler
> handler
=
36 new DelayedWebTaskHandler(cx
, this, aTask
);
38 int32_t delay
= aDelay
> INT32_MAX
? INT32_MAX
: (int32_t)aDelay
;
41 return global
->AsInnerWindow()->TimeoutManager().SetTimeout(
42 handler
, delay
, /* aIsInterval */ false,
43 Timeout::Reason::eDelayedWebTaskTimeout
, &handle
);
46 bool WebTaskSchedulerMainThread::DispatchEventLoopRunnable() {
47 RefPtr
<WebTaskMainThreadRunnable
> runnable
=
48 new WebTaskMainThreadRunnable(this);
50 MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThreadQueue(runnable
.forget(),
51 EventQueuePriority::Normal
));
54 } // namespace mozilla::dom