script: Migrate swmanager to GenericChannel (#39076)

Migrate `ServiceWorkerMsg` and `SWManagerMsg` to GenericChannel

Testing: Covered by service worker wpt tests
Part of #38912

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
This commit is contained in:
Jonathan Schwender 2025-09-01 21:23:16 +02:00 committed by GitHub
parent 93aeac056b
commit ce8b05738c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 44 additions and 34 deletions

View file

@ -252,6 +252,16 @@ impl From<crossbeam_channel::TryRecvError> for TryReceiveError {
pub type RoutedReceiver<T> = crossbeam_channel::Receiver<Result<T, ipc_channel::Error>>;
pub type ReceiveResult<T> = Result<T, ReceiveError>;
pub type TryReceiveResult<T> = Result<T, TryReceiveError>;
pub type RoutedReceiverReceiveResult<T> =
Result<Result<T, ipc_channel::Error>, crossbeam_channel::RecvError>;
pub fn to_receive_result<T>(receive_result: RoutedReceiverReceiveResult<T>) -> ReceiveResult<T> {
match receive_result {
Ok(Ok(msg)) => Ok(msg),
Err(_crossbeam_recv_err) => Err(ReceiveError::Disconnected),
Ok(Err(ipc_err)) => Err(ReceiveError::DeserializationFailed(ipc_err.to_string())),
}
}
pub struct GenericReceiver<T>(GenericReceiverVariants<T>)
where

View file

@ -8,7 +8,7 @@ use std::collections::HashMap;
use std::fmt;
use base::Epoch;
use base::generic_channel::{GenericCallback, GenericSender, SendResult};
use base::generic_channel::{GenericCallback, GenericReceiver, GenericSender, SendResult};
use base::id::{
BroadcastChannelRouterId, BrowsingContextId, HistoryStateId, MessagePortId,
MessagePortRouterId, PipelineId, ServiceWorkerId, ServiceWorkerRegistrationId, WebViewId,
@ -24,7 +24,7 @@ use embedder_traits::{
use euclid::default::Size2D as UntypedSize2D;
use fonts_traits::SystemFontServiceProxySender;
use http::{HeaderMap, Method};
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use ipc_channel::ipc::IpcSender;
use malloc_size_of_derive::MallocSizeOf;
use net_traits::policy_container::PolicyContainer;
use net_traits::request::{Destination, InsecureRequestsPolicy, Referrer, RequestBody};
@ -206,7 +206,7 @@ pub struct DOMMessage {
#[derive(Deserialize, Serialize)]
pub struct SWManagerSenders {
/// Sender of messages to the constellation.
pub swmanager_sender: IpcSender<SWManagerMsg>,
pub swmanager_sender: GenericSender<SWManagerMsg>,
/// [`ResourceThreads`] for initating fetches or using i/o.
pub resource_threads: ResourceThreads,
/// [`CrossProcessCompositorApi`] for communicating with the compositor.
@ -214,9 +214,9 @@ pub struct SWManagerSenders {
/// The [`SystemFontServiceProxy`] used to communicate with the `SystemFontService`.
pub system_font_service_sender: SystemFontServiceProxySender,
/// Sender of messages to the manager.
pub own_sender: IpcSender<ServiceWorkerMsg>,
pub own_sender: GenericSender<ServiceWorkerMsg>,
/// Receiver of messages from the constellation.
pub receiver: IpcReceiver<ServiceWorkerMsg>,
pub receiver: GenericReceiver<ServiceWorkerMsg>,
}
/// Messages sent to Service Worker Manager thread