diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2018-11-16 09:54:40 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-16 09:54:40 -0500 |
commit | a2937d948818665ecda16a06fe6c8fa751d265fd (patch) | |
tree | 7c925d0d1517807e56963847da4c3ca25d7b2626 /components/script/script_thread.rs | |
parent | 050b2bca70b09a84901de84b4538f19da3250eee (diff) | |
parent | 75eb94afcaae2f868ecccba5b5dcea4066998d7a (diff) | |
download | servo-a2937d948818665ecda16a06fe6c8fa751d265fd.tar.gz servo-a2937d948818665ecda16a06fe6c8fa751d265fd.zip |
Auto merge of #21804 - AgustinCB:unify-task-source-canceller-api, r=gterzian
Unify the task source and task canceller API
To do so, I created a struct `TaskManagement(TaskSource,
TaskCanceller)` and made `*_task_source` return that instead of just
the task source.
Next, I refactored all places in which `task_canceller` by basically
removing them in favour of a previously called `*_task_source`.
I tried to make `task_canceller` a private method in `Window`, with the
hope of enforcing the use of `*_task_source`. However, it's used in
components/script/dom/globalscope.rs:575 in such a way that will make it
harder to avoid. I decided to leave it that way.
It'd be possible to unify `*_task_source` in such a way that we would
have only one method. However, I decided not to do it because one of the
`TaskSource` implementations is special:
`history_traversal_task_source`. Not wanting to over complicate things,
I decided to leave the structure this way.
---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #21154 (github issue number if applicable).
- [x] These changes do not require tests because it's refactoring code that should already be tested.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21804)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/script_thread.rs')
-rw-r--r-- | components/script/script_thread.rs | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index cd2008bf56b..fe102a0a7b3 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -70,6 +70,7 @@ use crate::microtask::{Microtask, MicrotaskQueue}; use crate::script_runtime::{get_reports, new_rt_and_cx, Runtime, ScriptPort}; use crate::script_runtime::{CommonScriptMsg, ScriptChan, ScriptThreadEventCategory}; use crate::serviceworkerjob::{Job, JobQueue}; +use crate::task_manager::TaskManager; use crate::task_queue::{QueuedTask, QueuedTaskConversion, TaskQueue}; use crate::task_source::dom_manipulation::DOMManipulationTaskSource; use crate::task_source::file_reading::FileReadingTaskSource; @@ -521,7 +522,7 @@ pub struct ScriptThread { networking_task_sender: Box<dyn ScriptChan>, - history_traversal_task_source: HistoryTraversalTaskSource, + history_traversal_task_sender: Sender<MainThreadScriptMsg>, file_reading_task_sender: Box<dyn ScriptChan>, @@ -1042,7 +1043,7 @@ impl ScriptThread { performance_timeline_task_sender: boxed_script_sender.clone(), remote_event_task_sender: boxed_script_sender.clone(), - history_traversal_task_source: HistoryTraversalTaskSource(chan), + history_traversal_task_sender: chan.clone(), control_chan: state.control_chan, control_port: control_port, @@ -1409,6 +1410,7 @@ impl ScriptThread { ScriptThreadEventCategory::FormPlannedNavigation => { ProfilerCategory::ScriptPlannedNavigation }, + ScriptThreadEventCategory::HistoryEvent => ProfilerCategory::ScriptHistoryEvent, ScriptThreadEventCategory::ImageCacheMsg => ProfilerCategory::ScriptImageCacheMsg, ScriptThreadEventCategory::InputEvent => ProfilerCategory::ScriptInputEvent, ScriptThreadEventCategory::NetworkEvent => ProfilerCategory::ScriptNetworkEvent, @@ -2180,6 +2182,13 @@ impl ScriptThread { PerformanceTimelineTaskSource(self.performance_timeline_task_sender.clone(), pipeline_id) } + pub fn history_traversal_task_source( + &self, + pipeline_id: PipelineId, + ) -> HistoryTraversalTaskSource { + HistoryTraversalTaskSource(self.history_traversal_task_sender.clone(), pipeline_id) + } + pub fn user_interaction_task_source( &self, pipeline_id: PipelineId, @@ -2560,7 +2569,6 @@ impl ScriptThread { ); let MainThreadScriptChan(ref sender) = self.chan; - let HistoryTraversalTaskSource(ref history_sender) = self.history_traversal_task_source; let (ipc_timer_event_chan, ipc_timer_event_port) = ipc::channel().unwrap(); route_ipc_receiver_to_new_servo_sender(ipc_timer_event_port, self.timer_event_chan.clone()); @@ -2576,20 +2584,23 @@ impl ScriptThread { pipeline_id: incomplete.pipeline_id, }; - // Create the window and document objects. - let window = Window::new( - self.js_runtime.clone(), - MainThreadScriptChan(sender.clone()), + let task_manager = TaskManager::new( self.dom_manipulation_task_source(incomplete.pipeline_id), + self.file_reading_task_source(incomplete.pipeline_id), + self.history_traversal_task_source(incomplete.pipeline_id), self.media_element_task_source(incomplete.pipeline_id), - self.user_interaction_task_source(incomplete.pipeline_id), self.networking_task_source(incomplete.pipeline_id), - HistoryTraversalTaskSource(history_sender.clone()), - self.file_reading_task_source(incomplete.pipeline_id), self.performance_timeline_task_source(incomplete.pipeline_id) .clone(), + self.user_interaction_task_source(incomplete.pipeline_id), self.remote_event_task_source(incomplete.pipeline_id), self.websocket_task_source(incomplete.pipeline_id), + ); + // Create the window and document objects. + let window = Window::new( + self.js_runtime.clone(), + MainThreadScriptChan(sender.clone()), + task_manager, self.image_cache_channel.clone(), self.image_cache.clone(), self.resource_threads.clone(), |