Introduce GlobalScope::scheduler_chan

This commit is contained in:
Anthony Ramine 2016-10-01 16:02:20 +02:00
parent f789e73fd2
commit c6ff767625
4 changed files with 23 additions and 32 deletions

View file

@ -16,7 +16,6 @@ use dom::bindings::reflector::{Reflectable, Reflector};
use dom::globalscope::GlobalScope;
use dom::window;
use dom::workerglobalscope::WorkerGlobalScope;
use ipc_channel::ipc::IpcSender;
use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL};
use js::glue::{IsWrapper, UnwrapObject};
use js::jsapi::{CurrentGlobalOrNull, Evaluate2, GetGlobalForObjectCrossCompartment};
@ -30,7 +29,7 @@ use profile_traits::time;
use script_runtime::{CommonScriptMsg, EnqueuedPromiseCallback, ScriptChan};
use script_runtime::{ScriptPort, maybe_take_panic_result};
use script_thread::{MainThreadScriptChan, RunnableWrapper, ScriptThread};
use script_traits::{MsDuration, TimerEventRequest};
use script_traits::MsDuration;
use std::ffi::CString;
use std::panic;
use task_source::file_reading::FileReadingTaskSource;
@ -89,14 +88,6 @@ impl<'a> GlobalRef<'a> {
}
}
/// Get the scheduler channel to request timer events.
pub fn scheduler_chan(&self) -> &IpcSender<TimerEventRequest> {
match *self {
GlobalRef::Window(window) => window.scheduler_chan(),
GlobalRef::Worker(worker) => worker.scheduler_chan(),
}
}
/// Get the `ResourceThreads` for this global scope.
pub fn resource_threads(&self) -> ResourceThreads {
match *self {

View file

@ -12,7 +12,7 @@ use dom::eventtarget::EventTarget;
use ipc_channel::ipc::IpcSender;
use js::jsapi::{JS_GetContext, JS_GetObjectRuntime, JSContext};
use profile_traits::{mem, time};
use script_traits::ScriptMsg as ConstellationMsg;
use script_traits::{ScriptMsg as ConstellationMsg, TimerEventRequest};
use std::cell::Cell;
use std::collections::HashMap;
use std::collections::hash_map::Entry;
@ -46,6 +46,9 @@ pub struct GlobalScope {
/// A handle for communicating messages to the constellation thread.
#[ignore_heap_size_of = "channels are hard"]
constellation_chan: IpcSender<ConstellationMsg>,
#[ignore_heap_size_of = "channels are hard"]
scheduler_chan: IpcSender<TimerEventRequest>,
}
impl GlobalScope {
@ -53,7 +56,8 @@ impl GlobalScope {
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
mem_profiler_chan: mem::ProfilerChan,
time_profiler_chan: time::ProfilerChan,
constellation_chan: IpcSender<ConstellationMsg>)
constellation_chan: IpcSender<ConstellationMsg>,
scheduler_chan: IpcSender<TimerEventRequest>)
-> Self {
GlobalScope {
eventtarget: EventTarget::new_inherited(),
@ -65,6 +69,7 @@ impl GlobalScope {
mem_profiler_chan: mem_profiler_chan,
time_profiler_chan: time_profiler_chan,
constellation_chan: constellation_chan,
scheduler_chan: scheduler_chan,
}
}
@ -140,6 +145,10 @@ impl GlobalScope {
pub fn constellation_chan(&self) -> &IpcSender<ConstellationMsg> {
&self.constellation_chan
}
pub fn scheduler_chan(&self) -> &IpcSender<TimerEventRequest> {
&self.scheduler_chan
}
}
fn timestamp_in_ms(time: Timespec) -> u64 {

View file

@ -170,8 +170,6 @@ pub struct Window {
session_storage: MutNullableHeap<JS<Storage>>,
local_storage: MutNullableHeap<JS<Storage>>,
status: DOMRefCell<DOMString>,
#[ignore_heap_size_of = "channels are hard"]
scheduler_chan: IpcSender<TimerEventRequest>,
timers: OneshotTimers,
/// For sending timeline markers. Will be ignored if
@ -1387,10 +1385,6 @@ impl Window {
&self.layout_chan
}
pub fn scheduler_chan(&self) -> &IpcSender<TimerEventRequest> {
&self.scheduler_chan
}
pub fn schedule_callback(&self, callback: OneshotTimerCallback, duration: MsDuration) -> OneshotTimerHandle {
self.timers.schedule_callback(callback,
duration,
@ -1594,7 +1588,11 @@ impl Window {
let win = box Window {
globalscope:
GlobalScope::new_inherited(
devtools_chan, mem_profiler_chan, time_profiler_chan, constellation_chan),
devtools_chan,
mem_profiler_chan,
time_profiler_chan,
constellation_chan,
scheduler_chan.clone()),
script_chan: script_chan,
dom_manipulation_task_source: dom_task_source,
user_interaction_task_source: user_task_source,
@ -1613,7 +1611,6 @@ impl Window {
session_storage: Default::default(),
local_storage: Default::default(),
status: DOMRefCell::new(DOMString::new()),
scheduler_chan: scheduler_chan.clone(),
timers: OneshotTimers::new(timer_event_chan, scheduler_chan),
id: id,
parent_info: parent_info,

View file

@ -38,7 +38,7 @@ use net_traits::{LoadContext, ResourceThreads, load_whole_resource};
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, maybe_take_panic_result};
use script_runtime::{ScriptThreadEventCategory, PromiseJobQueue, EnqueuedPromiseCallback};
use script_thread::{Runnable, RunnableWrapper};
use script_traits::{MsDuration, TimerEvent, TimerEventId, TimerEventRequest, TimerSource};
use script_traits::{MsDuration, TimerEvent, TimerEventId, TimerSource};
use script_traits::WorkerGlobalScopeInit;
use std::cell::Cell;
use std::default::Default;
@ -59,6 +59,7 @@ pub fn prepare_workerscope_init(global: GlobalRef,
let mem_profiler_chan = global_scope.mem_profiler_chan().clone();
let time_profiler_chan = global_scope.time_profiler_chan().clone();
let constellation_chan = global_scope.constellation_chan().clone();
let scheduler_chan = global_scope.scheduler_chan().clone();
let init = WorkerGlobalScopeInit {
resource_threads: global.resource_threads(),
mem_profiler_chan: mem_profiler_chan,
@ -66,7 +67,7 @@ pub fn prepare_workerscope_init(global: GlobalRef,
time_profiler_chan: time_profiler_chan,
from_devtools_sender: devtools_sender,
constellation_chan: constellation_chan,
scheduler_chan: global.scheduler_chan().clone(),
scheduler_chan: scheduler_chan,
worker_id: worker_id,
pipeline_id: global.pipeline_id(),
};
@ -102,9 +103,6 @@ pub struct WorkerGlobalScope {
/// `IpcSender` doesn't exist
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
#[ignore_heap_size_of = "Defined in std"]
scheduler_chan: IpcSender<TimerEventRequest>,
promise_job_queue: PromiseJobQueue,
/// https://html.spec.whatwg.org/multipage/#in-error-reporting-mode
@ -125,7 +123,8 @@ impl WorkerGlobalScope {
init.to_devtools_sender,
init.mem_profiler_chan,
init.time_profiler_chan,
init.constellation_chan),
init.constellation_chan,
init.scheduler_chan.clone()),
worker_id: init.worker_id,
pipeline_id: init.pipeline_id,
worker_url: worker_url,
@ -134,10 +133,9 @@ impl WorkerGlobalScope {
resource_threads: init.resource_threads,
location: Default::default(),
navigator: Default::default(),
timers: OneshotTimers::new(timer_event_chan, init.scheduler_chan.clone()),
timers: OneshotTimers::new(timer_event_chan, init.scheduler_chan),
from_devtools_sender: init.from_devtools_sender,
from_devtools_receiver: from_devtools_receiver,
scheduler_chan: init.scheduler_chan,
promise_job_queue: PromiseJobQueue::new(),
in_error_reporting_mode: Default::default(),
}
@ -151,10 +149,6 @@ impl WorkerGlobalScope {
&self.from_devtools_receiver
}
pub fn scheduler_chan(&self) -> &IpcSender<TimerEventRequest> {
&self.scheduler_chan
}
pub fn schedule_callback(&self, callback: OneshotTimerCallback, duration: MsDuration) -> OneshotTimerHandle {
self.timers.schedule_callback(callback,
duration,