diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2017-09-16 02:09:26 +0200 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2017-09-16 15:43:26 +0200 |
commit | 56117d31856be46d7df417e659a4406305b4e258 (patch) | |
tree | c3a6b03f1bf9f3b9c8c1a2f67b0a8ac703f93d0a /components/script/task_source | |
parent | 52a6f63608a25e0574fd43b69f404f79a9a6c28f (diff) | |
download | servo-56117d31856be46d7df417e659a4406305b4e258.tar.gz servo-56117d31856be46d7df417e659a4406305b4e258.zip |
Rename Runnable to Task
The changes are:
* `*Runnable` -> `*Task`;
* `RunnableMsg` -> `Task`;
* `RunnableWrapper` -> `TaskCanceller`;
* `MainThreadRunnable` -> `MainThreadTask`;
* `wrap_runnable` -> `wrap_task`;
* `get_runnable_wrapper` -> `task_canceller`;
* `handler` -> `run`;
* `main_thread_handler` -> `run_with_script_thread`.
Diffstat (limited to 'components/script/task_source')
-rw-r--r-- | components/script/task_source/dom_manipulation.rs | 24 | ||||
-rw-r--r-- | components/script/task_source/file_reading.rs | 25 | ||||
-rw-r--r-- | components/script/task_source/mod.rs | 19 | ||||
-rw-r--r-- | components/script/task_source/networking.rs | 30 | ||||
-rw-r--r-- | components/script/task_source/performance_timeline.rs | 32 | ||||
-rw-r--r-- | components/script/task_source/user_interaction.rs | 23 |
6 files changed, 83 insertions, 70 deletions
diff --git a/components/script/task_source/dom_manipulation.rs b/components/script/task_source/dom_manipulation.rs index 636b99f87bf..f7b7a6577f8 100644 --- a/components/script/task_source/dom_manipulation.rs +++ b/components/script/task_source/dom_manipulation.rs @@ -4,11 +4,11 @@ use dom::bindings::inheritance::Castable; use dom::bindings::refcounted::Trusted; -use dom::event::{EventBubbles, EventCancelable, EventRunnable, SimpleEventRunnable}; +use dom::event::{EventBubbles, EventCancelable, EventTask, SimpleEventTask}; use dom::eventtarget::EventTarget; use dom::window::Window; use script_runtime::{CommonScriptMsg, ScriptThreadEventCategory}; -use script_thread::{MainThreadScriptMsg, Runnable, RunnableWrapper}; +use script_thread::{MainThreadScriptMsg, Task, TaskCanceller}; use servo_atoms::Atom; use std::fmt; use std::result::Result; @@ -25,17 +25,17 @@ impl fmt::Debug for DOMManipulationTaskSource { } impl TaskSource for DOMManipulationTaskSource { - fn queue_with_wrapper<T>( + fn queue_with_canceller<T>( &self, msg: Box<T>, - wrapper: &RunnableWrapper, + canceller: &TaskCanceller, ) -> Result<(), ()> where - T: Runnable + Send + 'static, + T: Task + Send + 'static, { - let msg = MainThreadScriptMsg::Common(CommonScriptMsg::RunnableMsg( + let msg = MainThreadScriptMsg::Common(CommonScriptMsg::Task( ScriptThreadEventCategory::ScriptEvent, - wrapper.wrap_runnable(msg), + canceller.wrap_task(msg), )); self.0.send(msg).map_err(|_| ()) } @@ -49,21 +49,17 @@ impl DOMManipulationTaskSource { cancelable: EventCancelable, window: &Window) { let target = Trusted::new(target); - let runnable = box EventRunnable { + let task = box EventTask { target: target, name: name, bubbles: bubbles, cancelable: cancelable, }; - let _ = self.queue(runnable, window.upcast()); + let _ = self.queue(task, window.upcast()); } pub fn queue_simple_event(&self, target: &EventTarget, name: Atom, window: &Window) { let target = Trusted::new(target); - let runnable = box SimpleEventRunnable { - target: target, - name: name, - }; - let _ = self.queue(runnable, window.upcast()); + let _ = self.queue(box SimpleEventTask { target, name }, window.upcast()); } } diff --git a/components/script/task_source/file_reading.rs b/components/script/task_source/file_reading.rs index a1732995fcb..433cc78c260 100644 --- a/components/script/task_source/file_reading.rs +++ b/components/script/task_source/file_reading.rs @@ -5,7 +5,7 @@ use dom::domexception::DOMErrorName; use dom::filereader::{FileReader, TrustedFileReader, GenerationId, ReadMetaData}; use script_runtime::{CommonScriptMsg, ScriptThreadEventCategory, ScriptChan}; -use script_thread::{Runnable, RunnableWrapper}; +use script_thread::{Task, TaskCanceller}; use std::sync::Arc; use task_source::TaskSource; @@ -19,13 +19,18 @@ impl Clone for FileReadingTaskSource { } impl TaskSource for FileReadingTaskSource { - fn queue_with_wrapper<T>(&self, - msg: Box<T>, - wrapper: &RunnableWrapper) - -> Result<(), ()> - where T: Runnable + Send + 'static { - self.0.send(CommonScriptMsg::RunnableMsg(ScriptThreadEventCategory::FileRead, - wrapper.wrap_runnable(msg))) + fn queue_with_canceller<T>( + &self, + msg: Box<T>, + canceller: &TaskCanceller, + ) -> Result<(), ()> + where + T: Send + Task + 'static, + { + self.0.send(CommonScriptMsg::Task( + ScriptThreadEventCategory::FileRead, + canceller.wrap_task(msg), + )) } } @@ -41,8 +46,8 @@ impl FileReadingRunnable { } } -impl Runnable for FileReadingRunnable { - fn handler(self: Box<FileReadingRunnable>) { +impl Task for FileReadingRunnable { + fn run(self: Box<FileReadingRunnable>) { self.task.handle_task(); } } diff --git a/components/script/task_source/mod.rs b/components/script/task_source/mod.rs index ff41a63f118..3dbb753883e 100644 --- a/components/script/task_source/mod.rs +++ b/components/script/task_source/mod.rs @@ -10,16 +10,19 @@ pub mod performance_timeline; pub mod user_interaction; use dom::globalscope::GlobalScope; -use script_thread::{Runnable, RunnableWrapper}; +use script_thread::{Task, TaskCanceller}; use std::result::Result; pub trait TaskSource { - fn queue_with_wrapper<T>(&self, - msg: Box<T>, - wrapper: &RunnableWrapper) - -> Result<(), ()> - where T: Runnable + Send + 'static; - fn queue<T: Runnable + Send + 'static>(&self, msg: Box<T>, global: &GlobalScope) -> Result<(), ()> { - self.queue_with_wrapper(msg, &global.get_runnable_wrapper()) + fn queue_with_canceller<T>( + &self, + msg: Box<T>, + canceller: &TaskCanceller, + ) -> Result<(), ()> + where + T: Send + Task + 'static; + + fn queue<T: Task + Send + 'static>(&self, msg: Box<T>, global: &GlobalScope) -> Result<(), ()> { + self.queue_with_canceller(msg, &global.task_canceller()) } } diff --git a/components/script/task_source/networking.rs b/components/script/task_source/networking.rs index 8306a4789bb..56c583d775f 100644 --- a/components/script/task_source/networking.rs +++ b/components/script/task_source/networking.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use script_runtime::{CommonScriptMsg, ScriptChan, ScriptThreadEventCategory}; -use script_thread::{Runnable, RunnableWrapper}; +use script_thread::{Task, TaskCanceller}; use task_source::TaskSource; #[derive(JSTraceable)] @@ -16,18 +16,28 @@ impl Clone for NetworkingTaskSource { } impl TaskSource for NetworkingTaskSource { - fn queue_with_wrapper<T>(&self, - msg: Box<T>, - wrapper: &RunnableWrapper) - -> Result<(), ()> - where T: Runnable + Send + 'static { - self.0.send(CommonScriptMsg::RunnableMsg(ScriptThreadEventCategory::NetworkEvent, - wrapper.wrap_runnable(msg))) + fn queue_with_canceller<T>( + &self, + msg: Box<T>, + canceller: &TaskCanceller, + ) -> Result<(), ()> + where + T: Send + Task + 'static, + { + self.0.send(CommonScriptMsg::Task( + ScriptThreadEventCategory::NetworkEvent, + canceller.wrap_task(msg), + )) } } impl NetworkingTaskSource { - pub fn queue_wrapperless<T: Runnable + Send + 'static>(&self, msg: Box<T>) -> Result<(), ()> { - self.0.send(CommonScriptMsg::RunnableMsg(ScriptThreadEventCategory::NetworkEvent, msg)) + /// This queues a task that will not be cancelled when its associated + /// global scope gets destroyed. + pub fn queue_unconditionally<T>(&self, msg: Box<T>) -> Result<(), ()> + where + T: Task + Send + 'static, + { + self.0.send(CommonScriptMsg::Task(ScriptThreadEventCategory::NetworkEvent, msg)) } } diff --git a/components/script/task_source/performance_timeline.rs b/components/script/task_source/performance_timeline.rs index 7d77b6b7db7..db80789a206 100644 --- a/components/script/task_source/performance_timeline.rs +++ b/components/script/task_source/performance_timeline.rs @@ -10,25 +10,25 @@ use dom::bindings::refcounted::Trusted; use dom::globalscope::GlobalScope; use dom::performance::Performance; use script_runtime::{CommonScriptMsg, ScriptChan, ScriptThreadEventCategory}; -use script_thread::{Runnable, RunnableWrapper}; +use script_thread::{Task, TaskCanceller}; use std::fmt; use std::result::Result; use task_source::TaskSource; -pub struct NotifyPerformanceObserverRunnable { +pub struct NotifyPerformanceObserverTask { owner: Trusted<Performance>, } -impl NotifyPerformanceObserverRunnable { +impl NotifyPerformanceObserverTask { pub fn new(owner: Trusted<Performance>) -> Self { - NotifyPerformanceObserverRunnable { + NotifyPerformanceObserverTask { owner, } } } -impl Runnable for NotifyPerformanceObserverRunnable { - fn handler(self: Box<NotifyPerformanceObserverRunnable>) { +impl Task for NotifyPerformanceObserverTask { + fn run(self: Box<Self>) { self.owner.root().notify_observers(); } } @@ -49,13 +49,17 @@ impl fmt::Debug for PerformanceTimelineTaskSource { } impl TaskSource for PerformanceTimelineTaskSource { - fn queue_with_wrapper<T>(&self, - msg: Box<T>, - wrapper: &RunnableWrapper) -> Result<(), ()> - where T: Runnable + Send + 'static { - let msg = CommonScriptMsg::RunnableMsg( + fn queue_with_canceller<T>( + &self, + msg: Box<T>, + canceller: &TaskCanceller, + ) -> Result<(), ()> + where + T: Send + Task + 'static, + { + let msg = CommonScriptMsg::Task( ScriptThreadEventCategory::PerformanceTimelineTask, - wrapper.wrap_runnable(msg) + canceller.wrap_task(msg) ); self.0.send(msg).map_err(|_| ()) } @@ -64,7 +68,7 @@ impl TaskSource for PerformanceTimelineTaskSource { impl PerformanceTimelineTaskSource { pub fn queue_notification(&self, global: &GlobalScope) { let owner = Trusted::new(&*global.performance()); - let runnable = box NotifyPerformanceObserverRunnable::new(owner); - let _ = self.queue(runnable, global); + let task = box NotifyPerformanceObserverTask::new(owner); + let _ = self.queue(task, global); } } diff --git a/components/script/task_source/user_interaction.rs b/components/script/task_source/user_interaction.rs index 9456d940416..3e84e0fb19a 100644 --- a/components/script/task_source/user_interaction.rs +++ b/components/script/task_source/user_interaction.rs @@ -4,11 +4,11 @@ use dom::bindings::inheritance::Castable; use dom::bindings::refcounted::Trusted; -use dom::event::{EventBubbles, EventCancelable, EventRunnable}; +use dom::event::{EventBubbles, EventCancelable, EventTask}; use dom::eventtarget::EventTarget; use dom::window::Window; use script_runtime::{CommonScriptMsg, ScriptThreadEventCategory}; -use script_thread::{MainThreadScriptMsg, Runnable, RunnableWrapper}; +use script_thread::{MainThreadScriptMsg, Task, TaskCanceller}; use servo_atoms::Atom; use std::fmt; use std::result::Result; @@ -25,17 +25,17 @@ impl fmt::Debug for UserInteractionTaskSource { } impl TaskSource for UserInteractionTaskSource { - fn queue_with_wrapper<T>( + fn queue_with_canceller<T>( &self, msg: Box<T>, - wrapper: &RunnableWrapper, + canceller: &TaskCanceller, ) -> Result<(), ()> where - T: Runnable + Send + 'static, + T: Task + Send + 'static, { - let msg = MainThreadScriptMsg::Common(CommonScriptMsg::RunnableMsg( + let msg = MainThreadScriptMsg::Common(CommonScriptMsg::Task( ScriptThreadEventCategory::InputEvent, - wrapper.wrap_runnable(msg), + canceller.wrap_task(msg), )); self.0.send(msg).map_err(|_| ()) } @@ -49,12 +49,7 @@ impl UserInteractionTaskSource { cancelable: EventCancelable, window: &Window) { let target = Trusted::new(target); - let runnable = box EventRunnable { - target: target, - name: name, - bubbles: bubbles, - cancelable: cancelable, - }; - let _ = self.queue(runnable, window.upcast()); + let task = box EventTask { target, name, bubbles, cancelable }; + let _ = self.queue(task, window.upcast()); } } |