Remove uses of AsyncJobHandler from script_thread

This commit is contained in:
Anthony Ramine 2017-09-17 10:27:02 +02:00
parent f58207b851
commit 1d52df0562
2 changed files with 11 additions and 13 deletions

View file

@ -98,7 +98,7 @@ use script_traits::{UpdatePipelineIdReason, WindowSizeData, WindowSizeType};
use script_traits::CompositorEvent::{KeyEvent, MouseButtonEvent, MouseMoveEvent, ResizeEvent};
use script_traits::CompositorEvent::{TouchEvent, TouchpadPressureEvent};
use script_traits::webdriver_msg::WebDriverScriptCommand;
use serviceworkerjob::{Job, JobQueue, AsyncJobHandler};
use serviceworkerjob::{Job, JobQueue};
use servo_atoms::Atom;
use servo_config::opts;
use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
@ -1787,8 +1787,8 @@ impl ScriptThread {
let _ = self.script_sender.send((pipeline_id, ScriptMsg::RegisterServiceWorker(scope_things, scope.clone())));
}
pub fn dispatch_job_queue(&self, job_handler: Box<AsyncJobHandler>) {
self.job_queue_map.run_job(job_handler, self);
pub fn dispatch_job_queue(&self, scope_url: ServoUrl) {
self.job_queue_map.run_job(scope_url, self);
}
pub fn dom_manipulation_task_source(&self) -> &DOMManipulationTaskSource {

View file

@ -108,7 +108,7 @@ impl AsyncJobHandler {
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);
script_thread.dispatch_job_queue(self.scope_url);
}
}
@ -157,30 +157,29 @@ impl JobQueue {
#[allow(unrooted_must_root)]
// https://w3c.github.io/ServiceWorker/#run-job-algorithm
pub fn run_job(&self, run_job_handler: Box<AsyncJobHandler>, script_thread: &ScriptThread) {
pub fn run_job(&self, scope_url: ServoUrl, script_thread: &ScriptThread) {
debug!("running a job");
let url = {
let queue_ref = self.0.borrow();
let front_job = {
let job_vec = queue_ref.get(&run_job_handler.scope_url);
let job_vec = queue_ref.get(&scope_url);
job_vec.unwrap().first().unwrap()
};
let scope_url = front_job.scope_url.clone();
let front_scope_url = front_job.scope_url.clone();
match front_job.job_type {
JobType::Register => self.run_register(front_job, run_job_handler, script_thread),
JobType::Register => self.run_register(front_job, scope_url, script_thread),
JobType::Update => self.update(front_job, script_thread),
JobType::Unregister => unreachable!(),
};
scope_url
front_scope_url
};
self.finish_job(url, script_thread);
}
#[allow(unrooted_must_root)]
// https://w3c.github.io/ServiceWorker/#register-algorithm
fn run_register(&self, job: &Job, register_job_handler: Box<AsyncJobHandler>, script_thread: &ScriptThread) {
fn run_register(&self, job: &Job, scope_url: ServoUrl, script_thread: &ScriptThread) {
debug!("running register job");
let AsyncJobHandler { scope_url, .. } = *register_job_handler;
// Step 1-3
if !UrlHelper::is_origin_trustworthy(&job.script_url) {
// Step 1.1
@ -239,8 +238,7 @@ impl JobQueue {
if run_job {
debug!("further jobs in queue after finishing");
let handler = box AsyncJobHandler::new(scope_url);
self.run_job(handler, script_thread);
self.run_job(scope_url, script_thread);
}
}