From 14bc8ab7542287a18ecdede1ca7ee2af077eb8a9 Mon Sep 17 00:00:00 2001 From: Agustin Chiappe Berrini Date: Thu, 27 Sep 2018 18:43:22 -0400 Subject: Implement TaskSource for HistoryTraversal And remove the method in window that returns it, because it isn't used so far. --- components/script/script_thread.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'components/script/script_thread.rs') diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index cd2008bf56b..c4177500b64 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -521,7 +521,7 @@ pub struct ScriptThread { networking_task_sender: Box, - history_traversal_task_source: HistoryTraversalTaskSource, + history_traversal_task_sender: Sender, file_reading_task_sender: Box, @@ -1042,7 +1042,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 +1409,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 +2181,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 +2568,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()); @@ -2584,7 +2591,7 @@ impl ScriptThread { 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.history_traversal_task_source(incomplete.pipeline_id), self.file_reading_task_source(incomplete.pipeline_id), self.performance_timeline_task_source(incomplete.pipeline_id) .clone(), -- cgit v1.2.3 From 75eb94afcaae2f868ecccba5b5dcea4066998d7a Mon Sep 17 00:00:00 2001 From: Agustin Chiappe Berrini Date: Mon, 24 Sep 2018 19:31:59 -0400 Subject: Unify the task source and task canceller API I moved away from the `Window` struct all the logic to handle task sources, into a new struct called `TaskManager`. In a happy world, I'd be able to just have there two functions, of the types: ```rust fn task_source(&self, name: TaskSourceName) -> Box fn task_source_with_canceller(&self, name: TaskSourceName) -> (Box, TaskSourceCanceller) ``` And not so much duplicated code. However, because TaskSource can't be a trait object (because it has generic type parameters), that's not possible. Instead, I decided to reduce duplicated logic through macros. For reasons[1], I have to pass both the name of the function with canceller and the name of the function without, as I'm not able to concatenate them in the macro itself. I could probably use `concat_idents` to create both types already defined and reduce the amount of arguments by one, but that macro is nightly only. At the same time, not being able to declare macros inside `impl` forces me to pass `self` as an argument. All this makes this solution more verbose than it would be ideally. It does reduce duplication, but it doesn't reduce the size of the file. [1](https://github.com/rust-lang/rust/issues/29599) --- components/script/script_thread.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'components/script/script_thread.rs') diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index c4177500b64..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; @@ -2583,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), - self.history_traversal_task_source(incomplete.pipeline_id), - 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(), -- cgit v1.2.3