Move workers' pipeline IDs to WorkerGlobalScope

This commit is contained in:
Anthony Ramine 2016-10-01 16:58:36 +02:00
parent fce0a8e7cf
commit 4ccdbccdd7
5 changed files with 11 additions and 35 deletions

View file

@ -81,7 +81,6 @@ enum MixedMessage {
#[dom_struct] #[dom_struct]
pub struct DedicatedWorkerGlobalScope { pub struct DedicatedWorkerGlobalScope {
workerglobalscope: WorkerGlobalScope, workerglobalscope: WorkerGlobalScope,
id: PipelineId,
#[ignore_heap_size_of = "Defined in std"] #[ignore_heap_size_of = "Defined in std"]
receiver: Receiver<(TrustedWorkerAddress, WorkerScriptMsg)>, receiver: Receiver<(TrustedWorkerAddress, WorkerScriptMsg)>,
#[ignore_heap_size_of = "Defined in std"] #[ignore_heap_size_of = "Defined in std"]
@ -100,7 +99,6 @@ pub struct DedicatedWorkerGlobalScope {
impl DedicatedWorkerGlobalScope { impl DedicatedWorkerGlobalScope {
fn new_inherited(init: WorkerGlobalScopeInit, fn new_inherited(init: WorkerGlobalScopeInit,
worker_url: Url, worker_url: Url,
id: PipelineId,
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>, from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
runtime: Runtime, runtime: Runtime,
parent_sender: Box<ScriptChan + Send>, parent_sender: Box<ScriptChan + Send>,
@ -117,7 +115,6 @@ impl DedicatedWorkerGlobalScope {
from_devtools_receiver, from_devtools_receiver,
timer_event_chan, timer_event_chan,
Some(closing)), Some(closing)),
id: id,
receiver: receiver, receiver: receiver,
own_sender: own_sender, own_sender: own_sender,
timer_event_port: timer_event_port, timer_event_port: timer_event_port,
@ -129,7 +126,6 @@ impl DedicatedWorkerGlobalScope {
pub fn new(init: WorkerGlobalScopeInit, pub fn new(init: WorkerGlobalScopeInit,
worker_url: Url, worker_url: Url,
id: PipelineId,
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>, from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
runtime: Runtime, runtime: Runtime,
parent_sender: Box<ScriptChan + Send>, parent_sender: Box<ScriptChan + Send>,
@ -142,7 +138,6 @@ impl DedicatedWorkerGlobalScope {
let cx = runtime.cx(); let cx = runtime.cx();
let scope = box DedicatedWorkerGlobalScope::new_inherited(init, let scope = box DedicatedWorkerGlobalScope::new_inherited(init,
worker_url, worker_url,
id,
from_devtools_receiver, from_devtools_receiver,
runtime, runtime,
parent_sender, parent_sender,
@ -157,7 +152,6 @@ impl DedicatedWorkerGlobalScope {
#[allow(unsafe_code)] #[allow(unsafe_code)]
pub fn run_worker_scope(init: WorkerGlobalScopeInit, pub fn run_worker_scope(init: WorkerGlobalScopeInit,
worker_url: Url, worker_url: Url,
id: PipelineId,
from_devtools_receiver: IpcReceiver<DevtoolScriptControlMsg>, from_devtools_receiver: IpcReceiver<DevtoolScriptControlMsg>,
worker_rt_for_mainthread: Arc<Mutex<Option<SharedRt>>>, worker_rt_for_mainthread: Arc<Mutex<Option<SharedRt>>>,
worker: TrustedWorkerAddress, worker: TrustedWorkerAddress,
@ -170,7 +164,7 @@ impl DedicatedWorkerGlobalScope {
let name = format!("WebWorker for {}", serialized_worker_url); let name = format!("WebWorker for {}", serialized_worker_url);
spawn_named(name, move || { spawn_named(name, move || {
thread_state::initialize(thread_state::SCRIPT | thread_state::IN_WORKER); thread_state::initialize(thread_state::SCRIPT | thread_state::IN_WORKER);
PipelineId::install(id); PipelineId::install(init.pipeline_id);
let roots = RootCollection::new(); let roots = RootCollection::new();
let _stack_roots_tls = StackRootTLS::new(&roots); let _stack_roots_tls = StackRootTLS::new(&roots);
@ -204,7 +198,7 @@ impl DedicatedWorkerGlobalScope {
}); });
let global = DedicatedWorkerGlobalScope::new( let global = DedicatedWorkerGlobalScope::new(
init, url, id, devtools_mpsc_port, runtime, init, url, devtools_mpsc_port, runtime,
parent_sender.clone(), own_sender, receiver, parent_sender.clone(), own_sender, receiver,
timer_ipc_chan, timer_rx, closing); timer_ipc_chan, timer_rx, closing);
// FIXME(njn): workers currently don't have a unique ID suitable for using in reporter // FIXME(njn): workers currently don't have a unique ID suitable for using in reporter
@ -244,10 +238,6 @@ impl DedicatedWorkerGlobalScope {
} }
} }
pub fn pipeline_id(&self) -> PipelineId {
self.id
}
pub fn new_script_pair(&self) -> (Box<ScriptChan + Send>, Box<ScriptPort + Send>) { pub fn new_script_pair(&self) -> (Box<ScriptChan + Send>, Box<ScriptPort + Send>) {
let (tx, rx) = channel(); let (tx, rx) = channel();
let chan = box SendableWorkerScriptChan { let chan = box SendableWorkerScriptChan {

View file

@ -23,7 +23,6 @@ use ipc_channel::router::ROUTER;
use js::jsapi::{JS_SetInterruptCallback, JSAutoCompartment, JSContext}; use js::jsapi::{JS_SetInterruptCallback, JSAutoCompartment, JSContext};
use js::jsval::UndefinedValue; use js::jsval::UndefinedValue;
use js::rust::Runtime; use js::rust::Runtime;
use msg::constellation_msg::PipelineId;
use net_traits::{LoadContext, load_whole_resource, IpcSend, CustomResponseMediator}; use net_traits::{LoadContext, load_whole_resource, IpcSend, CustomResponseMediator};
use rand::random; use rand::random;
use script_runtime::{CommonScriptMsg, StackRootTLS, get_reports, new_rt_and_cx, ScriptChan}; use script_runtime::{CommonScriptMsg, StackRootTLS, get_reports, new_rt_and_cx, ScriptChan};
@ -72,7 +71,6 @@ impl ScriptChan for ServiceWorkerChan {
#[dom_struct] #[dom_struct]
pub struct ServiceWorkerGlobalScope { pub struct ServiceWorkerGlobalScope {
workerglobalscope: WorkerGlobalScope, workerglobalscope: WorkerGlobalScope,
id: PipelineId,
#[ignore_heap_size_of = "Defined in std"] #[ignore_heap_size_of = "Defined in std"]
receiver: Receiver<ServiceWorkerScriptMsg>, receiver: Receiver<ServiceWorkerScriptMsg>,
#[ignore_heap_size_of = "Defined in std"] #[ignore_heap_size_of = "Defined in std"]
@ -87,7 +85,6 @@ pub struct ServiceWorkerGlobalScope {
impl ServiceWorkerGlobalScope { impl ServiceWorkerGlobalScope {
fn new_inherited(init: WorkerGlobalScopeInit, fn new_inherited(init: WorkerGlobalScopeInit,
worker_url: Url, worker_url: Url,
id: PipelineId,
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>, from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
runtime: Runtime, runtime: Runtime,
own_sender: Sender<ServiceWorkerScriptMsg>, own_sender: Sender<ServiceWorkerScriptMsg>,
@ -104,7 +101,6 @@ impl ServiceWorkerGlobalScope {
from_devtools_receiver, from_devtools_receiver,
timer_event_chan, timer_event_chan,
None), None),
id: id,
receiver: receiver, receiver: receiver,
timer_event_port: timer_event_port, timer_event_port: timer_event_port,
own_sender: own_sender, own_sender: own_sender,
@ -115,7 +111,6 @@ impl ServiceWorkerGlobalScope {
pub fn new(init: WorkerGlobalScopeInit, pub fn new(init: WorkerGlobalScopeInit,
worker_url: Url, worker_url: Url,
id: PipelineId,
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>, from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
runtime: Runtime, runtime: Runtime,
own_sender: Sender<ServiceWorkerScriptMsg>, own_sender: Sender<ServiceWorkerScriptMsg>,
@ -128,7 +123,6 @@ impl ServiceWorkerGlobalScope {
let cx = runtime.cx(); let cx = runtime.cx();
let scope = box ServiceWorkerGlobalScope::new_inherited(init, let scope = box ServiceWorkerGlobalScope::new_inherited(init,
worker_url, worker_url,
id,
from_devtools_receiver, from_devtools_receiver,
runtime, runtime,
own_sender, own_sender,
@ -148,7 +142,6 @@ impl ServiceWorkerGlobalScope {
swmanager_sender: IpcSender<ServiceWorkerMsg>, swmanager_sender: IpcSender<ServiceWorkerMsg>,
scope_url: Url) { scope_url: Url) {
let ScopeThings { script_url, let ScopeThings { script_url,
pipeline_id,
init, init,
worker_load_origin, worker_load_origin,
.. } = scope_things; .. } = scope_things;
@ -179,7 +172,7 @@ impl ServiceWorkerGlobalScope {
let (timer_ipc_chan, _timer_ipc_port) = ipc::channel().unwrap(); let (timer_ipc_chan, _timer_ipc_port) = ipc::channel().unwrap();
let (timer_chan, timer_port) = channel(); let (timer_chan, timer_port) = channel();
let global = ServiceWorkerGlobalScope::new( let global = ServiceWorkerGlobalScope::new(
init, url, pipeline_id, devtools_mpsc_port, runtime, init, url, devtools_mpsc_port, runtime,
own_sender, receiver, own_sender, receiver,
timer_ipc_chan, timer_port, swmanager_sender, scope_url); timer_ipc_chan, timer_port, swmanager_sender, scope_url);
let scope = global.upcast::<WorkerGlobalScope>(); let scope = global.upcast::<WorkerGlobalScope>();
@ -298,10 +291,6 @@ impl ServiceWorkerGlobalScope {
} }
} }
pub fn pipeline_id(&self) -> PipelineId {
self.id
}
pub fn process_event(&self, msg: CommonScriptMsg) { pub fn process_event(&self, msg: CommonScriptMsg) {
self.handle_script_event(ServiceWorkerScriptMsg::CommonWorker(WorkerScriptMsg::Common(msg))); self.handle_script_event(ServiceWorkerScriptMsg::CommonWorker(WorkerScriptMsg::Common(msg)));
} }

View file

@ -106,7 +106,7 @@ impl Worker {
let init = prepare_workerscope_init(global, Some(devtools_sender)); let init = prepare_workerscope_init(global, Some(devtools_sender));
DedicatedWorkerGlobalScope::run_worker_scope( DedicatedWorkerGlobalScope::run_worker_scope(
init, worker_url, global.pipeline_id(), devtools_receiver, worker.runtime.clone(), worker_ref, init, worker_url, devtools_receiver, worker.runtime.clone(), worker_ref,
global.script_chan(), sender, receiver, worker_load_origin, closing); global.script_chan(), sender, receiver, worker_load_origin, closing);
Ok(worker) Ok(worker)

View file

@ -66,7 +66,8 @@ pub fn prepare_workerscope_init(global: GlobalRef,
from_devtools_sender: devtools_sender, from_devtools_sender: devtools_sender,
constellation_chan: global.constellation_chan().clone(), constellation_chan: global.constellation_chan().clone(),
scheduler_chan: global.scheduler_chan().clone(), scheduler_chan: global.scheduler_chan().clone(),
worker_id: worker_id worker_id: worker_id,
pipeline_id: global.pipeline_id(),
}; };
init init
@ -77,6 +78,7 @@ pub fn prepare_workerscope_init(global: GlobalRef,
pub struct WorkerGlobalScope { pub struct WorkerGlobalScope {
eventtarget: EventTarget, eventtarget: EventTarget,
worker_id: WorkerId, worker_id: WorkerId,
pipeline_id: PipelineId,
worker_url: Url, worker_url: Url,
closing: Option<Arc<AtomicBool>>, closing: Option<Arc<AtomicBool>>,
#[ignore_heap_size_of = "Defined in js"] #[ignore_heap_size_of = "Defined in js"]
@ -134,6 +136,7 @@ impl WorkerGlobalScope {
eventtarget: EventTarget::new_inherited(), eventtarget: EventTarget::new_inherited(),
next_worker_id: Cell::new(WorkerId(0)), next_worker_id: Cell::new(WorkerId(0)),
worker_id: init.worker_id, worker_id: init.worker_id,
pipeline_id: init.pipeline_id,
worker_url: worker_url, worker_url: worker_url,
closing: closing, closing: closing,
runtime: runtime, runtime: runtime,
@ -447,15 +450,7 @@ impl WorkerGlobalScope {
} }
pub fn pipeline_id(&self) -> PipelineId { pub fn pipeline_id(&self) -> PipelineId {
let dedicated = self.downcast::<DedicatedWorkerGlobalScope>(); self.pipeline_id
let service_worker = self.downcast::<ServiceWorkerGlobalScope>();
if let Some(dedicated) = dedicated {
return dedicated.pipeline_id();
} else if let Some(service_worker) = service_worker {
return service_worker.pipeline_id();
} else {
panic!("need to implement a sender for SharedWorker")
}
} }
pub fn new_script_pair(&self) -> (Box<ScriptChan + Send>, Box<ScriptPort + Send>) { pub fn new_script_pair(&self) -> (Box<ScriptChan + Send>, Box<ScriptPort + Send>) {

View file

@ -663,6 +663,8 @@ pub struct WorkerGlobalScopeInit {
pub scheduler_chan: IpcSender<TimerEventRequest>, pub scheduler_chan: IpcSender<TimerEventRequest>,
/// The worker id /// The worker id
pub worker_id: WorkerId, pub worker_id: WorkerId,
/// The pipeline id
pub pipeline_id: PipelineId,
} }
/// Common entities representing a network load origin /// Common entities representing a network load origin