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/. */
7 #ifndef mozilla_dom_timeoutexecutor_h
8 #define mozilla_dom_timeoutexecutor_h
10 #include "mozilla/TimeStamp.h"
12 #include "nsIRunnable.h"
21 class TimeoutExecutor final
: public nsIRunnable
,
22 public nsITimerCallback
,
24 TimeoutManager
* mOwner
;
26 nsCOMPtr
<nsITimer
> mTimer
;
28 uint32_t mMaxIdleDeferMS
;
30 // Limits how far we allow timers to fire into the future from their
31 // deadline. Starts off at zero, but is then adjusted when we start
32 // using nsITimer. The nsITimer implementation may sometimes fire
33 // early and we should allow that to minimize additional wakeups.
34 TimeDuration mAllowedEarlyFiringTime
;
36 // The TimeoutExecutor is repeatedly scheduled by the TimeoutManager
37 // to fire for the next soonest Timeout. Since the executor is re-used
38 // it needs to handle switching between a few states.
40 // None indicates the executor is idle. It may be scheduled or shutdown.
42 // Immediate means the executor is scheduled to run a Timeout with a
43 // deadline that has already expired.
45 // Delayed means the executor is scheduled to run a Timeout with a
46 // deadline in the future.
48 // Shutdown means the TimeoutManager has been destroyed. Once this
49 // state is reached the executor cannot be scheduled again. If the
50 // executor is already dispatched as a runnable or held by a timer then
51 // we may still get a Run()/Notify() call which will be ignored.
59 nsresult
ScheduleImmediate(const TimeStamp
& aDeadline
, const TimeStamp
& aNow
);
61 nsresult
ScheduleDelayed(const TimeStamp
& aDeadline
, const TimeStamp
& aNow
,
62 const TimeDuration
& aMinDelay
);
64 nsresult
Schedule(const TimeStamp
& aDeadline
, const TimeDuration
& aMinDelay
);
66 nsresult
MaybeReschedule(const TimeStamp
& aDeadline
,
67 const TimeDuration
& aMinDelay
);
69 MOZ_CAN_RUN_SCRIPT
void MaybeExecute();
72 TimeoutExecutor(TimeoutManager
* aOwner
, bool aIsIdleQueue
,
73 uint32_t aMaxIdleDeferMS
);
77 nsresult
MaybeSchedule(const TimeStamp
& aDeadline
,
78 const TimeDuration
& aMinDelay
);
84 NS_DECL_NSITIMERCALLBACK
89 } // namespace mozilla
91 #endif // mozilla_dom_timeoutexecutor_h