aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/timers.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2019-11-26 16:26:20 -0500
committerGitHub <noreply@github.com>2019-11-26 16:26:20 -0500
commita922c497fade0250123b86d7535838c9a8d3b0af (patch)
tree58d60290dab73537d294c8a81dbef091279dc01a /components/script/timers.rs
parent8e0aa68aaafd96abc589f185f7f863f96c553e26 (diff)
parent50a7111eb65155fc7a0bdb1646c4a2e0ebdd8f90 (diff)
downloadservo-a922c497fade0250123b86d7535838c9a8d3b0af.tar.gz
servo-a922c497fade0250123b86d7535838c9a8d3b0af.zip
Auto merge of #24758 - gterzian:impl_timer_task_source, r=nox
Implement timer-task-source, time-out service worker <!-- Please describe your changes on the following line: --> Implements the timer task-source, and folds the IPC glue-code into a single route set by the globalscope. Also switches service worker to using a dedicated "time-out" mechanism, which previously relied on the timer mechanism(and I think didn't actually implement script timers). --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #24747 (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Diffstat (limited to 'components/script/timers.rs')
-rw-r--r--components/script/timers.rs25
1 files changed, 18 insertions, 7 deletions
diff --git a/components/script/timers.rs b/components/script/timers.rs
index f65d1013f48..4be6f822263 100644
--- a/components/script/timers.rs
+++ b/components/script/timers.rs
@@ -34,8 +34,12 @@ pub struct OneshotTimerHandle(i32);
pub struct OneshotTimers {
js_timers: JsTimers,
#[ignore_malloc_size_of = "Defined in std"]
- timer_event_chan: IpcSender<TimerEvent>,
+ /// The sender, to be cloned for each timer,
+ /// on which the timer scheduler in the constellation can send an event
+ /// when the timer is due.
+ timer_event_chan: DomRefCell<Option<IpcSender<TimerEvent>>>,
#[ignore_malloc_size_of = "Defined in std"]
+ /// The sender to the timer scheduler in the constellation.
scheduler_chan: IpcSender<TimerSchedulerMsg>,
next_timer_handle: Cell<OneshotTimerHandle>,
timers: DomRefCell<Vec<OneshotTimer>>,
@@ -109,13 +113,10 @@ impl PartialEq for OneshotTimer {
}
impl OneshotTimers {
- pub fn new(
- timer_event_chan: IpcSender<TimerEvent>,
- scheduler_chan: IpcSender<TimerSchedulerMsg>,
- ) -> OneshotTimers {
+ pub fn new(scheduler_chan: IpcSender<TimerSchedulerMsg>) -> OneshotTimers {
OneshotTimers {
js_timers: JsTimers::new(),
- timer_event_chan: timer_event_chan,
+ timer_event_chan: DomRefCell::new(None),
scheduler_chan: scheduler_chan,
next_timer_handle: Cell::new(OneshotTimerHandle(1)),
timers: DomRefCell::new(Vec::new()),
@@ -125,6 +126,12 @@ impl OneshotTimers {
}
}
+ pub fn setup_scheduling(&self, timer_event_chan: IpcSender<TimerEvent>) {
+ let mut chan = self.timer_event_chan.borrow_mut();
+ assert!(chan.is_none());
+ *chan = Some(timer_event_chan);
+ }
+
pub fn schedule_callback(
&self,
callback: OneshotTimerCallback,
@@ -279,7 +286,10 @@ impl OneshotTimers {
.saturating_sub(precise_time_ms().get()),
);
let request = TimerEventRequest(
- self.timer_event_chan.clone(),
+ self.timer_event_chan
+ .borrow()
+ .clone()
+ .expect("Timer event chan not setup to schedule timers."),
timer.source,
expected_event_id,
delay,
@@ -331,6 +341,7 @@ pub struct JsTimerHandle(i32);
#[derive(DenyPublicFields, JSTraceable, MallocSizeOf)]
pub struct JsTimers {
next_timer_handle: Cell<JsTimerHandle>,
+ /// https://html.spec.whatwg.org/multipage/#list-of-active-timers
active_timers: DomRefCell<HashMap<JsTimerHandle, JsTimerEntry>>,
/// The nesting level of the currently executing timer task or 0.
nesting_level: Cell<u32>,