Introduce MainThreadScriptMsg::DispatchJobQueue

This removes the last remaining use of Task::run_with_script_thread
This commit is contained in:
Anthony Ramine 2017-09-17 10:46:00 +02:00
parent 1d52df0562
commit 8e78f18d2d
4 changed files with 16 additions and 67 deletions

View file

@ -114,7 +114,7 @@ impl ServiceWorkerContainerMethods for ServiceWorkerContainer {
// B: Step 8
let job = Job::create_job(JobType::Register, scope, script_url, promise.clone(), &*self.client);
ScriptThread::schedule_job(job, &*self.global());
ScriptThread::schedule_job(job);
promise
}
}

View file

@ -244,12 +244,6 @@ impl<T> Task for CancellableTask<T>
where
T: Send + Task,
{
fn run_with_script_thread(self: Box<CancellableTask<T>>, script_thread: &ScriptThread) {
if !self.is_cancelled() {
self.inner.run_with_script_thread(script_thread);
}
}
fn run(self: Box<Self>) {
if !self.is_cancelled() {
self.inner.run()
@ -259,12 +253,7 @@ where
pub trait Task {
fn name(&self) -> &'static str { unsafe { intrinsics::type_name::<Self>() } }
fn run(self: Box<Self>) {
panic!("This should probably be redefined.")
}
fn run_with_script_thread(self: Box<Self>, _script_thread: &ScriptThread) {
self.run();
}
fn run(self: Box<Self>);
}
impl fmt::Debug for Task + Send {
@ -304,8 +293,8 @@ pub enum MainThreadScriptMsg {
properties: Vec<Atom>,
painter: Box<Painter>
},
/// Runs a Task in the main thread.
MainThreadTask(ScriptThreadEventCategory, Box<Task + Send>),
/// Dispatches a job queue.
DispatchJobQueue { scope_url: ServoUrl },
}
impl OpaqueSender<CommonScriptMsg> for Box<ScriptChan + Send> {
@ -718,11 +707,11 @@ impl ScriptThread {
}
#[allow(unrooted_must_root)]
pub fn schedule_job(job: Job, global: &GlobalScope) {
pub fn schedule_job(job: Job) {
SCRIPT_THREAD_ROOT.with(|root| {
let script_thread = unsafe { &*root.get().unwrap() };
let job_queue = &*script_thread.job_queue_map;
job_queue.schedule_job(job, global, &script_thread);
job_queue.schedule_job(job, &script_thread);
});
}
@ -1192,8 +1181,9 @@ impl ScriptThread {
MixedMessage::FromImageCache(_) => ScriptThreadEventCategory::ImageCacheMsg,
MixedMessage::FromScript(ref inner_msg) => {
match *inner_msg {
MainThreadScriptMsg::Common(CommonScriptMsg::Task(category, _)) |
MainThreadScriptMsg::MainThreadTask(category, _) => category,
MainThreadScriptMsg::Common(CommonScriptMsg::Task(category, _)) => {
category
},
MainThreadScriptMsg::RegisterPaintWorklet { .. } => {
ScriptThreadEventCategory::WorkletEvent
},
@ -1348,9 +1338,9 @@ impl ScriptThread {
painter,
)
},
MainThreadScriptMsg::MainThreadTask(_, task) => {
task.run_with_script_thread(self)
},
MainThreadScriptMsg::DispatchJobQueue { scope_url } => {
self.job_queue_map.run_job(scope_url, self)
}
}
}
@ -1787,8 +1777,8 @@ impl ScriptThread {
let _ = self.script_sender.send((pipeline_id, ScriptMsg::RegisterServiceWorker(scope_things, scope.clone())));
}
pub fn dispatch_job_queue(&self, scope_url: ServoUrl) {
self.job_queue_map.run_job(scope_url, self);
pub fn schedule_job_queue(&self, scope_url: ServoUrl) {
let _ = self.chan.0.send(MainThreadScriptMsg::DispatchJobQueue { scope_url });
}
pub fn dom_manipulation_task_source(&self) -> &DOMManipulationTaskSource {

View file

@ -93,25 +93,6 @@ impl PartialEq for Job {
}
}
pub struct AsyncJobHandler {
pub scope_url: ServoUrl,
}
impl AsyncJobHandler {
fn new(scope_url: ServoUrl) -> AsyncJobHandler {
AsyncJobHandler {
scope_url: scope_url,
}
}
}
impl Task for AsyncJobHandler {
#[allow(unrooted_must_root)]
fn run_with_script_thread(self: Box<AsyncJobHandler>, script_thread: &ScriptThread) {
script_thread.dispatch_job_queue(self.scope_url);
}
}
#[must_root]
#[derive(JSTraceable)]
pub struct JobQueue(pub DOMRefCell<HashMap<ServoUrl, Vec<Job>>>);
@ -122,10 +103,7 @@ impl JobQueue {
}
#[allow(unrooted_must_root)]
// https://w3c.github.io/ServiceWorker/#schedule-job-algorithm
pub fn schedule_job(&self,
job: Job,
global: &GlobalScope,
script_thread: &ScriptThread) {
pub fn schedule_job(&self, job: Job, script_thread: &ScriptThread) {
debug!("scheduling {:?} job", job.job_type);
let mut queue_ref = self.0.borrow_mut();
let job_queue = queue_ref.entry(job.scope_url.clone()).or_insert(vec![]);
@ -133,10 +111,7 @@ impl JobQueue {
if job_queue.is_empty() {
let scope_url = job.scope_url.clone();
job_queue.push(job);
let _ = script_thread.dom_manipulation_task_source().queue_main_thread_task(
box AsyncJobHandler::new(scope_url),
global,
);
let _ = script_thread.schedule_job_queue(scope_url);
debug!("queued task to run newly-queued job");
} else {
// Step 2

View file

@ -6,7 +6,6 @@ use dom::bindings::inheritance::Castable;
use dom::bindings::refcounted::Trusted;
use dom::event::{EventBubbles, EventCancelable, EventTask, SimpleEventTask};
use dom::eventtarget::EventTarget;
use dom::globalscope::GlobalScope;
use dom::window::Window;
use script_runtime::{CommonScriptMsg, ScriptThreadEventCategory};
use script_thread::{MainThreadScriptMsg, Task, TaskCanceller};
@ -43,21 +42,6 @@ impl TaskSource for DOMManipulationTaskSource {
}
impl DOMManipulationTaskSource {
pub fn queue_main_thread_task<T>(
&self,
task: Box<T>,
global: &GlobalScope,
) -> Result<(), ()>
where
T: Task + Send + 'static,
{
let msg = MainThreadScriptMsg::MainThreadTask(
ScriptThreadEventCategory::ScriptEvent,
global.task_canceller().wrap_task(task),
);
self.0.send(msg).map_err(|_| ())
}
pub fn queue_event(&self,
target: &EventTarget,
name: Atom,