diff options
author | yvt <i@yvt.jp> | 2021-07-10 17:24:27 +0900 |
---|---|---|
committer | yvt <i@yvt.jp> | 2021-07-10 17:55:42 +0900 |
commit | 01a7de50ab1843d85295f9dccad7f4c099e7208c (patch) | |
tree | ee53fb6e8889deb7b880ee969e6c662e6128d210 /components/script/task_manager.rs | |
parent | ff8d2cdbbfc7a9dc7f38b7dd47cb350fde39388f (diff) | |
parent | 94b613fbdaa2b98f2179fc0bbda13c64e6fa0d38 (diff) | |
download | servo-01a7de50ab1843d85295f9dccad7f4c099e7208c.tar.gz servo-01a7de50ab1843d85295f9dccad7f4c099e7208c.zip |
Merge remote-tracking branch 'upstream/master' into feat-cow-infra
`tests/wpt/web-platform-tests/html/browsers/origin/cross-origin-objects/cross-origin-objects.html`
was reverted to the upstream version.
Diffstat (limited to 'components/script/task_manager.rs')
-rw-r--r-- | components/script/task_manager.rs | 188 |
1 files changed, 188 insertions, 0 deletions
diff --git a/components/script/task_manager.rs b/components/script/task_manager.rs new file mode 100644 index 00000000000..184b427cfcb --- /dev/null +++ b/components/script/task_manager.rs @@ -0,0 +1,188 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +use crate::dom::bindings::cell::DomRefCell; +use crate::task::TaskCanceller; +use crate::task_source::dom_manipulation::DOMManipulationTaskSource; +use crate::task_source::file_reading::FileReadingTaskSource; +use crate::task_source::history_traversal::HistoryTraversalTaskSource; +use crate::task_source::media_element::MediaElementTaskSource; +use crate::task_source::networking::NetworkingTaskSource; +use crate::task_source::performance_timeline::PerformanceTimelineTaskSource; +use crate::task_source::port_message::PortMessageQueue; +use crate::task_source::remote_event::RemoteEventTaskSource; +use crate::task_source::timer::TimerTaskSource; +use crate::task_source::user_interaction::UserInteractionTaskSource; +use crate::task_source::websocket::WebsocketTaskSource; +use crate::task_source::TaskSourceName; +use std::collections::HashMap; +use std::sync::atomic::AtomicBool; +use std::sync::Arc; + +macro_rules! task_source_functions { + ($self:ident,$with_canceller:ident,$task_source:ident,$task_source_type:ident,$task_source_name:ident) => { + pub fn $with_canceller(&$self) -> ($task_source_type, TaskCanceller) { + ($self.$task_source.clone(), $self.task_canceller(TaskSourceName::$task_source_name)) + } + + pub fn $task_source(&$self) -> $task_source_type { + $self.$task_source.clone() + } + } +} + +#[derive(JSTraceable, MallocSizeOf)] +pub struct TaskManager { + #[ignore_malloc_size_of = "task sources are hard"] + pub task_cancellers: DomRefCell<HashMap<TaskSourceName, Arc<AtomicBool>>>, + #[ignore_malloc_size_of = "task sources are hard"] + dom_manipulation_task_source: DOMManipulationTaskSource, + #[ignore_malloc_size_of = "task sources are hard"] + file_reading_task_source: FileReadingTaskSource, + #[ignore_malloc_size_of = "task sources are hard"] + history_traversal_task_source: HistoryTraversalTaskSource, + #[ignore_malloc_size_of = "task sources are hard"] + media_element_task_source: MediaElementTaskSource, + #[ignore_malloc_size_of = "task sources are hard"] + networking_task_source: NetworkingTaskSource, + #[ignore_malloc_size_of = "task sources are hard"] + performance_timeline_task_source: PerformanceTimelineTaskSource, + #[ignore_malloc_size_of = "task sources are hard"] + port_message_queue: PortMessageQueue, + #[ignore_malloc_size_of = "task sources are hard"] + user_interaction_task_source: UserInteractionTaskSource, + #[ignore_malloc_size_of = "task sources are hard"] + remote_event_task_source: RemoteEventTaskSource, + #[ignore_malloc_size_of = "task sources are hard"] + timer_task_source: TimerTaskSource, + #[ignore_malloc_size_of = "task sources are hard"] + websocket_task_source: WebsocketTaskSource, +} + +impl TaskManager { + pub fn new( + dom_manipulation_task_source: DOMManipulationTaskSource, + file_reading_task_source: FileReadingTaskSource, + history_traversal_task_source: HistoryTraversalTaskSource, + media_element_task_source: MediaElementTaskSource, + networking_task_source: NetworkingTaskSource, + performance_timeline_task_source: PerformanceTimelineTaskSource, + port_message_queue: PortMessageQueue, + user_interaction_task_source: UserInteractionTaskSource, + remote_event_task_source: RemoteEventTaskSource, + timer_task_source: TimerTaskSource, + websocket_task_source: WebsocketTaskSource, + ) -> Self { + TaskManager { + dom_manipulation_task_source, + file_reading_task_source, + history_traversal_task_source, + media_element_task_source, + networking_task_source, + performance_timeline_task_source, + port_message_queue, + user_interaction_task_source, + remote_event_task_source, + timer_task_source, + websocket_task_source, + task_cancellers: Default::default(), + } + } + + task_source_functions!( + self, + dom_manipulation_task_source_with_canceller, + dom_manipulation_task_source, + DOMManipulationTaskSource, + DOMManipulation + ); + + task_source_functions!( + self, + media_element_task_source_with_canceller, + media_element_task_source, + MediaElementTaskSource, + MediaElement + ); + + task_source_functions!( + self, + user_interaction_task_source_with_canceller, + user_interaction_task_source, + UserInteractionTaskSource, + UserInteraction + ); + + task_source_functions!( + self, + networking_task_source_with_canceller, + networking_task_source, + NetworkingTaskSource, + Networking + ); + + task_source_functions!( + self, + file_reading_task_source_with_canceller, + file_reading_task_source, + FileReadingTaskSource, + FileReading + ); + + task_source_functions!( + self, + history_traversal_task_source_with_canceller, + history_traversal_task_source, + HistoryTraversalTaskSource, + HistoryTraversal + ); + + task_source_functions!( + self, + performance_timeline_task_source_with_canceller, + performance_timeline_task_source, + PerformanceTimelineTaskSource, + PerformanceTimeline + ); + + task_source_functions!( + self, + port_message_queue_with_canceller, + port_message_queue, + PortMessageQueue, + PortMessage + ); + + task_source_functions!( + self, + remote_event_task_source_with_canceller, + remote_event_task_source, + RemoteEventTaskSource, + RemoteEvent + ); + + task_source_functions!( + self, + timer_task_source_with_canceller, + timer_task_source, + TimerTaskSource, + Timer + ); + + task_source_functions!( + self, + websocket_task_source_with_canceller, + websocket_task_source, + WebsocketTaskSource, + Websocket + ); + + pub fn task_canceller(&self, name: TaskSourceName) -> TaskCanceller { + let mut flags = self.task_cancellers.borrow_mut(); + let cancel_flag = flags.entry(name).or_insert(Default::default()); + TaskCanceller { + cancelled: cancel_flag.clone(), + } + } +} |