Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

refactor(service-worker): bind work to exact run owners

ldm09454318cdd7c
diff --git a/moli-renderer-v8/src/service_worker_runtime.rs b/moli-renderer-v8/src/service_worker_runtime.rs
index cc96ceba3..e2669d7a1 100644
--- a/moli-renderer-v8/src/service_worker_runtime.rs
+++ b/moli-renderer-v8/src/service_worker_runtime.rs
@@ -12,6 +12,7 @@ mod path_restriction;
mod pending_clear;
mod registration;
mod resource_store;
+mod run_owner;
mod script_loading;
mod service;
mod service_lane;
@@ -78,6 +79,7 @@ pub use resource_store::{
SharedServiceWorkerResourceStore, new_shared_json_service_worker_resource_store,
new_shared_service_worker_resource_store,
};
+pub(crate) use run_owner::ServiceWorkerRunOwner;
pub(crate) use service::{
ServiceWorkerRuntimeService,
new_service_worker_runtime_service_with_resource_store_and_browser_resource_runtime_binding,
diff --git a/moli-renderer-v8/src/service_worker_runtime/clients.rs b/moli-renderer-v8/src/service_worker_runtime/clients.rs
index 87d8d0c3d..23a9cb4f4 100644
--- a/moli-renderer-v8/src/service_worker_runtime/clients.rs
+++ b/moli-renderer-v8/src/service_worker_runtime/clients.rs
@@ -1,7 +1,11 @@
+use std::sync::atomic::{AtomicU64, Ordering};
+
use url::Url;
use super::ids::{ServiceWorkerClientId, ServiceWorkerRegistrationId, ServiceWorkerVersionId};
+static NEXT_SERVICE_WORKER_EXPOSED_CLIENT_ID: AtomicU64 = AtomicU64::new(1);
+
#[derive(Clone, Debug, Eq, PartialEq)]
pub(crate) struct ServiceWorkerClientSnapshot {
pub(crate) id: ServiceWorkerClientId,
@@ -67,21 +71,20 @@ impl ServiceWorkerClientSnapshot {
}
pub(crate) fn service_worker_exposed_client_id(id: ServiceWorkerClientId) -> String {
- service_worker_exposed_client_id_for_generation(id, 0)
+ format!("client-{:016x}", id.as_u64())
}
-pub(crate) fn service_worker_exposed_client_id_for_generation(
- id: ServiceWorkerClientId,
- generation: u64,
-) -> String {
- if generation == 0 {
- return format!("client-{:016x}", id.as_u64());
- }
- format!("client-{:016x}-{:016x}", id.as_u64(), generation)
+pub(crate) fn allocate_service_worker_exposed_client_id() -> String {
+ allocate_service_worker_exposed_client_id_from(&NEXT_SERVICE_WORKER_EXPOSED_CLIENT_ID)
}
-pub(crate) fn service_worker_next_exposed_client_id_generation(generation: u64) -> u64 {
- generation.saturating_add(1)
+fn allocate_service_worker_exposed_client_id_from(counter: &AtomicU64) -> String {
+ let raw = counter
+ .fetch_update(Ordering::Relaxed, Ordering::Relaxed, |current| {
+ current.checked_add(1)
+ })
+ .expect("ServiceWorker exposed client id allocator exhausted");
+ format!("client-document-{raw:016x}")
}
pub(crate) fn service_worker_current_url_for_creation_url(creation_url: &Url) -> Url {
@@ -90,6 +93,31 @@ pub(crate) fn service_worker_current_url_for_creation_url(creation_url: &Url) ->
current_url
}
+#[cfg(test)]
+mod exposed_client_identity_tests {
+ use super::*;
+
+ #[test]
+ fn replacement_ids_are_fresh_and_not_derived_from_internal_client_id() {
+ let client_id = ServiceWorkerClientId::from_u64_for_test(7);
+ let first = allocate_service_worker_exposed_client_id();
+ let second = allocate_service_worker_exposed_client_id();
+
+ assert_ne!(first, second);
+ assert_ne!(first, service_worker_exposed_client_id(client_id));
+ }
+
+ #[test]
+ fn replacement_id_allocator_rejects_exhaustion_without_wrapping() {
+ let counter = AtomicU64::new(u64::MAX);
+ let exhausted =
+ std::panic::catch_unwind(|| allocate_service_worker_exposed_client_id_from(&counter));
+
+ assert!(exhausted.is_err());
+ assert_eq!(counter.load(Ordering::Relaxed), u64::MAX);
+ }
+}
+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) enum ServiceWorkerClientType {
Window,
diff --git a/moli-renderer-v8/src/service_worker_runtime/events.rs b/moli-renderer-v8/src/service_worker_runtime/events.rs
index 6f69d8679..f4b7fb556 100644
--- a/moli-renderer-v8/src/service_worker_runtime/events.rs
+++ b/moli-renderer-v8/src/service_worker_runtime/events.rs
@@ -4,8 +4,7 @@ use url::Url;
use crate::types::NetworkBodySourceId;
use crate::{
network::ResourceRequestClient, page_task_queue::RendererResourceCompletionSender,
- runtime::RendererServiceWorkerRunIdentity, structured_clone::V8StructuredClonePayload,
- types::AsyncSubresourceNetworkContext,
+ structured_clone::V8StructuredClonePayload, types::AsyncSubresourceNetworkContext,
};
use super::{
@@ -14,6 +13,7 @@ use super::{
ServiceWorkerClientId, ServiceWorkerEventId, ServiceWorkerRegistrationId,
ServiceWorkerVersionId,
},
+ run_owner::ServiceWorkerRunOwner,
snapshots::ServiceWorkerVersionSnapshot,
};
@@ -35,16 +35,14 @@ impl ServiceWorkerLifecycleEventKind {
#[derive(Clone, Debug)]
pub(crate) struct ServiceWorkerLifecycleEvent {
pub(crate) event_id: ServiceWorkerEventId,
- pub(crate) version_id: ServiceWorkerVersionId,
- pub(crate) run: RendererServiceWorkerRunIdentity,
+ pub(crate) owner: ServiceWorkerRunOwner,
pub(crate) kind: ServiceWorkerLifecycleEventKind,
}
#[derive(Clone, Debug)]
pub(crate) struct ServiceWorkerLifecycleCompletion {
pub(crate) event_id: ServiceWorkerEventId,
- pub(crate) version_id: ServiceWorkerVersionId,
- pub(crate) run: RendererServiceWorkerRunIdentity,
+ pub(crate) owner: ServiceWorkerRunOwner,
pub(crate) kind: ServiceWorkerLifecycleEventKind,
pub(crate) result: Result<(), String>,
}
@@ -52,8 +50,7 @@ pub(crate) struct ServiceWorkerLifecycleCompletion {
#[derive(Clone, Debug)]
pub(crate) struct ServiceWorkerMessageEvent {
pub(crate) event_id: ServiceWorkerEventId,
- pub(crate) version_id: ServiceWorkerVersionId,
- pub(crate) run: RendererServiceWorkerRunIdentity,
+ pub(crate) owner: ServiceWorkerRunOwner,
pub(crate) source_client_id: Option<ServiceWorkerClientId>,
pub(crate) source_client_url: Option<Url>,
pub(crate) source_client_snapshot: Option<ServiceWorkerClientSnapshot>,
@@ -68,8 +65,7 @@ pub(crate) struct ServiceWorkerNotificationEvent {
pub(crate) event_id: ServiceWorkerEventId,
pub(crate) kind: ServiceWorkerNotificationEventKind,
pub(crate) registration_id: ServiceWorkerRegistrationId,
- pub(crate) version_id: ServiceWorkerVersionId,
- pub(crate) run: RendererServiceWorkerRunIdentity,
+ pub(crate) owner: ServiceWorkerRunOwner,
pub(crate) notification_id: u64,
pub(crate) title: String,
pub(crate) tag: String,
@@ -101,24 +97,21 @@ impl ServiceWorkerNotificationEventKind {
#[derive(Clone, Debug)]
pub(crate) struct ServiceWorkerNotificationCompletion {
pub(crate) event_id: ServiceWorkerEventId,
- pub(crate) version_id: ServiceWorkerVersionId,
- pub(crate) run: RendererServiceWorkerRunIdentity,
+ pub(crate) owner: ServiceWorkerRunOwner,
pub(crate) result: Result<(), String>,
}
#[derive(Clone, Debug)]
pub(crate) struct ServiceWorkerPushEvent {
pub(crate) event_id: ServiceWorkerEventId,
- pub(crate) version_id: ServiceWorkerVersionId,
- pub(crate) run: RendererServiceWorkerRunIdentity,
+ pub(crate) owner: ServiceWorkerRunOwner,
pub(crate) data: Option<Vec<u8>>,
}
#[derive(Clone, Debug)]
pub(crate) struct ServiceWorkerPushCompletion {
pub(crate) event_id: ServiceWorkerEventId,
- pub(crate) version_id: ServiceWorkerVersionId,
- pub(crate) run: RendererServiceWorkerRunIdentity,
+ pub(crate) owner: ServiceWorkerRunOwner,
pub(crate) result: Result<(), String>,
}
@@ -126,8 +119,7 @@ pub(crate) struct ServiceWorkerPushCompletion {
pub(crate) struct ServiceWorkerSyncEvent {
pub(crate) event_id: ServiceWorkerEventId,
pub(crate) registration_id: ServiceWorkerRegistrationId,
- pub(crate) version_id: ServiceWorkerVersionId,
- pub(crate) run: RendererServiceWorkerRunIdentity,
+ pub(crate) owner: ServiceWorkerRunOwner,
pub(crate) tag: String,
pub(crate) last_chance: bool,
}
@@ -136,8 +128,7 @@ pub(crate) struct ServiceWorkerSyncEvent {
pub(crate) struct ServiceWorkerSyncCompletion {
pub(crate) event_id: ServiceWorkerEventId,
pub(crate) registration_id: ServiceWorkerRegistrationId,
- pub(crate) version_id: ServiceWorkerVersionId,
- pub(crate) run: RendererServiceWorkerRunIdentity,
+ pub(crate) owner: ServiceWorkerRunOwner,
pub(crate) tag: String,
pub(crate) result: Result<(), String>,
}
@@ -146,8 +137,7 @@ pub(crate) struct ServiceWorkerSyncCompletion {
pub(crate) struct ServiceWorkerPeriodicSyncEvent {
pub(crate) event_id: ServiceWorkerEventId,
pub(crate) registration_id: ServiceWorkerRegistrationId,
- pub(crate) version_id: ServiceWorkerVersionId,
- pub(crate) run: RendererServiceWorkerRunIdentity,
+ pub(crate) owner: ServiceWorkerRunOwner,
pub(crate) tag: String,
}
@@ -155,8 +145,7 @@ pub(crate) struct ServiceWorkerPeriodicSyncEvent {
pub(crate) struct ServiceWorkerPeriodicSyncCompletion {
pub(crate) event_id: ServiceWorkerEventId,
pub(crate) registration_id: ServiceWorkerRegistrationId,
- pub(crate) version_id: ServiceWorkerVersionId,
- pub(crate) run: RendererServiceWorkerRunIdentity,
+ pub(crate) owner: ServiceWorkerRunOwner,
pub(crate) tag: String,
pub(crate) result: Result<(), String>,
}
@@ -471,8 +460,7 @@ pub(crate) struct ServiceWorkerClientsOpenWindowResult {
#[derive(Clone, Debug)]
pub(crate) struct ServiceWorkerMessageCompletion {
pub(crate) event_id: ServiceWorkerEventId,
- pub(crate) version_id: ServiceWorkerVersionId,
- pub(crate) run: RendererServiceWorkerRunIdentity,
+ pub(crate) owner: ServiceWorkerRunOwner,
pub(crate) result: Result<(), String>,
}
@@ -630,8 +618,7 @@ pub(crate) fn service_worker_opaque_response_rejection(
#[derive(Clone, Debug)]
pub(crate) struct ServiceWorkerFetchEvent {
pub(crate) event_id: ServiceWorkerEventId,
- pub(crate) version_id: ServiceWorkerVersionId,
- pub(crate) run: RendererServiceWorkerRunIdentity,
+ pub(crate) owner: ServiceWorkerRunOwner,
pub(crate) request: ServiceWorkerFetchRequest,
pub(crate) navigation_preload_sent: bool,
}
@@ -657,8 +644,7 @@ pub(crate) enum ServiceWorkerFetchResult {
#[derive(Clone, Debug)]
pub(crate) struct ServiceWorkerFetchStreamStarted {
pub(crate) event_id: ServiceWorkerEventId,
- pub(crate) version_id: ServiceWorkerVersionId,
- pub(crate) run: RendererServiceWorkerRunIdentity,
+ pub(crate) owner: ServiceWorkerRunOwner,
pub(crate) body_source_id: NetworkBodySourceId,
pub(crate) response_head: MaterializedServiceWorkerFetchResponseHead,
}
@@ -673,8 +659,7 @@ pub(crate) struct ServiceWorkerFetchStreamChunk {
#[derive(Clone, Debug)]
pub(crate) struct ServiceWorkerNavigationPreloadResponseStarted {
pub(crate) event_id: ServiceWorkerEventId,
- pub(crate) version_id: ServiceWorkerVersionId,
- pub(crate) run: RendererServiceWorkerRunIdentity,
+ pub(crate) owner: ServiceWorkerRunOwner,
pub(crate) request_url: Url,
pub(crate) request_mode: moli_fetch::RequestMode,
pub(crate) body_source_id: NetworkBodySourceId,
@@ -691,8 +676,7 @@ pub(crate) struct ServiceWorkerNavigationPreloadStreamChunk {
#[derive(Clone, Debug)]
pub(crate) struct ServiceWorkerNavigationPreloadStreamFinished {
pub(crate) event_id: ServiceWorkerEventId,
- pub(crate) version_id: ServiceWorkerVersionId,
- pub(crate) run: RendererServiceWorkerRunIdentity,
+ pub(crate) owner: ServiceWorkerRunOwner,
pub(crate) body_source_id: NetworkBodySourceId,
pub(crate) result: Result<(), String>,
}
@@ -700,8 +684,7 @@ pub(crate) struct ServiceWorkerNavigationPreloadStreamFinished {
#[derive(Clone, Debug)]
pub(crate) struct ServiceWorkerNavigationPreloadFailure {
pub(crate) event_id: ServiceWorkerEventId,
- pub(crate) version_id: ServiceWorkerVersionId,
- pub(crate) run: RendererServiceWorkerRunIdentity,
+ pub(crate) owner: ServiceWorkerRunOwner,
pub(crate) message: String,
}
@@ -730,8 +713,7 @@ pub(crate) struct ServiceWorkerDirectFetchResponse {
#[derive(Clone, Debug)]
pub(crate) struct ServiceWorkerFetchCompletion {
pub(crate) event_id: ServiceWorkerEventId,
- pub(crate) version_id: ServiceWorkerVersionId,
- pub(crate) run: RendererServiceWorkerRunIdentity,
+ pub(crate) owner: ServiceWorkerRunOwner,
pub(crate) result: ServiceWorkerFetchResult,
}
diff --git a/moli-renderer-v8/src/service_worker_runtime/host.rs b/moli-renderer-v8/src/service_worker_runtime/host.rs
index e25d99085..e7ea573da 100644
--- a/moli-renderer-v8/src/service_worker_runtime/host.rs
+++ b/moli-renderer-v8/src/service_worker_runtime/host.rs
@@ -23,6 +23,7 @@ use crate::{
use super::{
ids::ServiceWorkerVersionId,
jobs::ServiceWorkerLaunchParams,
+ run_owner::ServiceWorkerRunOwner,
script_loading::{
LoadedServiceWorkerScript, ServiceWorkerScriptResource, load_service_worker_script_source,
},
@@ -33,8 +34,7 @@ use super::{
pub(super) type SharedRendererServiceWorkerHost = Arc<RendererServiceWorkerHost>;
pub(super) struct RendererServiceWorkerHost {
- version_id: ServiceWorkerVersionId,
- run: RendererServiceWorkerRunIdentity,
+ run_owner: ServiceWorkerRunOwner,
state: Mutex<RendererServiceWorkerHostState>,
}
@@ -47,37 +47,31 @@ enum RendererServiceWorkerHostState {
impl RendererServiceWorkerHost {
pub(super) fn new_loading(
- version_id: ServiceWorkerVersionId,
- run: &RendererServiceWorkerRunIdentity,
+ run_owner: &ServiceWorkerRunOwner,
) -> SharedRendererServiceWorkerHost {
Arc::new(Self {
- version_id,
- run: run.clone(),
+ run_owner: run_owner.clone(),
state: Mutex::new(RendererServiceWorkerHostState::Loading),
})
}
#[cfg(test)]
pub(super) fn new_running_without_handle_for_test(
- version_id: ServiceWorkerVersionId,
- run: &RendererServiceWorkerRunIdentity,
+ run_owner: &ServiceWorkerRunOwner,
) -> SharedRendererServiceWorkerHost {
Arc::new(Self {
- version_id,
- run: run.clone(),
+ run_owner: run_owner.clone(),
state: Mutex::new(RendererServiceWorkerHostState::Running { handle: None }),
})
}
#[cfg(test)]
pub(super) fn new_running_with_handle_for_test(
- version_id: ServiceWorkerVersionId,
- run: &RendererServiceWorkerRunIdentity,
+ run_owner: &ServiceWorkerRunOwner,
handle: WorkerHandle,
) -> SharedRendererServiceWorkerHost {
Arc::new(Self {
- version_id,
- run: run.clone(),
+ run_owner: run_owner.clone(),
state: Mutex::new(RendererServiceWorkerHostState::Running {
handle: Some(handle),
}),
@@ -90,14 +84,17 @@ impl RendererServiceWorkerHost {
params: ServiceWorkerLaunchParams,
preloaded_script: Option<LoadedServiceWorkerScript>,
) {
- let version_id = params.version_id;
- let run = params.run.clone();
+ assert_eq!(
+ self.run_owner, params.run_owner,
+ "a ServiceWorker host must start only its bound run owner"
+ );
+ let run_owner = params.run_owner.clone();
let host_for_task = Arc::clone(self);
let service_for_task = service.clone();
let _ = std::thread::Builder::new()
.name(format!(
"service-worker-load-{}",
- params.version_id.as_u64()
+ params.run_owner.version_id().as_u64()
))
.spawn(move || {
let result = match preloaded_script {
@@ -109,8 +106,7 @@ impl RendererServiceWorkerHost {
.map_err(|error| {
self.mark_failed();
service.enqueue_worker_start_failed(
- version_id,
- run,
+ run_owner,
ServiceWorkerVersionStartFailure::HostThreadSpawn {
message: error.to_string(),
},
@@ -119,12 +115,16 @@ impl RendererServiceWorkerHost {
}
pub(super) fn version_id(&self) -> ServiceWorkerVersionId {
- self.version_id
+ self.run_owner.version_id()
}
/// Exact identity of this concrete V8 worker run.
pub(super) fn run_identity(&self) -> RendererServiceWorkerRunIdentity {
- self.run.clone()
+ self.run_owner.cloned_run_identity()
+ }
+
+ pub(super) fn run_owner(&self) -> ServiceWorkerRunOwner {
+ self.run_owner.clone()
}
pub(super) fn has_running_worker(&self) -> bool {
@@ -636,8 +636,7 @@ impl RendererServiceWorkerHost {
);
self.mark_failed();
service.enqueue_worker_start_failed(
- params.version_id,
- params.run.clone(),
+ params.run_owner.clone(),
ServiceWorkerVersionStartFailure::ScriptLoad { message: error },
);
return;
@@ -646,8 +645,8 @@ impl RendererServiceWorkerHost {
let script_resource = script.resource.clone();
let final_script_url = script_resource.final_url.to_string();
if service.finish_worker_start_identical_script_update(
- params.version_id,
- params.run.clone(),
+ params.run_owner.version_id(),
+ params.run_owner.cloned_run_identity(),
&script_resource,
) {
self.mark_failed();
@@ -662,12 +661,7 @@ impl RendererServiceWorkerHost {
bootstrap_completion_tx,
);
if let Some(receiver) = handle.take_receiver() {
- spawn_parent_message_pump(
- service.clone(),
- Arc::clone(self),
- params.version_id,
- receiver,
- );
+ spawn_parent_message_pump(service.clone(), Arc::clone(self), receiver);
}
let mut state = self.state.lock();
if !matches!(*state, RendererServiceWorkerHostState::Loading) {
@@ -679,13 +673,12 @@ impl RendererServiceWorkerHost {
handle: Some(handle),
};
drop(state);
- if service.take_devtools_evaluation_release_for_version(params.version_id) {
+ if service.take_devtools_evaluation_release_for_version(params.run_owner.version_id()) {
self.run_if_waiting_for_debugger_for_devtools();
}
report_bootstrap_completion(
service,
- params.version_id,
- params.run,
+ params.run_owner,
final_script_url,
script_resource,
bootstrap_completion_rx,
@@ -696,9 +689,9 @@ impl RendererServiceWorkerHost {
fn spawn_parent_message_pump(
service: ServiceWorkerRuntimeService,
source_host: SharedRendererServiceWorkerHost,
- version_id: ServiceWorkerVersionId,
mut receiver: mpsc::UnboundedReceiver<WorkerToParentMessage>,
) {
+ let version_id = source_host.version_id();
let source_run = source_host.run_identity();
let _ = std::thread::Builder::new()
.name(format!("service-worker-pump-{}", version_id.as_u64()))
@@ -733,77 +726,54 @@ fn spawn_parent_message_pump(
service.enqueue_periodic_sync_event_completed(completion);
}
WorkerToParentMessage::ServiceWorkerShowNotification(request) => {
- service.enqueue_show_notification_requested(
- request,
- source_run.clone(),
- Arc::clone(&source_host),
- );
+ service
+ .enqueue_show_notification_requested(request, Arc::clone(&source_host));
}
WorkerToParentMessage::ServiceWorkerGetNotifications(request) => {
- service.enqueue_get_notifications_requested(
- request,
- source_run.clone(),
- Arc::clone(&source_host),
- );
+ service
+ .enqueue_get_notifications_requested(request, Arc::clone(&source_host));
}
WorkerToParentMessage::ServiceWorkerSyncRegistration(request) => {
- service.enqueue_sync_registration_requested(
- request,
- source_run.clone(),
- Arc::clone(&source_host),
- );
+ service
+ .enqueue_sync_registration_requested(request, Arc::clone(&source_host));
}
WorkerToParentMessage::ServiceWorkerSyncGetTags(request) => {
- service.enqueue_sync_get_tags_requested(
- request,
- source_run.clone(),
- Arc::clone(&source_host),
- );
+ service.enqueue_sync_get_tags_requested(request, Arc::clone(&source_host));
}
WorkerToParentMessage::ServiceWorkerPeriodicSyncRegistration(request) => {
service.enqueue_periodic_sync_registration_requested(
request,
- source_run.clone(),
Arc::clone(&source_host),
);
}
WorkerToParentMessage::ServiceWorkerPeriodicSyncGetTags(request) => {
service.enqueue_periodic_sync_get_tags_requested(
request,
- source_run.clone(),
Arc::clone(&source_host),
);
}
WorkerToParentMessage::ServiceWorkerPeriodicSyncUnregistration(request) => {
service.enqueue_periodic_sync_unregistration_requested(
request,
- source_run.clone(),
Arc::clone(&source_host),
);
}
WorkerToParentMessage::ServiceWorkerPushSubscribe(request) => {
- service.enqueue_push_subscribe_requested(
- request,
- source_run.clone(),
- Arc::clone(&source_host),
- );
+ service.enqueue_push_subscribe_requested(request, Arc::clone(&source_host));
}
WorkerToParentMessage::ServiceWorkerPushGetSubscription(request) => {
service.enqueue_push_get_subscription_requested(
request,
- source_run.clone(),
Arc::clone(&source_host),
);
}
WorkerToParentMessage::ServiceWorkerPushUnsubscribe(request) => {
- service.enqueue_push_unsubscribe_requested(
- request,
- source_run.clone(),
- Arc::clone(&source_host),
- );
+ service
+ .enqueue_push_unsubscribe_requested(request, Arc::clone(&source_host));
}
WorkerToParentMessage::ServiceWorkerCloseNotification(request) => {
- service.enqueue_close_notification_requested(request, source_run.clone());
+ service
+ .enqueue_close_notification_requested(request, source_host.run_owner());
}
WorkerToParentMessage::ServiceWorkerClientMessage(message) => {
service.enqueue_client_message(message);
@@ -812,16 +782,16 @@ fn spawn_parent_message_pump(
service.enqueue_worker_message(message);
}
WorkerToParentMessage::ServiceWorkerClientQuery(query) => {
- service.enqueue_client_query(query, source_run.clone());
+ service.enqueue_client_query(query, source_host.run_owner());
}
WorkerToParentMessage::ServiceWorkerClientNavigate(navigate) => {
- service.enqueue_client_navigate(navigate, source_run.clone());
+ service.enqueue_client_navigate(navigate, source_host.run_owner());
}
WorkerToParentMessage::ServiceWorkerClientFocus(focus) => {
- service.enqueue_client_focus(focus, source_run.clone());
+ service.enqueue_client_focus(focus, source_host.run_owner());
}
WorkerToParentMessage::ServiceWorkerClientsOpenWindow(open_window) => {
- service.enqueue_clients_open_window(open_window, source_run.clone());
+ service.enqueue_clients_open_window(open_window, source_host.run_owner());
}
WorkerToParentMessage::ServiceWorkerSkipWaiting {
registration_id,
@@ -840,10 +810,12 @@ fn spawn_parent_message_pump(
version_id,
resource,
} => {
+ if version_id != source_host.version_id() {
+ continue;
+ }
service.enqueue_imported_script_loaded(
registration_id,
- version_id,
- source_run.clone(),
+ source_host.run_owner(),
resource,
);
}
@@ -899,8 +871,7 @@ fn spawn_parent_message_pump(
fn report_bootstrap_completion(
service: ServiceWorkerRuntimeService,
- version_id: ServiceWorkerVersionId,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
final_script_url: String,
script_resource: ServiceWorkerScriptResource,
mut receiver: mpsc::UnboundedReceiver<WorkerBootstrapCompletion>,
@@ -910,8 +881,7 @@ fn report_bootstrap_completion(
result: Ok(success),
}) => {
service.enqueue_worker_start_completed(
- version_id,
- run,
+ owner,
final_script_url,
script_resource,
service_worker_fetch_handler_type(success),
@@ -921,15 +891,13 @@ fn report_bootstrap_completion(
result: Err(failure),
}) => {
service.enqueue_worker_start_failed(
- version_id,
- run,
+ owner,
ServiceWorkerVersionStartFailure::Bootstrap { failure },
);
}
None => {
service.enqueue_worker_start_failed(
- version_id,
- run,
+ owner,
ServiceWorkerVersionStartFailure::BootstrapChannelClosed,
);
}
@@ -980,7 +948,7 @@ fn spawn_service_worker(
.with_service_worker_runtime(service)
.with_global_kind(crate::worker::WorkerGlobalKind::Service {
registration_id: params.registration_id,
- version_id: params.version_id,
+ version_id: params.run_owner.version_id(),
scope_url: params.scope_url.clone(),
})
.with_api_storage_key(Some(storage_key))
@@ -1017,8 +985,10 @@ mod tests {
let version_id = ServiceWorkerVersionId(7);
let first_run = RendererServiceWorkerRunIdentity::fresh();
let second_run = RendererServiceWorkerRunIdentity::fresh();
- let first = RendererServiceWorkerHost::new_loading(version_id, &first_run);
- let second = RendererServiceWorkerHost::new_loading(version_id, &second_run);
+ let first_owner = ServiceWorkerRunOwner::new(version_id, first_run.clone());
+ let second_owner = ServiceWorkerRunOwner::new(version_id, second_run.clone());
+ let first = RendererServiceWorkerHost::new_loading(&first_owner);
+ let second = RendererServiceWorkerHost::new_loading(&second_owner);
assert_eq!(first.run_identity(), first_run);
assert_eq!(second.run_identity(), second_run);
diff --git a/moli-renderer-v8/src/service_worker_runtime/jobs.rs b/moli-renderer-v8/src/service_worker_runtime/jobs.rs
index 87bd355d6..6c8855266 100644
--- a/moli-renderer-v8/src/service_worker_runtime/jobs.rs
+++ b/moli-renderer-v8/src/service_worker_runtime/jobs.rs
@@ -6,10 +6,7 @@ use url::Url;
use crate::{
network::{BrowserResourceRuntimeBinding, ResourceRequestClient},
page_task_queue::RendererPageServiceWorkerTaskSender,
- runtime::{
- RendererBrowserContextRuntime, RendererServiceWorkerRunIdentity,
- RendererWorkerContextRuntime,
- },
+ runtime::{RendererBrowserContextRuntime, RendererWorkerContextRuntime},
types::{ServiceWorkerRegisterCompletion, ServiceWorkerUnregisterCompletion},
worker::{WorkerNetworkPolicy, WorkerScriptKind},
};
@@ -18,6 +15,7 @@ use super::{
errors::ServiceWorkerRegistrationError,
ids::{ServiceWorkerRegistrationId, ServiceWorkerVersionId},
registration::ServiceWorkerUpdateViaCache,
+ run_owner::ServiceWorkerRunOwner,
script_loading::ServiceWorkerScriptUpdateCheckParams,
snapshots::ServiceWorkerRegistrationSnapshot,
};
@@ -25,8 +23,7 @@ use super::{
#[derive(Clone)]
pub(crate) struct ServiceWorkerLaunchParams {
pub(super) registration_id: ServiceWorkerRegistrationId,
- pub(super) version_id: ServiceWorkerVersionId,
- pub(super) run: RendererServiceWorkerRunIdentity,
+ pub(super) run_owner: ServiceWorkerRunOwner,
pub(super) script_url: Url,
pub(super) scope_url: Url,
pub(super) storage_key: String,
@@ -747,8 +744,7 @@ impl ServiceWorkerVersionLaunchConfig {
pub(super) fn to_launch_params(
&self,
registration_id: ServiceWorkerRegistrationId,
- version_id: ServiceWorkerVersionId,
- run: &RendererServiceWorkerRunIdentity,
+ run_owner: &ServiceWorkerRunOwner,
script_url: Url,
scope_url: Url,
storage_key: String,
@@ -756,8 +752,7 @@ impl ServiceWorkerVersionLaunchConfig {
) -> ServiceWorkerLaunchParams {
ServiceWorkerLaunchParams {
registration_id,
- version_id,
- run: run.clone(),
+ run_owner: run_owner.clone(),
script_url,
scope_url,
storage_key,
diff --git a/moli-renderer-v8/src/service_worker_runtime/pending_clear.rs b/moli-renderer-v8/src/service_worker_runtime/pending_clear.rs
index 3dec577ce..8fd1f8be3 100644
--- a/moli-renderer-v8/src/service_worker_runtime/pending_clear.rs
+++ b/moli-renderer-v8/src/service_worker_runtime/pending_clear.rs
@@ -111,7 +111,7 @@ fn clear_registration_owner_state_locked(
let failed_fetch_event_ids = state
.pending_fetch_jobs
.iter()
- .filter(|(_, job)| registration_version_ids.contains(&job.version_id))
+ .filter(|(_, job)| registration_version_ids.contains(&job.version_id()))
.map(|(event_id, _)| *event_id)
.collect::<Vec<_>>();
let progress = failed_fetch_event_ids
diff --git a/moli-renderer-v8/src/service_worker_runtime/run_owner.rs b/moli-renderer-v8/src/service_worker_runtime/run_owner.rs
new file mode 100644
index 000000000..289ad23c3
--- /dev/null
+++ b/moli-renderer-v8/src/service_worker_runtime/run_owner.rs
@@ -0,0 +1,67 @@
+use crate::runtime::RendererServiceWorkerRunIdentity;
+
+use super::ids::ServiceWorkerVersionId;
+
+/// Exact owner of work emitted by one concrete ServiceWorker execution run.
+///
+/// A version id survives worker restarts, while the renderer run identity does
+/// not. Keeping the two values in one carrier prevents asynchronous events and
+/// completions from accidentally combining a version with another run.
+#[derive(Clone, Debug, Eq, PartialEq, Hash)]
+pub(crate) struct ServiceWorkerRunOwner {
+ version_id: ServiceWorkerVersionId,
+ run: RendererServiceWorkerRunIdentity,
+}
+
+impl ServiceWorkerRunOwner {
+ pub(crate) fn new(
+ version_id: ServiceWorkerVersionId,
+ run: RendererServiceWorkerRunIdentity,
+ ) -> Self {
+ Self { version_id, run }
+ }
+
+ pub(crate) fn fresh(version_id: ServiceWorkerVersionId) -> Self {
+ Self::new(version_id, RendererServiceWorkerRunIdentity::fresh())
+ }
+
+ pub(crate) fn version_id(&self) -> ServiceWorkerVersionId {
+ self.version_id
+ }
+
+ pub(crate) fn run_identity(&self) -> &RendererServiceWorkerRunIdentity {
+ &self.run
+ }
+
+ pub(crate) fn cloned_run_identity(&self) -> RendererServiceWorkerRunIdentity {
+ self.run.clone()
+ }
+
+ pub(crate) fn into_parts(self) -> (ServiceWorkerVersionId, RendererServiceWorkerRunIdentity) {
+ (self.version_id, self.run)
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn owner_binds_version_and_exact_run_as_one_value() {
+ let version_id = ServiceWorkerVersionId::from_u64_for_test(7);
+ let owner = ServiceWorkerRunOwner::fresh(version_id);
+
+ assert_eq!(owner.version_id(), version_id);
+ assert_eq!(owner.run_identity(), &owner.cloned_run_identity());
+ }
+
+ #[test]
+ fn restarting_a_version_creates_a_distinct_owner() {
+ let version_id = ServiceWorkerVersionId::from_u64_for_test(7);
+
+ assert_ne!(
+ ServiceWorkerRunOwner::fresh(version_id),
+ ServiceWorkerRunOwner::fresh(version_id)
+ );
+ }
+}
diff --git a/moli-renderer-v8/src/service_worker_runtime/service.rs b/moli-renderer-v8/src/service_worker_runtime/service.rs
index 8a32a3707..49c93b19d 100644
--- a/moli-renderer-v8/src/service_worker_runtime/service.rs
+++ b/moli-renderer-v8/src/service_worker_runtime/service.rs
@@ -34,9 +34,8 @@ use super::{
ServiceWorkerClientFrameType, ServiceWorkerClientQuery, ServiceWorkerClientQueryKind,
ServiceWorkerClientQueryOptions, ServiceWorkerClientQueryResult,
ServiceWorkerClientQueryType, ServiceWorkerClientSnapshot, ServiceWorkerClientType,
- ServiceWorkerClientVisibilityState, service_worker_current_url_for_creation_url,
- service_worker_exposed_client_id, service_worker_exposed_client_id_for_generation,
- service_worker_next_exposed_client_id_generation,
+ ServiceWorkerClientVisibilityState, allocate_service_worker_exposed_client_id,
+ service_worker_current_url_for_creation_url, service_worker_exposed_client_id,
},
diagnostics::{
ServiceWorkerMainScriptUpdateCheckDiagnostics, ServiceWorkerRegistrationDiagnostics,
@@ -100,6 +99,7 @@ use super::{
ServiceWorkerRegistration, ServiceWorkerUpdateViaCache,
},
resource_store::SharedServiceWorkerResourceStore,
+ run_owner::ServiceWorkerRunOwner,
script_loading::{
LoadedServiceWorkerScript, ServiceWorkerScriptLoadParams, ServiceWorkerScriptResource,
ServiceWorkerScriptUpdateCheckChange, ServiceWorkerScriptUpdateCheckCompletion,
@@ -620,6 +620,40 @@ mod tests {
crate::network::RendererResourceTaskRunner::for_test()
}
+ fn test_run_owner(
+ version_id: ServiceWorkerVersionId,
+ run: &RendererServiceWorkerRunIdentity,
+ ) -> ServiceWorkerRunOwner {
+ ServiceWorkerRunOwner::new(version_id, run.clone())
+ }
+
+ fn new_loading_test_host(
+ version_id: ServiceWorkerVersionId,
+ run: &RendererServiceWorkerRunIdentity,
+ ) -> SharedRendererServiceWorkerHost {
+ RendererServiceWorkerHost::new_loading(&test_run_owner(version_id, run))
+ }
+
+ fn new_running_test_host(
+ version_id: ServiceWorkerVersionId,
+ run: &RendererServiceWorkerRunIdentity,
+ ) -> SharedRendererServiceWorkerHost {
+ RendererServiceWorkerHost::new_running_without_handle_for_test(&test_run_owner(
+ version_id, run,
+ ))
+ }
+
+ fn new_running_test_host_with_handle(
+ version_id: ServiceWorkerVersionId,
+ run: &RendererServiceWorkerRunIdentity,
+ handle: crate::worker::WorkerHandle,
+ ) -> SharedRendererServiceWorkerHost {
+ RendererServiceWorkerHost::new_running_with_handle_for_test(
+ &test_run_owner(version_id, run),
+ handle,
+ )
+ }
+
fn async_subresource_completion_queue()
-> crate::page_task_queue::RendererResourceCompletionTestHarness {
crate::page_task_queue::RendererResourceCompletionTestHarness::new()
@@ -706,11 +740,11 @@ mod tests {
scope_url: Url,
) -> ServiceWorkerQueuedLaunch {
let run = exact_version_run(service, version_id);
+ let owner = test_run_owner(version_id, &run);
let launch_config = test_launch_config(service, &script_url, &scope_url);
let params = launch_config.to_launch_params(
registration_id,
- version_id,
- &run,
+ &owner,
script_url,
scope_url.clone(),
ServiceWorkerRegistrationKey::storage_key_for_scope_url(&scope_url),
@@ -718,7 +752,7 @@ mod tests {
);
ServiceWorkerQueuedLaunch {
params,
- host: RendererServiceWorkerHost::new_loading(version_id, &run),
+ host: new_loading_test_host(version_id, &run),
lifecycle_notifications: Vec::new(),
preloaded_script: None,
}
@@ -779,7 +813,6 @@ mod tests {
ServiceWorkerClient {
id: client_id,
exposed_id: service_worker_exposed_client_id(client_id),
- exposed_id_generation: 0,
creation_url: document_url.clone(),
document_url: current_document_url,
client_type: ServiceWorkerClientType::Window,
@@ -881,8 +914,7 @@ mod tests {
) -> ServiceWorkerFetchJob {
ServiceWorkerFetchJob {
internal_id,
- version_id,
- run: Some(run.clone()),
+ owner: Some(test_run_owner(version_id, run)),
request_url,
request_method: "GET".to_owned(),
request_headers: Vec::new(),
@@ -1131,7 +1163,6 @@ mod tests {
ServiceWorkerClient {
id: client_id,
exposed_id: service_worker_exposed_client_id(client_id),
- exposed_id_generation: 0,
creation_url,
document_url,
client_type,
@@ -1421,7 +1452,7 @@ mod tests {
let registration_id = ServiceWorkerRegistrationId(1);
let version_id = ServiceWorkerVersionId(1);
let run = RendererServiceWorkerRunIdentity::fresh();
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(version_id, &run);
+ let host = new_running_test_host(version_id, &run);
let mut state = service.inner.state.lock();
state.registrations.insert(
registration_id,
@@ -1479,7 +1510,7 @@ mod tests {
let registration_id = ServiceWorkerRegistrationId(1);
let version_id = ServiceWorkerVersionId(1);
let run = RendererServiceWorkerRunIdentity::fresh();
- let host = RendererServiceWorkerHost::new_loading(version_id, &run);
+ let host = new_loading_test_host(version_id, &run);
let mut state = service.inner.state.lock();
state.registrations.insert(
registration_id,
@@ -1539,7 +1570,7 @@ mod tests {
completion_tx: RendererPageServiceWorkerTaskSender,
) {
let run = RendererServiceWorkerRunIdentity::fresh();
- let host = RendererServiceWorkerHost::new_loading(version_id, &run);
+ let host = new_loading_test_host(version_id, &run);
let mut state = service.inner.state.lock();
let registration = state
.registrations
@@ -3428,7 +3459,6 @@ mod tests {
assert_eq!(client.creation_url, same_origin_creation_url);
assert_eq!(client.document_url, same_origin_current_url);
assert_eq!(client.exposed_id, initial_exposed_id);
- assert_eq!(client.exposed_id_generation, 0);
}
let cross_origin_creation_url = url("https://other.test/app/page.html#cross-origin");
@@ -3457,7 +3487,6 @@ mod tests {
assert_eq!(client.creation_url, cross_origin_creation_url);
assert_eq!(client.document_url, cross_origin_current_url);
assert_ne!(client.exposed_id, initial_exposed_id);
- assert_eq!(client.exposed_id_generation, 1);
let registration = state.registrations.get(&registration_id).unwrap();
assert!(!registration.controlled_client_ids.contains(&client_id));
}
@@ -3875,7 +3904,7 @@ mod tests {
let active_script_url = url("https://example.test/app/worker-v1.js");
let waiting_script_url = url("https://example.test/app/worker-v2.js");
let waiting_run = RendererServiceWorkerRunIdentity::fresh();
- let waiting_host = RendererServiceWorkerHost::new_loading(waiting_version_id, &waiting_run);
+ let waiting_host = new_loading_test_host(waiting_version_id, &waiting_run);
{
let mut state = service.inner.state.lock();
state.live_clients.insert(
@@ -3883,7 +3912,6 @@ mod tests {
ServiceWorkerClient {
id: client_id,
exposed_id: service_worker_exposed_client_id(client_id),
- exposed_id_generation: 0,
creation_url: url("https://example.test/app/page.html"),
document_url: url("https://example.test/app/page.html"),
client_type: ServiceWorkerClientType::Window,
@@ -4000,7 +4028,10 @@ mod tests {
panic!("expected queued activate event");
};
assert_eq!(event.kind, ServiceWorkerLifecycleEventKind::Activate);
- assert_eq!(event.run, waiting_run);
+ assert_eq!(
+ event.owner,
+ test_run_owner(waiting_version_id, &waiting_run)
+ );
}
#[test]
@@ -4210,8 +4241,7 @@ mod tests {
event_id,
ServiceWorkerFetchJob {
internal_id: event_id.as_u64(),
- version_id,
- run: Some(run),
+ owner: Some(ServiceWorkerRunOwner::new(version_id, run)),
request_url: request_url.clone(),
request_method: "GET".to_owned(),
request_headers: Vec::new(),
@@ -4449,8 +4479,7 @@ self.addEventListener("message", event => {
);
handle.dispatch_service_worker_message_event(ServiceWorkerMessageEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(61),
- version_id,
- run: run.clone(),
+ owner: test_run_owner(version_id, &run),
source_client_id: None,
source_client_url: None,
source_client_snapshot: None,
@@ -4466,8 +4495,7 @@ self.addEventListener("message", event => {
let mut parent_rx = handle
.take_receiver()
.expect("service worker should expose parent receiver");
- let host =
- RendererServiceWorkerHost::new_running_with_handle_for_test(version_id, &run, handle);
+ let host = new_running_test_host_with_handle(version_id, &run, handle);
{
let mut state = service.inner.state.lock();
state.registrations.insert(
@@ -4679,8 +4707,7 @@ self.addEventListener("message", event => {
event_id,
ServiceWorkerFetchJob {
internal_id: 131,
- version_id,
- run: Some(run.clone()),
+ owner: Some(test_run_owner(version_id, &run)),
request_url: request_url.clone(),
request_method: "GET".to_owned(),
request_headers: Vec::new(),
@@ -4753,8 +4780,7 @@ self.addEventListener("message", event => {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: test_run_owner(version_id, &run),
result: ServiceWorkerFetchResult::Failure("done".to_owned()),
});
@@ -4955,8 +4981,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(1),
- version_id,
- run,
+ owner: test_run_owner(version_id, &run),
kind: ServiceWorkerLifecycleEventKind::Install,
result: Ok(()),
});
@@ -5029,8 +5054,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(1),
- version_id,
- run,
+ owner: test_run_owner(version_id, &run),
kind: ServiceWorkerLifecycleEventKind::Install,
result: Ok(()),
});
@@ -5145,8 +5169,7 @@ self.addEventListener("message", event => {
assert!(!first_queue.has_ready_task());
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(1),
- version_id: first_version_id,
- run: first_run,
+ owner: test_run_owner(first_version_id, &first_run),
kind: ServiceWorkerLifecycleEventKind::Install,
result: Ok(()),
});
@@ -5367,8 +5390,7 @@ self.addEventListener("message", event => {
assert!(!second_completion_queue.has_ready_task());
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(1),
- version_id,
- run,
+ owner: test_run_owner(version_id, &run),
kind: ServiceWorkerLifecycleEventKind::Install,
result: Ok(()),
});
@@ -5459,8 +5481,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(1),
- version_id: first_version_id,
- run: first_run,
+ owner: test_run_owner(first_version_id, &first_run),
kind: ServiceWorkerLifecycleEventKind::Install,
result: Ok(()),
});
@@ -5482,8 +5503,7 @@ self.addEventListener("message", event => {
assert!(!third_completion_queue.has_ready_task());
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(2),
- version_id: second_version_id,
- run: second_run,
+ owner: test_run_owner(second_version_id, &second_run),
kind: ServiceWorkerLifecycleEventKind::Install,
result: Ok(()),
});
@@ -5551,8 +5571,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(1),
- version_id,
- run,
+ owner: test_run_owner(version_id, &run),
kind: ServiceWorkerLifecycleEventKind::Install,
result: Ok(()),
});
@@ -5609,8 +5628,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(1),
- version_id,
- run,
+ owner: test_run_owner(version_id, &run),
kind: ServiceWorkerLifecycleEventKind::Install,
result: Ok(()),
});
@@ -5678,8 +5696,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(1),
- version_id: first_version_id,
- run: first_run,
+ owner: test_run_owner(first_version_id, &first_run),
kind: ServiceWorkerLifecycleEventKind::Install,
result: Ok(()),
});
@@ -6115,8 +6132,7 @@ self.addEventListener("message", event => {
exact_created_target_run(&service.take_target_output_events_for_test(), version_id)
};
service.enqueue_worker_start_failed(
- version_id,
- created_run.clone(),
+ test_run_owner(version_id, &created_run),
ServiceWorkerVersionStartFailure::ScriptLoad {
message: "service worker script load failed: network request client not available"
.to_owned(),
@@ -6203,8 +6219,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(1),
- version_id,
- run,
+ owner: test_run_owner(version_id, &run),
kind: ServiceWorkerLifecycleEventKind::Install,
result: Ok(()),
});
@@ -6233,8 +6248,7 @@ self.addEventListener("message", event => {
let (script_url, _, _, version_id) = insert_starting_version(&service);
service.enqueue_worker_start_completed(
- version_id,
- RendererServiceWorkerRunIdentity::fresh(),
+ ServiceWorkerRunOwner::fresh(version_id),
"https://example.test/app/sw.js".to_owned(),
test_script_resource(&script_url),
ServiceWorkerFetchHandlerType::NotSkippable,
@@ -6475,10 +6489,10 @@ self.addEventListener("message", event => {
.iter()
.next()
.expect("install launch should wait for debugger");
- assert_eq!(launch.params.version_id, *version_id);
+ assert_eq!(launch.params.run_owner.version_id(), *version_id);
assert_eq!(
- launch.params.run,
- state
+ launch.params.run_owner.run_identity(),
+ &state
.versions
.get(version_id)
.expect("starting version")
@@ -6700,7 +6714,7 @@ self.addEventListener("message", event => {
version.run = run.clone();
version.should_pause_on_start_for_devtools = true;
version.running_state = ServiceWorkerVersionRunningState::Starting {
- host: RendererServiceWorkerHost::new_loading(version_id, &run),
+ host: new_loading_test_host(version_id, &run),
};
}
service.set_devtools_attached_for_version(version_id, true);
@@ -7568,8 +7582,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(1),
- version_id,
- run,
+ owner: test_run_owner(version_id, &run),
kind: ServiceWorkerLifecycleEventKind::Install,
result: Ok(()),
});
@@ -7689,8 +7702,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(1),
- version_id,
- run,
+ owner: test_run_owner(version_id, &run),
kind: ServiceWorkerLifecycleEventKind::Install,
result: Ok(()),
});
@@ -7751,8 +7763,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(1),
- version_id: first_version_id,
- run: first_run,
+ owner: test_run_owner(first_version_id, &first_run),
kind: ServiceWorkerLifecycleEventKind::Install,
result: Ok(()),
});
@@ -7833,8 +7844,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(1),
- version_id: installing_version_id,
- run: installing_run.clone(),
+ owner: test_run_owner(installing_version_id, &installing_run),
kind: ServiceWorkerLifecycleEventKind::Install,
result: Ok(()),
});
@@ -8326,7 +8336,7 @@ self.addEventListener("message", event => {
let client_id = register_client_for_test(&service, document_url.clone());
let event_id = ServiceWorkerEventId(7);
let mut completion_queue = async_subresource_completion_queue();
- let host = RendererServiceWorkerHost::new_loading(version_id, &run);
+ let host = new_loading_test_host(version_id, &run);
{
let mut state = service.inner.state.lock();
state.registrations.insert(
@@ -8353,8 +8363,7 @@ self.addEventListener("message", event => {
event_id,
ServiceWorkerFetchJob {
internal_id: 41,
- version_id,
- run: Some(run.clone()),
+ owner: Some(test_run_owner(version_id, &run)),
request_url: request_url.clone(),
request_method: "GET".to_owned(),
request_headers: Vec::new(),
@@ -8408,8 +8417,7 @@ self.addEventListener("message", event => {
pending_start_events: VecDeque::from([ServiceWorkerPendingStartEvent::Fetch(
ServiceWorkerFetchEvent {
event_id,
- version_id,
- run: run.clone(),
+ owner: test_run_owner(version_id, &run),
request: ServiceWorkerFetchRequest {
client_id,
resulting_client_id: None,
@@ -8497,9 +8505,7 @@ self.addEventListener("message", event => {
let version = state.versions.get_mut(&version_id).unwrap();
version.run = run.clone();
version.running_state = ServiceWorkerVersionRunningState::Running {
- host: RendererServiceWorkerHost::new_running_without_handle_for_test(
- version_id, &run,
- ),
+ host: new_running_test_host(version_id, &run),
};
version.in_flight_event_count = 1;
state.pending_fetch_jobs.insert(
@@ -8532,8 +8538,7 @@ self.addEventListener("message", event => {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: test_run_owner(version_id, &run),
result: ServiceWorkerFetchResult::Fallback,
});
{
@@ -8596,8 +8601,7 @@ self.addEventListener("message", event => {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: test_run_owner(version_id, &run),
result: ServiceWorkerFetchResult::Fallback,
});
@@ -8662,11 +8666,12 @@ self.addEventListener("message", event => {
navigation_preload_cancel_handle.clone(),
);
- assert!(service.mark_navigation_preload_response_started(
- event_id,
- version_id,
- run.clone(),
- ));
+ assert!(
+ service.mark_navigation_preload_response_started(
+ event_id,
+ &test_run_owner(version_id, &run),
+ )
+ );
assert!(
!navigation_preload_cancel_handle.is_cancelled(),
"marking response-started should detach the runtime cancel handle, not cancel it"
@@ -8674,8 +8679,7 @@ self.addEventListener("message", event => {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: test_run_owner(version_id, &run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
status: 200,
status_text: "OK".to_owned(),
@@ -8781,9 +8785,7 @@ self.addEventListener("message", event => {
let version = state.versions.get_mut(&version_id).unwrap();
version.run = run.clone();
version.running_state = ServiceWorkerVersionRunningState::Running {
- host: RendererServiceWorkerHost::new_running_without_handle_for_test(
- version_id, &run,
- ),
+ host: new_running_test_host(version_id, &run),
};
version.in_flight_event_count = 1;
state.pending_fetch_jobs.insert(
@@ -8866,9 +8868,7 @@ self.addEventListener("message", event => {
let version = state.versions.get_mut(&version_id).unwrap();
version.run = run.clone();
version.running_state = ServiceWorkerVersionRunningState::Running {
- host: RendererServiceWorkerHost::new_running_with_handle_for_test(
- version_id, &run, handle,
- ),
+ host: new_running_test_host_with_handle(version_id, &run, handle),
};
version.in_flight_event_count = 1;
let mut job = test_fetch_job(
@@ -8944,9 +8944,7 @@ self.addEventListener("message", event => {
let version = state.versions.get_mut(&version_id).unwrap();
version.run = run.clone();
version.running_state = ServiceWorkerVersionRunningState::Running {
- host: RendererServiceWorkerHost::new_running_without_handle_for_test(
- version_id, &run,
- ),
+ host: new_running_test_host(version_id, &run),
};
version.in_flight_event_count = 1;
let mut job = test_fetch_job(
@@ -8982,8 +8980,7 @@ self.addEventListener("message", event => {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: test_run_owner(version_id, &run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
status: 200,
status_text: "OK".to_owned(),
@@ -9047,13 +9044,12 @@ self.addEventListener("message", event => {
let version = state.versions.get_mut(&version_id).unwrap();
version.run = run.clone();
version.running_state = ServiceWorkerVersionRunningState::Starting {
- host: RendererServiceWorkerHost::new_loading(version_id, &run),
+ host: new_loading_test_host(version_id, &run),
};
version.pending_start_events = VecDeque::from([ServiceWorkerPendingStartEvent::Fetch(
ServiceWorkerFetchEvent {
event_id,
- version_id,
- run: run.clone(),
+ owner: test_run_owner(version_id, &run),
request: test_fetch_request(client_id, request_url),
navigation_preload_sent: false,
},
@@ -9074,8 +9070,7 @@ self.addEventListener("message", event => {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: test_run_owner(version_id, &run),
result: ServiceWorkerFetchResult::Fallback,
});
{
@@ -9099,7 +9094,7 @@ self.addEventListener("message", event => {
let request_url = url("https://example.test/app/data.txt");
let client_id = register_client_for_test(&service, document_url.clone());
let mut completion_queue = async_subresource_completion_queue();
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(version_id, &run);
+ let host = new_running_test_host(version_id, &run);
{
let mut state = service.inner.state.lock();
state.registrations.insert(
@@ -9233,7 +9228,7 @@ self.addEventListener("message", event => {
[document_url.clone()],
);
let client_id = client_id_for_document(&service, &document_url);
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(version_id, &run);
+ let host = new_running_test_host(version_id, &run);
{
let mut state = service.inner.state.lock();
let version = state.versions.get_mut(&version_id).unwrap();
@@ -9288,8 +9283,7 @@ self.addEventListener("message", event => {
assert!(version.pending_start_events.is_empty());
assert_eq!(version.pending_activation_fetch_events.len(), 1);
let event = version.pending_activation_fetch_events.front().unwrap();
- assert_eq!(event.version_id, version_id);
- assert_eq!(event.run, run);
+ assert_eq!(event.owner, test_run_owner(version_id, &run));
assert_eq!(
event.request.destination,
ServiceWorkerRequestDestination::Document
@@ -9302,8 +9296,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(77),
- version_id,
- run,
+ owner: test_run_owner(version_id, &run),
kind: ServiceWorkerLifecycleEventKind::Activate,
result: Ok(()),
});
@@ -9382,8 +9375,7 @@ self.addEventListener("message", event => {
let mut parent_rx = handle
.take_receiver()
.expect("service worker should expose parent receiver");
- let host =
- RendererServiceWorkerHost::new_running_with_handle_for_test(version_id, &run, handle);
+ let host = new_running_test_host_with_handle(version_id, &run, handle);
insert_registered_version(
&service,
registration_id,
@@ -9517,7 +9509,7 @@ self.addEventListener("message", event => {
[document_url.clone()],
);
let client_id = client_id_for_document(&service, &document_url);
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(version_id, &run);
+ let host = new_running_test_host(version_id, &run);
{
let mut state = service.inner.state.lock();
let version = state.versions.get_mut(&version_id).unwrap();
@@ -9608,7 +9600,7 @@ self.addEventListener("message", event => {
[document_url.clone()],
);
let client_id = client_id_for_document(&service, &document_url);
- let host = RendererServiceWorkerHost::new_loading(version_id, &run);
+ let host = new_loading_test_host(version_id, &run);
let request = ServiceWorkerFetchRequest {
client_id,
resulting_client_id: None,
@@ -9631,8 +9623,7 @@ self.addEventListener("message", event => {
event_id,
ServiceWorkerFetchJob {
internal_id: 90,
- version_id,
- run: Some(run.clone()),
+ owner: Some(test_run_owner(version_id, &run)),
request_url,
request_method: "GET".to_owned(),
request_headers: Vec::new(),
@@ -9673,8 +9664,7 @@ self.addEventListener("message", event => {
version.pending_start_events = VecDeque::from([ServiceWorkerPendingStartEvent::Fetch(
ServiceWorkerFetchEvent {
event_id,
- version_id,
- run: run.clone(),
+ owner: test_run_owner(version_id, &run),
request,
navigation_preload_sent: false,
},
@@ -9737,7 +9727,7 @@ self.addEventListener("message", event => {
let client_id = register_client_for_test(&service, document_url.clone());
let event_id = ServiceWorkerEventId(11);
let mut completion_queue = async_subresource_completion_queue();
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(version_id, &run);
+ let host = new_running_test_host(version_id, &run);
{
let mut state = service.inner.state.lock();
state.registrations.insert(
@@ -9764,8 +9754,7 @@ self.addEventListener("message", event => {
event_id,
ServiceWorkerFetchJob {
internal_id: 77,
- version_id,
- run: Some(run.clone()),
+ owner: Some(test_run_owner(version_id, &run)),
request_url,
request_method: "GET".to_owned(),
request_headers: Vec::new(),
@@ -9836,8 +9825,7 @@ self.addEventListener("message", event => {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: test_run_owner(version_id, &run),
result: ServiceWorkerFetchResult::Failure("handled".to_owned()),
});
@@ -9896,7 +9884,7 @@ self.addEventListener("message", event => {
scope_url.clone(),
[],
);
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(version_id, &run);
+ let host = new_running_test_host(version_id, &run);
{
let mut state = service.inner.state.lock();
let version = state.versions.get_mut(&version_id).unwrap();
@@ -9992,10 +9980,7 @@ self.addEventListener("message", event => {
scope_url.clone(),
[],
);
- let waiting_host = RendererServiceWorkerHost::new_running_without_handle_for_test(
- waiting_version_id,
- &waiting_run,
- );
+ let waiting_host = new_running_test_host(waiting_version_id, &waiting_run);
{
let mut state = service.inner.state.lock();
let registration = state.registrations.get_mut(&registration_id).unwrap();
@@ -10199,7 +10184,7 @@ self.addEventListener("message", event => {
let version = state.versions.get_mut(&version_id).unwrap();
version.run = run.clone();
version.running_state = ServiceWorkerVersionRunningState::Starting {
- host: RendererServiceWorkerHost::new_loading(version_id, &run),
+ host: new_loading_test_host(version_id, &run),
};
}
@@ -10245,15 +10230,13 @@ self.addEventListener("message", event => {
let ServiceWorkerPendingStartEvent::Push(push) = &version.pending_start_events[0] else {
panic!("expected pending push event");
};
- assert_eq!(push.version_id, version_id);
- assert_eq!(push.run, run);
+ assert_eq!(push.owner, test_run_owner(version_id, &run));
assert_eq!(push.data.as_deref(), Some(&b"payload"[..]));
let ServiceWorkerPendingStartEvent::Sync(sync) = &version.pending_start_events[1] else {
panic!("expected pending sync event");
};
assert_eq!(sync.registration_id, registration_id);
- assert_eq!(sync.version_id, version_id);
- assert_eq!(sync.run, run);
+ assert_eq!(sync.owner, test_run_owner(version_id, &run));
assert_eq!(sync.tag, "sync-tag");
assert!(sync.last_chance);
let ServiceWorkerPendingStartEvent::PeriodicSync(periodic) =
@@ -10262,8 +10245,7 @@ self.addEventListener("message", event => {
panic!("expected pending periodic sync event");
};
assert_eq!(periodic.registration_id, registration_id);
- assert_eq!(periodic.version_id, version_id);
- assert_eq!(periodic.run, run);
+ assert_eq!(periodic.owner, test_run_owner(version_id, &run));
assert_eq!(periodic.tag, "periodic-tag");
}
@@ -10281,7 +10263,7 @@ self.addEventListener("message", event => {
let document_url = url("https://example.test/app/page.html");
let request_url = url("https://example.test/app/data.txt");
let event_id = ServiceWorkerEventId(19);
- let waiting_host = RendererServiceWorkerHost::new_loading(waiting_version_id, &waiting_run);
+ let waiting_host = new_loading_test_host(waiting_version_id, &waiting_run);
let mut completion_queue = async_subresource_completion_queue();
{
let mut state = service.inner.state.lock();
@@ -10309,8 +10291,7 @@ self.addEventListener("message", event => {
event_id,
ServiceWorkerFetchJob {
internal_id: 91,
- version_id: active_version_id,
- run: Some(active_run.clone()),
+ owner: Some(test_run_owner(active_version_id, &active_run)),
request_url: request_url.clone(),
request_method: "GET".to_owned(),
request_headers: Vec::new(),
@@ -10404,8 +10385,7 @@ self.addEventListener("message", event => {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id: active_version_id,
- run: active_run.clone(),
+ owner: test_run_owner(active_version_id, &active_run),
result: ServiceWorkerFetchResult::Failure("done".to_owned()),
});
@@ -10441,7 +10421,7 @@ self.addEventListener("message", event => {
let run = RendererServiceWorkerRunIdentity::fresh();
let scope_url = url("https://example.test/app/");
let script_url = url("https://example.test/app/worker.js");
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(version_id, &run);
+ let host = new_running_test_host(version_id, &run);
{
let mut state = service.inner.state.lock();
state.registrations.insert(
@@ -10521,8 +10501,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(1),
- version_id,
- run,
+ owner: test_run_owner(version_id, &run),
kind: ServiceWorkerLifecycleEventKind::Install,
result: Ok(()),
});
@@ -10548,8 +10527,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(1),
- version_id,
- run,
+ owner: test_run_owner(version_id, &run),
kind: ServiceWorkerLifecycleEventKind::Install,
result: Err("service worker waitUntil promise rejected".to_owned()),
});
@@ -10576,8 +10554,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(2),
- version_id,
- run,
+ owner: test_run_owner(version_id, &run),
kind: ServiceWorkerLifecycleEventKind::Activate,
result: Err("service worker waitUntil promise rejected".to_owned()),
});
@@ -10685,8 +10662,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(2),
- version_id: activating_version_id,
- run: activating_run,
+ owner: test_run_owner(activating_version_id, &activating_run),
kind: ServiceWorkerLifecycleEventKind::Activate,
result: Ok(()),
});
@@ -10803,8 +10779,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(2),
- version_id: activating_version_id,
- run: activating_run,
+ owner: test_run_owner(activating_version_id, &activating_run),
kind: ServiceWorkerLifecycleEventKind::Activate,
result: Ok(()),
});
@@ -10880,8 +10855,7 @@ self.addEventListener("message", event => {
let root_run = exact_version_run(&service, root_version_id);
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(2),
- version_id: root_version_id,
- run: root_run,
+ owner: test_run_owner(root_version_id, &root_run),
kind: ServiceWorkerLifecycleEventKind::Activate,
result: Ok(()),
});
@@ -10909,8 +10883,7 @@ self.addEventListener("message", event => {
let admin_run = exact_version_run(&service, admin_version_id);
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(3),
- version_id: admin_version_id,
- run: admin_run,
+ owner: test_run_owner(admin_version_id, &admin_run),
kind: ServiceWorkerLifecycleEventKind::Activate,
result: Ok(()),
});
@@ -10935,10 +10908,7 @@ self.addEventListener("message", event => {
let active_script_url = url("https://example.test/app/worker-v1.js");
let installing_script_url = url("https://example.test/app/worker-v2.js");
let installing_run = RendererServiceWorkerRunIdentity::fresh();
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(
- installing_version_id,
- &installing_run,
- );
+ let host = new_running_test_host(installing_version_id, &installing_run);
let (force_update_tx, mut force_update_rx) = tokio::sync::oneshot::channel();
{
let mut state = service.inner.state.lock();
@@ -10950,7 +10920,6 @@ self.addEventListener("message", event => {
ServiceWorkerClient {
id: client_id,
exposed_id: service_worker_exposed_client_id(client_id),
- exposed_id_generation: 0,
creation_url: scope_url.clone(),
document_url: scope_url.clone(),
client_type: ServiceWorkerClientType::Window,
@@ -11045,8 +11014,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(1),
- version_id: installing_version_id,
- run: installing_run.clone(),
+ owner: test_run_owner(installing_version_id, &installing_run),
kind: ServiceWorkerLifecycleEventKind::Install,
result: Ok(()),
});
@@ -11091,8 +11059,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(2),
- version_id: installing_version_id,
- run: installing_run.clone(),
+ owner: test_run_owner(installing_version_id, &installing_run),
kind: ServiceWorkerLifecycleEventKind::Activate,
result: Ok(()),
});
@@ -11121,10 +11088,7 @@ self.addEventListener("message", event => {
let active_script_url = url("https://example.test/app/worker-v1.js");
let installing_script_url = url("https://example.test/app/worker-v2.js");
let installing_run = RendererServiceWorkerRunIdentity::fresh();
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(
- installing_version_id,
- &installing_run,
- );
+ let host = new_running_test_host(installing_version_id, &installing_run);
{
let mut state = service.inner.state.lock();
let client_id = ServiceWorkerClientId::from_u64_for_test(1);
@@ -11133,7 +11097,6 @@ self.addEventListener("message", event => {
ServiceWorkerClient {
id: client_id,
exposed_id: service_worker_exposed_client_id(client_id),
- exposed_id_generation: 0,
creation_url: url("https://example.test/app/page.html"),
document_url: url("https://example.test/app/page.html"),
client_type: ServiceWorkerClientType::Window,
@@ -11231,8 +11194,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(1),
- version_id: installing_version_id,
- run: installing_run.clone(),
+ owner: test_run_owner(installing_version_id, &installing_run),
kind: ServiceWorkerLifecycleEventKind::Install,
result: Ok(()),
});
@@ -11260,10 +11222,7 @@ self.addEventListener("message", event => {
let active_script_url = url("https://example.test/app/worker-v1.js");
let installing_script_url = url("https://example.test/app/worker-v2.js");
let installing_run = RendererServiceWorkerRunIdentity::fresh();
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(
- installing_version_id,
- &installing_run,
- );
+ let host = new_running_test_host(installing_version_id, &installing_run);
{
let mut state = service.inner.state.lock();
state.registrations.insert(
@@ -11344,8 +11303,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(1),
- version_id: installing_version_id,
- run: installing_run.clone(),
+ owner: test_run_owner(installing_version_id, &installing_run),
kind: ServiceWorkerLifecycleEventKind::Install,
result: Ok(()),
});
@@ -11484,8 +11442,8 @@ self.addEventListener("message", event => {
panic!("expected stopped waiting activation to start worker");
};
assert_eq!(launch.params.registration_id, registration_id);
- assert_eq!(launch.params.version_id, waiting_version_id);
- let restarted_run = launch.params.run.clone();
+ assert_eq!(launch.params.run_owner.version_id(), waiting_version_id);
+ let restarted_run = launch.params.run_owner.cloned_run_identity();
assert_ne!(restarted_run, previous_waiting_run);
assert_eq!(launch.params.script_url, waiting_script_url);
assert_eq!(launch.params.scope_url, scope_url);
@@ -11514,8 +11472,10 @@ self.addEventListener("message", event => {
else {
panic!("expected pending activate lifecycle event");
};
- assert_eq!(event.version_id, waiting_version_id);
- assert_eq!(event.run, restarted_run);
+ assert_eq!(
+ event.owner,
+ test_run_owner(waiting_version_id, &restarted_run)
+ );
assert_eq!(event.kind, ServiceWorkerLifecycleEventKind::Activate);
}
@@ -11527,7 +11487,7 @@ self.addEventListener("message", event => {
let run = RendererServiceWorkerRunIdentity::fresh();
let scope_url = url("https://example.test/app/");
let script_url = url("https://example.test/app/worker.js");
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(version_id, &run);
+ let host = new_running_test_host(version_id, &run);
{
let mut state = service.inner.state.lock();
state.registrations.insert(
@@ -11588,8 +11548,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(7),
- version_id,
- run,
+ owner: test_run_owner(version_id, &run),
kind: ServiceWorkerLifecycleEventKind::Activate,
result: Ok(()),
});
@@ -11618,7 +11577,7 @@ self.addEventListener("message", event => {
let active_script_url = url("https://example.test/app/worker-v1.js");
let waiting_script_url = url("https://example.test/app/worker-v2.js");
let event_id = ServiceWorkerEventId(7);
- let host = RendererServiceWorkerHost::new_loading(waiting_version_id, &run);
+ let host = new_loading_test_host(waiting_version_id, &run);
{
let mut state = service.inner.state.lock();
state.registrations.insert(
@@ -11688,8 +11647,7 @@ self.addEventListener("message", event => {
pending_start_events: VecDeque::from([
ServiceWorkerPendingStartEvent::Lifecycle(ServiceWorkerLifecycleEvent {
event_id,
- version_id: waiting_version_id,
- run: run.clone(),
+ owner: test_run_owner(waiting_version_id, &run),
kind: ServiceWorkerLifecycleEventKind::Activate,
}),
]),
@@ -11749,7 +11707,6 @@ self.addEventListener("message", event => {
ServiceWorkerClient {
id: client_id,
exposed_id: service_worker_exposed_client_id(client_id),
- exposed_id_generation: 0,
creation_url: url("https://example.test/app/page.html"),
document_url: url("https://example.test/app/page.html"),
client_type: ServiceWorkerClientType::Window,
@@ -11844,8 +11801,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(2),
- version_id: waiting_version_id,
- run: waiting_run,
+ owner: test_run_owner(waiting_version_id, &waiting_run),
kind: ServiceWorkerLifecycleEventKind::Activate,
result: Ok(()),
});
@@ -11898,10 +11854,7 @@ self.addEventListener("message", event => {
let document_url = url("https://example.test/app/page.html");
let request_url = url("https://example.test/app/data.txt");
let client_id = ServiceWorkerClientId::from_u64_for_test(1);
- let active_host = RendererServiceWorkerHost::new_running_without_handle_for_test(
- active_version_id,
- &active_run,
- );
+ let active_host = new_running_test_host(active_version_id, &active_run);
let mut completion_queue = async_subresource_completion_queue();
{
let mut state = service.inner.state.lock();
@@ -11910,7 +11863,6 @@ self.addEventListener("message", event => {
ServiceWorkerClient {
id: client_id,
exposed_id: service_worker_exposed_client_id(client_id),
- exposed_id_generation: 0,
creation_url: document_url.clone(),
document_url: document_url.clone(),
client_type: ServiceWorkerClientType::Window,
@@ -11956,8 +11908,7 @@ self.addEventListener("message", event => {
event_id,
ServiceWorkerFetchJob {
internal_id,
- version_id: active_version_id,
- run: Some(active_run.clone()),
+ owner: Some(test_run_owner(active_version_id, &active_run)),
request_url: request_url.clone(),
request_method: "GET".to_owned(),
request_headers: Vec::new(),
@@ -12012,8 +11963,7 @@ self.addEventListener("message", event => {
pending_start_events: VecDeque::from([ServiceWorkerPendingStartEvent::Fetch(
ServiceWorkerFetchEvent {
event_id: pending_event_id,
- version_id: active_version_id,
- run: active_run.clone(),
+ owner: test_run_owner(active_version_id, &active_run),
request: ServiceWorkerFetchRequest {
client_id,
resulting_client_id: None,
@@ -12034,8 +11984,7 @@ self.addEventListener("message", event => {
)]),
pending_activation_fetch_events: VecDeque::from([ServiceWorkerFetchEvent {
event_id: activation_wait_event_id,
- version_id: active_version_id,
- run: active_run.clone(),
+ owner: test_run_owner(active_version_id, &active_run),
request: ServiceWorkerFetchRequest {
client_id,
resulting_client_id: None,
@@ -12092,8 +12041,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(2),
- version_id: waiting_version_id,
- run: waiting_run.clone(),
+ owner: test_run_owner(waiting_version_id, &waiting_run),
kind: ServiceWorkerLifecycleEventKind::Activate,
result: Ok(()),
});
@@ -12171,10 +12119,7 @@ self.addEventListener("message", event => {
);
{
let mut state = service.inner.state.lock();
- let active_host = RendererServiceWorkerHost::new_running_without_handle_for_test(
- active_version_id,
- &active_run,
- );
+ let active_host = new_running_test_host(active_version_id, &active_run);
let active = state
.versions
.get_mut(&active_version_id)
@@ -12224,8 +12169,7 @@ self.addEventListener("message", event => {
service.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: ServiceWorkerEventId(2),
- version_id: waiting_version_id,
- run: waiting_run.clone(),
+ owner: test_run_owner(waiting_version_id, &waiting_run),
kind: ServiceWorkerLifecycleEventKind::Activate,
result: Ok(()),
});
@@ -12314,8 +12258,7 @@ self.addEventListener("message", event => {
else {
panic!("expected pending message event");
};
- assert_eq!(event.version_id, version_id);
- assert_eq!(event.run, restarted_run);
+ assert_eq!(event.owner, test_run_owner(version_id, &restarted_run));
assert_eq!(event.source_client_id, Some(client_id));
assert_eq!(
event.source_client_snapshot,
@@ -12380,7 +12323,7 @@ self.addEventListener("message", event => {
let run = RendererServiceWorkerRunIdentity::fresh();
let scope_url = url("https://example.test/app/");
let script_url = url("https://example.test/app/sw.js");
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(version_id, &run);
+ let host = new_running_test_host(version_id, &run);
{
let mut state = service.inner.state.lock();
state.registrations.insert(
@@ -12434,8 +12377,7 @@ self.addEventListener("message", event => {
service.finish_message_event_completed(ServiceWorkerMessageCompletion {
event_id: ServiceWorkerEventId(7),
- version_id,
- run,
+ owner: test_run_owner(version_id, &run),
result: Ok(()),
});
@@ -12457,7 +12399,7 @@ self.addEventListener("message", event => {
let run = RendererServiceWorkerRunIdentity::fresh();
let scope_url = url("https://example.test/app/");
let script_url = url("https://example.test/app/sw.js");
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(version_id, &run);
+ let host = new_running_test_host(version_id, &run);
{
let mut state = service.inner.state.lock();
state.registrations.insert(
@@ -12551,7 +12493,7 @@ self.addEventListener("message", event => {
let run = RendererServiceWorkerRunIdentity::fresh();
let scope_url = url("https://example.test/app/");
let script_url = url("https://example.test/app/sw.js");
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(version_id, &run);
+ let host = new_running_test_host(version_id, &run);
{
let mut state = service.inner.state.lock();
state.registrations.insert(
@@ -12628,7 +12570,7 @@ self.addEventListener("message", event => {
let run = RendererServiceWorkerRunIdentity::fresh();
let scope_url = url("https://example.test/app/");
let script_url = url("https://example.test/app/sw.js");
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(version_id, &run);
+ let host = new_running_test_host(version_id, &run);
{
let mut state = service.inner.state.lock();
state.registrations.insert(
@@ -12711,7 +12653,7 @@ self.addEventListener("message", event => {
let run = RendererServiceWorkerRunIdentity::fresh();
let scope_url = url("https://example.test/app/");
let script_url = url("https://example.test/app/sw.js");
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(version_id, &run);
+ let host = new_running_test_host(version_id, &run);
{
let mut state = service.inner.state.lock();
state.registrations.insert(
@@ -12817,7 +12759,7 @@ self.addEventListener("message", event => {
let sync_key = (registration_id, "sync-tag".to_owned());
let scope_url = url("https://example.test/app/");
let script_url = url("https://example.test/app/sw.js");
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(version_id, &run);
+ let host = new_running_test_host(version_id, &run);
{
let mut state = service.inner.state.lock();
state.registrations.insert(
@@ -12958,7 +12900,7 @@ self.addEventListener("message", event => {
let run = RendererServiceWorkerRunIdentity::fresh();
let scope_url = url("https://example.test/app/");
let script_url = url("https://example.test/app/sw.js");
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(version_id, &run);
+ let host = new_running_test_host(version_id, &run);
{
let mut state = service.inner.state.lock();
state.registrations.insert(
@@ -13027,7 +12969,7 @@ self.addEventListener("message", event => {
};
assert_eq!(event.tag, "sync-tag");
assert!(event.last_chance);
- assert_eq!(event.run, run);
+ assert_eq!(event.owner, test_run_owner(version_id, &run));
}
#[test]
@@ -13110,7 +13052,7 @@ self.addEventListener("message", event => {
let run = RendererServiceWorkerRunIdentity::fresh();
let scope_url = url("https://example.test/app/");
let script_url = url("https://example.test/app/sw.js");
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(version_id, &run);
+ let host = new_running_test_host(version_id, &run);
{
let mut state = service.inner.state.lock();
state.registrations.insert(
@@ -13179,8 +13121,7 @@ self.addEventListener("message", event => {
panic!("expected queued periodic sync event");
};
assert_eq!(event.registration_id, registration_id);
- assert_eq!(event.version_id, version_id);
- assert_eq!(event.run, run);
+ assert_eq!(event.owner, test_run_owner(version_id, &run));
assert_eq!(event.tag, "daily");
}
@@ -13215,7 +13156,7 @@ self.addEventListener("message", event => {
let periodic_key = (registration_id, "daily".to_owned());
let scope_url = url("https://example.test/app/");
let script_url = url("https://example.test/app/sw.js");
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(version_id, &run);
+ let host = new_running_test_host(version_id, &run);
{
let mut state = service.inner.state.lock();
state.registrations.insert(
@@ -13342,7 +13283,7 @@ self.addEventListener("message", event => {
let run = RendererServiceWorkerRunIdentity::fresh();
let scope_url = url("https://example.test/app/");
let script_url = url("https://example.test/app/sw.js");
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(version_id, &run);
+ let host = new_running_test_host(version_id, &run);
{
let mut state = service.inner.state.lock();
state.registrations.insert(
@@ -13481,7 +13422,7 @@ self.addEventListener("message", event => {
let run = RendererServiceWorkerRunIdentity::fresh();
let scope_url = url("https://example.test/app/");
let script_url = url("https://example.test/app/sw.js");
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(version_id, &run);
+ let host = new_running_test_host(version_id, &run);
{
let mut state = service.inner.state.lock();
state.registrations.insert(
@@ -13568,7 +13509,7 @@ self.addEventListener("message", event => {
let scope_url = url("https://example.test/app/");
let script_url = url("https://example.test/app/sw.js");
let action_url = url("https://example.test/app/reply.html");
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(version_id, &run);
+ let host = new_running_test_host(version_id, &run);
let mut completion_queue =
crate::page_task_queue::RendererPageServiceWorkerTestHarness::new();
let client_id = ServiceWorkerClientId(9);
@@ -13626,7 +13567,6 @@ self.addEventListener("message", event => {
ServiceWorkerClient {
id: client_id,
exposed_id: service_worker_exposed_client_id(client_id),
- exposed_id_generation: 0,
creation_url: url("https://example.test/app/page.html"),
document_url: url("https://example.test/app/page.html"),
client_type: ServiceWorkerClientType::Window,
@@ -13692,7 +13632,7 @@ self.addEventListener("message", event => {
let run = RendererServiceWorkerRunIdentity::fresh();
let scope_url = url("https://example.test/app/");
let script_url = url("https://example.test/app/sw.js");
- let host = RendererServiceWorkerHost::new_running_without_handle_for_test(version_id, &run);
+ let host = new_running_test_host(version_id, &run);
{
let mut state = service.inner.state.lock();
state.registrations.insert(
diff --git a/moli-renderer-v8/src/service_worker_runtime/service/client_registry.rs b/moli-renderer-v8/src/service_worker_runtime/service/client_registry.rs
index 1240e7a09..ac139d0b5 100644
--- a/moli-renderer-v8/src/service_worker_runtime/service/client_registry.rs
+++ b/moli-renderer-v8/src/service_worker_runtime/service/client_registry.rs
@@ -120,7 +120,6 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerClient {
id: client_id,
exposed_id: service_worker_exposed_client_id(client_id),
- exposed_id_generation: 0,
creation_url: script_url,
document_url: current_script_url.clone(),
client_type,
@@ -175,7 +174,6 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerClient {
id: client_id,
exposed_id: service_worker_exposed_client_id(client_id),
- exposed_id_generation: 0,
creation_url: script_url,
document_url: current_script_url.clone(),
client_type,
@@ -259,7 +257,6 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerClient {
id: client_id,
exposed_id: service_worker_exposed_client_id(client_id),
- exposed_id_generation: 0,
creation_url: script_url,
document_url: parent_document_url,
client_type,
@@ -334,7 +331,6 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerClient {
id: client_id,
exposed_id: service_worker_exposed_client_id(client_id),
- exposed_id_generation: 0,
creation_url: document_url.clone(),
document_url: current_document_url.clone(),
client_type: ServiceWorkerClientType::Window,
@@ -481,13 +477,7 @@ impl ServiceWorkerRuntimeService {
);
if let Some(client) = state.live_clients.get_mut(&client_id) {
if !moli_url::same_origin(&client.document_url, &current_document_url) {
- client.exposed_id_generation = service_worker_next_exposed_client_id_generation(
- client.exposed_id_generation,
- );
- client.exposed_id = service_worker_exposed_client_id_for_generation(
- client.id,
- client.exposed_id_generation,
- );
+ client.exposed_id = allocate_service_worker_exposed_client_id();
}
client.creation_url = document_url.clone();
client.document_url = current_document_url.clone();
diff --git a/moli-renderer-v8/src/service_worker_runtime/service/client_requests.rs b/moli-renderer-v8/src/service_worker_runtime/service/client_requests.rs
index 7a89de2cb..d6e11e121 100644
--- a/moli-renderer-v8/src/service_worker_runtime/service/client_requests.rs
+++ b/moli-renderer-v8/src/service_worker_runtime/service/client_requests.rs
@@ -68,8 +68,7 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerEventId(self.inner.next_event_id.fetch_add(1, Ordering::Relaxed));
let event = ServiceWorkerMessageEvent {
event_id,
- version_id: message.target_version_id,
- run: target_version.run.clone(),
+ owner: target_version.run_owner(),
source_client_id: None,
source_client_url: None,
source_client_snapshot: None,
diff --git a/moli-renderer-v8/src/service_worker_runtime/service/devtools_commands.rs b/moli-renderer-v8/src/service_worker_runtime/service/devtools_commands.rs
index ab4171d15..64300dc66 100644
--- a/moli-renderer-v8/src/service_worker_runtime/service/devtools_commands.rs
+++ b/moli-renderer-v8/src/service_worker_runtime/service/devtools_commands.rs
@@ -318,14 +318,12 @@ impl ServiceWorkerRuntimeService {
return Ok(false);
}
ServiceWorkerVersionRunningState::Stopped => {
- version.run = RendererServiceWorkerRunIdentity::fresh();
+ let owner = version.replace_run_owner();
version.last_start_error = None;
- let run = version.run.clone();
- let host = RendererServiceWorkerHost::new_loading(version_id, &run);
+ let host = RendererServiceWorkerHost::new_loading(&owner);
let params = version.launch_config.to_launch_params(
registration_id,
- version_id,
- &run,
+ &owner,
version.script_url.clone(),
registration_scope_url,
registration_storage_key,
@@ -532,8 +530,7 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerEventId(self.inner.next_event_id.fetch_add(1, Ordering::Relaxed));
let event = ServiceWorkerPushEvent {
event_id,
- version_id,
- run: version.run.clone(),
+ owner: version.run_owner(),
data,
};
self.start_push_event_locked(&mut state, registration_id, scope_url, storage_key, event)
@@ -577,8 +574,7 @@ impl ServiceWorkerRuntimeService {
let event = ServiceWorkerSyncEvent {
event_id,
registration_id,
- version_id,
- run: version.run.clone(),
+ owner: version.run_owner(),
tag,
last_chance,
};
@@ -622,8 +618,7 @@ impl ServiceWorkerRuntimeService {
let event = ServiceWorkerPeriodicSyncEvent {
event_id,
registration_id,
- version_id,
- run: version.run.clone(),
+ owner: version.run_owner(),
tag,
};
self.start_periodic_sync_event_locked(
diff --git a/moli-renderer-v8/src/service_worker_runtime/service/event_completion.rs b/moli-renderer-v8/src/service_worker_runtime/service/event_completion.rs
index 59ac00ada..09929b324 100644
--- a/moli-renderer-v8/src/service_worker_runtime/service/event_completion.rs
+++ b/moli-renderer-v8/src/service_worker_runtime/service/event_completion.rs
@@ -23,8 +23,8 @@ impl ServiceWorkerRuntimeService {
return false;
};
let mut should_update_lifecycle = false;
- if let Some(version) = state.versions.get_mut(&job.version_id)
- && job.is_bound_to_run(&version.run)
+ if let Some(version) = state.versions.get_mut(&job.version_id())
+ && version.run_owner() == *job.owner()
{
let activation_len_before = version.pending_activation_fetch_events.len();
version
@@ -47,27 +47,29 @@ impl ServiceWorkerRuntimeService {
should_update_lifecycle = true;
}
let stream_cancel = job.streaming_body_source_id.and_then(|body_source_id| {
- let version = state.versions.get(&job.version_id)?;
- if !job.is_bound_to_run(&version.run) {
+ let version = state.versions.get(&job.version_id())?;
+ if version.run_owner() != *job.owner() {
return None;
}
let ServiceWorkerVersionRunningState::Running { host } = &version.running_state
else {
return None;
};
- (host.version_id() == job.version_id && job.is_bound_to_run(&host.run_identity()))
- .then_some((host.clone(), event_id, body_source_id))
+ (host.run_owner() == *job.owner()).then_some((
+ host.clone(),
+ event_id,
+ body_source_id,
+ ))
});
- let request_signal_abort = state.versions.get(&job.version_id).and_then(|version| {
- if !job.is_bound_to_run(&version.run) {
+ let request_signal_abort = state.versions.get(&job.version_id()).and_then(|version| {
+ if version.run_owner() != *job.owner() {
return None;
}
let ServiceWorkerVersionRunningState::Running { host } = &version.running_state
else {
return None;
};
- (host.version_id() == job.version_id && job.is_bound_to_run(&host.run_identity()))
- .then_some((host.clone(), event_id))
+ (host.run_owner() == *job.owner()).then_some((host.clone(), event_id))
});
job.cancel_handle.cancel();
job.cancel_pending_navigation_preload();
@@ -75,22 +77,22 @@ impl ServiceWorkerRuntimeService {
let unregistration_progress = self
.unregistration_progress_for_version_if_ready_locked(
&mut state,
- job.version_id,
+ job.version_id(),
);
let activation_progress = if unregistration_progress.is_empty() {
self.activation_progress_for_active_version_if_ready_locked(
&mut state,
- job.version_id,
+ job.version_id(),
)
} else {
Vec::new()
};
let idle_timeout =
- self.maybe_schedule_idle_timeout_locked(&mut state, job.version_id);
+ self.maybe_schedule_idle_timeout_locked(&mut state, job.version_id());
let mut progress = unregistration_progress;
progress.extend(activation_progress);
Some((
- job.version_id,
+ job.version_id(),
job.run_identity().clone(),
job,
idle_timeout,
@@ -100,7 +102,7 @@ impl ServiceWorkerRuntimeService {
))
} else {
Some((
- job.version_id,
+ job.version_id(),
job.run_identity().clone(),
job,
None,
@@ -142,8 +144,7 @@ impl ServiceWorkerRuntimeService {
}
pub(super) fn finish_fetch_event_completed(&self, completion: ServiceWorkerFetchCompletion) {
- let version_id = completion.version_id;
- let run = completion.run;
+ let (version_id, run) = completion.owner.into_parts();
let (job, result, idle_timeout, lifecycle_progress) = {
let mut state = self.inner.state.lock();
{
@@ -200,10 +201,10 @@ impl ServiceWorkerRuntimeService {
) {
let (idle_timeout, lifecycle_progress) = {
let mut state = self.inner.state.lock();
- let Some(version) = state.versions.get_mut(&completion.version_id) else {
+ let Some(version) = state.versions.get_mut(&completion.owner.version_id()) else {
return;
};
- if version.run != completion.run {
+ if &version.run != completion.owner.run_identity() {
return;
}
version.in_flight_event_count = version.in_flight_event_count.saturating_sub(1);
@@ -212,18 +213,18 @@ impl ServiceWorkerRuntimeService {
}
let unregistration_progress = self.unregistration_progress_for_version_if_ready_locked(
&mut state,
- completion.version_id,
+ completion.owner.version_id(),
);
let activation_progress = if unregistration_progress.is_empty() {
self.activation_progress_for_active_version_if_ready_locked(
&mut state,
- completion.version_id,
+ completion.owner.version_id(),
)
} else {
Vec::new()
};
let idle_timeout =
- self.maybe_schedule_idle_timeout_locked(&mut state, completion.version_id);
+ self.maybe_schedule_idle_timeout_locked(&mut state, completion.owner.version_id());
let mut progress = unregistration_progress;
progress.extend(activation_progress);
(idle_timeout, progress)
@@ -242,10 +243,10 @@ impl ServiceWorkerRuntimeService {
) {
let (idle_timeout, lifecycle_progress) = {
let mut state = self.inner.state.lock();
- let Some(version) = state.versions.get_mut(&completion.version_id) else {
+ let Some(version) = state.versions.get_mut(&completion.owner.version_id()) else {
return;
};
- if version.run != completion.run {
+ if &version.run != completion.owner.run_identity() {
return;
}
version.in_flight_event_count = version.in_flight_event_count.saturating_sub(1);
@@ -254,18 +255,18 @@ impl ServiceWorkerRuntimeService {
}
let unregistration_progress = self.unregistration_progress_for_version_if_ready_locked(
&mut state,
- completion.version_id,
+ completion.owner.version_id(),
);
let activation_progress = if unregistration_progress.is_empty() {
self.activation_progress_for_active_version_if_ready_locked(
&mut state,
- completion.version_id,
+ completion.owner.version_id(),
)
} else {
Vec::new()
};
let idle_timeout =
- self.maybe_schedule_idle_timeout_locked(&mut state, completion.version_id);
+ self.maybe_schedule_idle_timeout_locked(&mut state, completion.owner.version_id());
let mut progress = unregistration_progress;
progress.extend(activation_progress);
(idle_timeout, progress)
@@ -281,10 +282,10 @@ impl ServiceWorkerRuntimeService {
pub(super) fn finish_push_event_completed(&self, completion: ServiceWorkerPushCompletion) {
let (idle_timeout, lifecycle_progress) = {
let mut state = self.inner.state.lock();
- let Some(version) = state.versions.get_mut(&completion.version_id) else {
+ let Some(version) = state.versions.get_mut(&completion.owner.version_id()) else {
return;
};
- if version.run != completion.run {
+ if &version.run != completion.owner.run_identity() {
return;
}
version.in_flight_event_count = version.in_flight_event_count.saturating_sub(1);
@@ -293,18 +294,18 @@ impl ServiceWorkerRuntimeService {
}
let unregistration_progress = self.unregistration_progress_for_version_if_ready_locked(
&mut state,
- completion.version_id,
+ completion.owner.version_id(),
);
let activation_progress = if unregistration_progress.is_empty() {
self.activation_progress_for_active_version_if_ready_locked(
&mut state,
- completion.version_id,
+ completion.owner.version_id(),
)
} else {
Vec::new()
};
let idle_timeout =
- self.maybe_schedule_idle_timeout_locked(&mut state, completion.version_id);
+ self.maybe_schedule_idle_timeout_locked(&mut state, completion.owner.version_id());
let mut progress = unregistration_progress;
progress.extend(activation_progress);
(idle_timeout, progress)
@@ -325,10 +326,10 @@ impl ServiceWorkerRuntimeService {
let (idle_timeout, lifecycle_progress, follow_up) = {
let mut state = self.inner.state.lock();
- let Some(version) = state.versions.get_mut(&completion.version_id) else {
+ let Some(version) = state.versions.get_mut(&completion.owner.version_id()) else {
return;
};
- if version.run != completion.run {
+ if &version.run != completion.owner.run_identity() {
return;
}
version.in_flight_event_count = version.in_flight_event_count.saturating_sub(1);
@@ -398,18 +399,18 @@ impl ServiceWorkerRuntimeService {
}
let unregistration_progress = self.unregistration_progress_for_version_if_ready_locked(
&mut state,
- completion.version_id,
+ completion.owner.version_id(),
);
let activation_progress = if unregistration_progress.is_empty() {
self.activation_progress_for_active_version_if_ready_locked(
&mut state,
- completion.version_id,
+ completion.owner.version_id(),
)
} else {
Vec::new()
};
let idle_timeout =
- self.maybe_schedule_idle_timeout_locked(&mut state, completion.version_id);
+ self.maybe_schedule_idle_timeout_locked(&mut state, completion.owner.version_id());
let mut progress = unregistration_progress;
progress.extend(activation_progress);
(idle_timeout, progress, follow_up)
@@ -438,10 +439,10 @@ impl ServiceWorkerRuntimeService {
) {
let (idle_timeout, lifecycle_progress, refire) = {
let mut state = self.inner.state.lock();
- let Some(version) = state.versions.get_mut(&completion.version_id) else {
+ let Some(version) = state.versions.get_mut(&completion.owner.version_id()) else {
return;
};
- if version.run != completion.run
+ if &version.run != completion.owner.run_identity()
|| version.registration_id != completion.registration_id
{
return;
@@ -467,18 +468,18 @@ impl ServiceWorkerRuntimeService {
});
let unregistration_progress = self.unregistration_progress_for_version_if_ready_locked(
&mut state,
- completion.version_id,
+ completion.owner.version_id(),
);
let activation_progress = if unregistration_progress.is_empty() {
self.activation_progress_for_active_version_if_ready_locked(
&mut state,
- completion.version_id,
+ completion.owner.version_id(),
)
} else {
Vec::new()
};
let idle_timeout =
- self.maybe_schedule_idle_timeout_locked(&mut state, completion.version_id);
+ self.maybe_schedule_idle_timeout_locked(&mut state, completion.owner.version_id());
let mut progress = unregistration_progress;
progress.extend(activation_progress);
(idle_timeout, progress, refire)
diff --git a/moli-renderer-v8/src/service_worker_runtime/service/event_dispatch.rs b/moli-renderer-v8/src/service_worker_runtime/service/event_dispatch.rs
index 60b69e32d..df5b88ac2 100644
--- a/moli-renderer-v8/src/service_worker_runtime/service/event_dispatch.rs
+++ b/moli-renderer-v8/src/service_worker_runtime/service/event_dispatch.rs
@@ -17,8 +17,7 @@ const NAVIGATION_PRELOAD_NETWORK_ERROR_MESSAGE: &str = "The service worker navig
struct ServiceWorkerNavigationPreloadDispatch {
event_id: ServiceWorkerEventId,
- version_id: ServiceWorkerVersionId,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
request_url: url::Url,
request_mode: moli_fetch::RequestMode,
request_client: ResourceRequestClient,
@@ -114,8 +113,7 @@ async fn stream_navigation_preload_response(
Err(_) => {
let _ = host.fail_navigation_preload(ServiceWorkerNavigationPreloadFailure {
event_id: dispatch.event_id,
- version_id: dispatch.version_id,
- run: dispatch.run.clone(),
+ owner: dispatch.owner.clone(),
message: navigation_preload_response_start_failure_message(&cancel_handle),
});
return;
@@ -124,8 +122,7 @@ async fn stream_navigation_preload_response(
Err(message) => {
let _ = host.fail_navigation_preload(ServiceWorkerNavigationPreloadFailure {
event_id: dispatch.event_id,
- version_id: dispatch.version_id,
- run: dispatch.run.clone(),
+ owner: dispatch.owner.clone(),
message,
});
return;
@@ -134,18 +131,13 @@ async fn stream_navigation_preload_response(
let body_source_id = new_network_body_source_id();
let response_head = navigation_preload_response_head(raw.head());
- if !service.mark_navigation_preload_response_started(
- dispatch.event_id,
- dispatch.version_id,
- dispatch.run.clone(),
- ) {
+ if !service.mark_navigation_preload_response_started(dispatch.event_id, &dispatch.owner) {
cancel_handle.cancel();
return;
}
if !host.start_navigation_preload_response(ServiceWorkerNavigationPreloadResponseStarted {
event_id: dispatch.event_id,
- version_id: dispatch.version_id,
- run: dispatch.run.clone(),
+ owner: dispatch.owner.clone(),
request_url: dispatch.request_url,
request_mode: dispatch.request_mode,
body_source_id,
@@ -172,8 +164,7 @@ async fn stream_navigation_preload_response(
.map_err(|_| NAVIGATION_PRELOAD_NETWORK_ERROR_MESSAGE.to_owned());
let _ = host.finish_navigation_preload_stream(ServiceWorkerNavigationPreloadStreamFinished {
event_id: dispatch.event_id,
- version_id: dispatch.version_id,
- run: dispatch.run.clone(),
+ owner: dispatch.owner,
body_source_id,
result,
});
@@ -219,10 +210,10 @@ impl ServiceWorkerRuntimeService {
if debugger_release_consumed {
return;
}
- if self.take_devtools_evaluation_release_for_version(launch.params.version_id) {
+ if self.take_devtools_evaluation_release_for_version(launch.params.run_owner.version_id()) {
return;
}
- if self.launch_should_pause_on_start_for_devtools(launch.params.version_id) {
+ if self.launch_should_pause_on_start_for_devtools(launch.params.run_owner.version_id()) {
launch.params.pause_evaluation_until_debugger = true;
}
}
@@ -247,8 +238,8 @@ impl ServiceWorkerRuntimeService {
if launch.preloaded_script.is_some() {
return Some(launch);
}
- let version_id = launch.params.version_id;
- let run = launch.params.run.clone();
+ let version_id = launch.params.run_owner.version_id();
+ let run = launch.params.run_owner.cloned_run_identity();
let mut state = self.inner.state.lock();
let should_defer = state.versions.get(&version_id).is_some_and(|version| {
version.should_pause_on_start_for_devtools
@@ -270,8 +261,7 @@ impl ServiceWorkerRuntimeService {
let request = dispatch.request.clone();
let fetch_job = ServiceWorkerFetchJob {
internal_id: dispatch.internal_id,
- version_id: ServiceWorkerVersionId(0),
- run: None,
+ owner: None,
request_url: request.url.clone(),
request_method: request.method.clone(),
request_headers: request.headers.clone(),
@@ -352,15 +342,13 @@ impl ServiceWorkerRuntimeService {
let Some(version) = state.versions.get_mut(&version_id) else {
return Err(Box::new(fetch_job));
};
- fetch_job.version_id = version_id;
- fetch_job.bind_to_run(version.run.clone());
+ fetch_job.bind_to_owner(version.run_owner());
if version.lifecycle_state == ServiceWorkerVersionLifecycleState::Activating {
let event_id =
ServiceWorkerEventId(self.inner.next_event_id.fetch_add(1, Ordering::Relaxed));
let event = ServiceWorkerFetchEvent {
event_id,
- version_id,
- run: version.run.clone(),
+ owner: version.run_owner(),
request,
navigation_preload_sent: false,
};
@@ -381,8 +369,7 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerVersionRunningState::Running { host } => {
let event = ServiceWorkerFetchEvent {
event_id,
- version_id,
- run: version.run.clone(),
+ owner: version.run_owner(),
request,
navigation_preload_sent: false,
};
@@ -392,8 +379,7 @@ impl ServiceWorkerRuntimeService {
version.pending_start_events.push_back(
ServiceWorkerPendingStartEvent::Fetch(ServiceWorkerFetchEvent {
event_id,
- version_id,
- run: version.run.clone(),
+ owner: version.run_owner(),
request,
navigation_preload_sent: false,
}),
@@ -401,16 +387,14 @@ impl ServiceWorkerRuntimeService {
(None, None, None)
}
ServiceWorkerVersionRunningState::Stopped => {
- version.run = RendererServiceWorkerRunIdentity::fresh();
+ let owner = version.replace_run_owner();
version.last_start_error = None;
- let run = version.run.clone();
- fetch_job.bind_to_run(run.clone());
- let host = RendererServiceWorkerHost::new_loading(version_id, &run);
+ fetch_job.bind_to_owner(owner.clone());
+ let host = RendererServiceWorkerHost::new_loading(&owner);
version.launch_config.document_url = document_url.clone();
let params = version.launch_config.to_launch_params(
registration_id,
- version_id,
- &run,
+ &owner,
version.script_url.clone(),
scope_url,
registration_storage_key,
@@ -418,8 +402,7 @@ impl ServiceWorkerRuntimeService {
);
let event = ServiceWorkerFetchEvent {
event_id,
- version_id,
- run: run.clone(),
+ owner,
request,
navigation_preload_sent: false,
};
@@ -472,8 +455,8 @@ impl ServiceWorkerRuntimeService {
let action = {
let mut state = self.inner.state.lock();
- match state.versions.get_mut(&event.version_id) {
- Some(version) if version.run != event.run => {
+ match state.versions.get_mut(&event.owner.version_id()) {
+ Some(version) if &version.run != event.owner.run_identity() => {
PendingActivationFetchAction::Failure(
"service worker fetch dispatch failed: stale activating worker"
.to_owned(),
@@ -523,16 +506,14 @@ impl ServiceWorkerRuntimeService {
PendingActivationFetchAction::Fallback => {
self.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner,
result: ServiceWorkerFetchResult::Fallback,
});
}
PendingActivationFetchAction::Failure(message) => {
self.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner,
result: ServiceWorkerFetchResult::Failure(message),
});
}
@@ -583,8 +564,7 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerEventId(self.inner.next_event_id.fetch_add(1, Ordering::Relaxed));
let event = ServiceWorkerMessageEvent {
event_id,
- version_id,
- run: version.run.clone(),
+ owner: version.run_owner(),
source_client_id: Some(source_client_id),
source_client_url: Some(source_client_url),
source_client_snapshot: Some(source_client_snapshot),
@@ -671,8 +651,7 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerEventId(self.inner.next_event_id.fetch_add(1, Ordering::Relaxed));
let event = ServiceWorkerPushEvent {
event_id,
- version_id,
- run: version.run.clone(),
+ owner: version.run_owner(),
data,
};
self.start_push_event_locked(
@@ -725,7 +704,7 @@ impl ServiceWorkerRuntimeService {
if version.lifecycle_state != ServiceWorkerVersionLifecycleState::Activated {
return false;
}
- let run = version.run.clone();
+ let owner = version.run_owner();
let sync_key = (registration_id, tag.clone());
if state
.sync_registrations
@@ -739,8 +718,7 @@ impl ServiceWorkerRuntimeService {
let event = ServiceWorkerSyncEvent {
event_id,
registration_id,
- version_id,
- run,
+ owner,
tag: tag.clone(),
last_chance: false,
};
@@ -814,14 +792,13 @@ impl ServiceWorkerRuntimeService {
if !sync_record.is_idle() {
return false;
}
- let run = version.run.clone();
+ let owner = version.run_owner();
let event_id =
ServiceWorkerEventId(self.inner.next_event_id.fetch_add(1, Ordering::Relaxed));
let event = ServiceWorkerSyncEvent {
event_id,
registration_id,
- version_id,
- run,
+ owner,
tag: tag.to_owned(),
last_chance: sync_record.failed_attempts > 0,
};
@@ -968,7 +945,7 @@ impl ServiceWorkerRuntimeService {
if version.lifecycle_state != ServiceWorkerVersionLifecycleState::Activated {
return false;
}
- let run = version.run.clone();
+ let owner = version.run_owner();
if state
.periodic_sync_registrations
.get_mut(&periodic_sync_key)
@@ -981,8 +958,7 @@ impl ServiceWorkerRuntimeService {
let event = ServiceWorkerPeriodicSyncEvent {
event_id,
registration_id,
- version_id,
- run,
+ owner,
tag: tag.to_owned(),
};
let start = self.start_periodic_sync_event_locked(
@@ -1298,8 +1274,7 @@ impl ServiceWorkerRuntimeService {
event_id,
kind,
registration_id,
- version_id,
- run: version.run.clone(),
+ owner: version.run_owner(),
notification_id,
title,
tag,
@@ -1396,8 +1371,7 @@ impl ServiceWorkerRuntimeService {
}
self.enqueue_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
result: ServiceWorkerFetchResult::Failure(
"service worker fetch dispatch failed: worker is not running".to_owned(),
),
@@ -1410,15 +1384,15 @@ impl ServiceWorkerRuntimeService {
) -> Option<ServiceWorkerNavigationPreloadDispatch> {
let mut state = self.inner.state.lock();
let job = state.pending_fetch_jobs.get(&event.event_id)?;
- if job.version_id != event.version_id || !job.is_bound_to_run(&event.run) {
+ if !job.is_bound_to_owner(&event.owner) {
return None;
}
if !service_worker_fetch_event_can_use_navigation_preload(job) {
return None;
}
- let version = state.versions.get(&event.version_id)?;
+ let version = state.versions.get(&event.owner.version_id())?;
let registration = state.registrations.get(&version.registration_id)?;
- if registration.active_version_id != Some(event.version_id)
+ if registration.active_version_id != Some(event.owner.version_id())
|| !registration.navigation_preload_state.enabled
{
return None;
@@ -1435,16 +1409,14 @@ impl ServiceWorkerRuntimeService {
);
if request.is_ok()
&& let Some(job) = state.pending_fetch_jobs.get_mut(&event.event_id)
- && job.version_id == event.version_id
- && job.is_bound_to_run(&event.run)
+ && job.is_bound_to_owner(&event.owner)
{
job.navigation_preload_cancel_handle = Some(cancel_handle.clone());
}
Some(ServiceWorkerNavigationPreloadDispatch {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
request_url,
request_mode,
request_client,
@@ -1468,14 +1440,13 @@ impl ServiceWorkerRuntimeService {
pub(super) fn mark_navigation_preload_response_started(
&self,
event_id: ServiceWorkerEventId,
- version_id: ServiceWorkerVersionId,
- run: RendererServiceWorkerRunIdentity,
+ owner: &ServiceWorkerRunOwner,
) -> bool {
let mut state = self.inner.state.lock();
let Some(job) = state.pending_fetch_jobs.get_mut(&event_id) else {
return false;
};
- if job.version_id != version_id || !job.is_bound_to_run(&run) {
+ if !job.is_bound_to_owner(owner) {
return false;
}
job.clear_pending_navigation_preload_cancel_handle();
@@ -1492,8 +1463,7 @@ impl ServiceWorkerRuntimeService {
}
self.enqueue_notification_event_completed(ServiceWorkerNotificationCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
result: Err(
"service worker notification dispatch failed: worker is not running".to_owned(),
),
@@ -1510,8 +1480,7 @@ impl ServiceWorkerRuntimeService {
}
self.enqueue_push_event_completed(ServiceWorkerPushCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
result: Err("service worker push dispatch failed: worker is not running".to_owned()),
});
}
@@ -1527,8 +1496,7 @@ impl ServiceWorkerRuntimeService {
self.enqueue_sync_event_completed(ServiceWorkerSyncCompletion {
event_id: event.event_id,
registration_id: event.registration_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
tag: event.tag,
result: Err("service worker sync dispatch failed: worker is not running".to_owned()),
});
@@ -1545,8 +1513,7 @@ impl ServiceWorkerRuntimeService {
self.enqueue_periodic_sync_event_completed(ServiceWorkerPeriodicSyncCompletion {
event_id: event.event_id,
registration_id: event.registration_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
tag: event.tag,
result: Err(
"service worker periodic sync dispatch failed: worker is not running".to_owned(),
@@ -1564,8 +1531,7 @@ impl ServiceWorkerRuntimeService {
}
self.enqueue_message_event_completed(ServiceWorkerMessageCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
result: Err("service worker message dispatch failed: worker is not running".to_owned()),
});
}
diff --git a/moli-renderer-v8/src/service_worker_runtime/service/event_start.rs b/moli-renderer-v8/src/service_worker_runtime/service/event_start.rs
index a62efd7ed..b85df0125 100644
--- a/moli-renderer-v8/src/service_worker_runtime/service/event_start.rs
+++ b/moli-renderer-v8/src/service_worker_runtime/service/event_start.rs
@@ -20,7 +20,7 @@ impl ServiceWorkerRuntimeService {
return None;
}
let registration_id = version.registration_id;
- let run = version.run.clone();
+ let owner = version.run_owner();
let ServiceWorkerVersionRunningState::Running { host } = &version.running_state else {
return None;
};
@@ -36,11 +36,7 @@ impl ServiceWorkerRuntimeService {
}
let token = ServiceWorkerIdleTimeoutToken::fresh();
version.idle_timeout_token = Some(token.clone());
- Some(ServiceWorkerIdleTimeout {
- version_id,
- run,
- token,
- })
+ Some(ServiceWorkerIdleTimeout { owner, token })
}
pub(super) fn fail_pending_start_events(
@@ -53,16 +49,14 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerPendingStartEvent::Fetch(event) => {
self.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
result: ServiceWorkerFetchResult::Failure(message.to_owned()),
});
}
ServiceWorkerPendingStartEvent::Lifecycle(event) => {
self.finish_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
kind: event.kind,
result: Err(message.to_owned()),
});
@@ -70,24 +64,21 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerPendingStartEvent::Message(event) => {
self.finish_message_event_completed(ServiceWorkerMessageCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
result: Err(message.to_owned()),
});
}
ServiceWorkerPendingStartEvent::Notification(event) => {
self.finish_notification_event_completed(ServiceWorkerNotificationCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
result: Err(message.to_owned()),
});
}
ServiceWorkerPendingStartEvent::Push(event) => {
self.finish_push_event_completed(ServiceWorkerPushCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
result: Err(message.to_owned()),
});
}
@@ -95,8 +86,7 @@ impl ServiceWorkerRuntimeService {
self.finish_sync_event_completed(ServiceWorkerSyncCompletion {
event_id: event.event_id,
registration_id: event.registration_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
tag: event.tag,
result: Err(message.to_owned()),
});
@@ -106,8 +96,7 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerPeriodicSyncCompletion {
event_id: event.event_id,
registration_id: event.registration_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
tag: event.tag,
result: Err(message.to_owned()),
},
@@ -127,8 +116,7 @@ impl ServiceWorkerRuntimeService {
}
self.enqueue_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
kind: event.kind,
result: Err(
"service worker lifecycle dispatch failed: worker is not running".to_owned(),
@@ -327,8 +315,7 @@ impl ServiceWorkerRuntimeService {
host,
ServiceWorkerLifecycleEvent {
event_id,
- version_id,
- run: version.run.clone(),
+ owner: version.run_owner(),
kind,
},
)))
@@ -341,22 +328,19 @@ impl ServiceWorkerRuntimeService {
version.pending_start_events.push_back(
ServiceWorkerPendingStartEvent::Lifecycle(ServiceWorkerLifecycleEvent {
event_id,
- version_id,
- run: version.run.clone(),
+ owner: version.run_owner(),
kind,
}),
);
Some(ServiceWorkerLifecycleStart::Queued)
}
LifecycleRunningAction::StartStopped => {
- version.run = RendererServiceWorkerRunIdentity::fresh();
+ let owner = version.replace_run_owner();
version.last_start_error = None;
- let run = version.run.clone();
- let host = RendererServiceWorkerHost::new_loading(version_id, &run);
+ let host = RendererServiceWorkerHost::new_loading(&owner);
let params = version.launch_config.to_launch_params(
registration_id,
- version_id,
- &run,
+ &owner,
version.script_url.clone(),
scope_url,
storage_key,
@@ -369,8 +353,7 @@ impl ServiceWorkerRuntimeService {
version.pending_start_events.push_back(
ServiceWorkerPendingStartEvent::Lifecycle(ServiceWorkerLifecycleEvent {
event_id,
- version_id,
- run,
+ owner,
kind,
}),
);
@@ -401,7 +384,7 @@ impl ServiceWorkerRuntimeService {
storage_key: String,
mut event: ServiceWorkerMessageEvent,
) -> ServiceWorkerMessageStart {
- let Some(version) = state.versions.get_mut(&event.version_id) else {
+ let Some(version) = state.versions.get_mut(&event.owner.version_id()) else {
return ServiceWorkerMessageStart::Dropped;
};
if version.registration_id != registration_id
@@ -414,33 +397,31 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerVersionRunningState::Running { host } if host.has_running_worker() => {
let host = host.clone();
Self::begin_version_event_locked(version);
- event.run = version.run.clone();
+ event.owner = version.run_owner();
ServiceWorkerMessageStart::Dispatch(Box::new((host, event)))
}
ServiceWorkerVersionRunningState::Starting { .. } => {
Self::begin_version_event_locked(version);
- event.run = version.run.clone();
+ event.owner = version.run_owner();
version
.pending_start_events
.push_back(ServiceWorkerPendingStartEvent::Message(event));
ServiceWorkerMessageStart::Queued
}
ServiceWorkerVersionRunningState::Stopped => {
- version.run = RendererServiceWorkerRunIdentity::fresh();
+ let owner = version.replace_run_owner();
version.last_start_error = None;
- let run = version.run.clone();
- let host = RendererServiceWorkerHost::new_loading(event.version_id, &run);
+ let host = RendererServiceWorkerHost::new_loading(&owner);
let params = version.launch_config.to_launch_params(
registration_id,
- event.version_id,
- &run,
+ &owner,
version.script_url.clone(),
scope_url,
storage_key,
version.script_kind,
);
Self::begin_version_event_locked(version);
- event.run = run;
+ event.owner = owner;
version
.pending_start_events
.push_back(ServiceWorkerPendingStartEvent::Message(event));
@@ -465,7 +446,7 @@ impl ServiceWorkerRuntimeService {
storage_key: String,
mut event: ServiceWorkerNotificationEvent,
) -> ServiceWorkerNotificationStart {
- let Some(version) = state.versions.get_mut(&event.version_id) else {
+ let Some(version) = state.versions.get_mut(&event.owner.version_id()) else {
return ServiceWorkerNotificationStart::Dropped;
};
if version.registration_id != registration_id
@@ -478,33 +459,31 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerVersionRunningState::Running { host } if host.has_running_worker() => {
let host = host.clone();
Self::begin_version_event_locked(version);
- event.run = version.run.clone();
+ event.owner = version.run_owner();
ServiceWorkerNotificationStart::Dispatch(Box::new((host, event)))
}
ServiceWorkerVersionRunningState::Starting { .. } => {
Self::begin_version_event_locked(version);
- event.run = version.run.clone();
+ event.owner = version.run_owner();
version
.pending_start_events
.push_back(ServiceWorkerPendingStartEvent::Notification(event));
ServiceWorkerNotificationStart::Queued
}
ServiceWorkerVersionRunningState::Stopped => {
- version.run = RendererServiceWorkerRunIdentity::fresh();
+ let owner = version.replace_run_owner();
version.last_start_error = None;
- let run = version.run.clone();
- let host = RendererServiceWorkerHost::new_loading(event.version_id, &run);
+ let host = RendererServiceWorkerHost::new_loading(&owner);
let params = version.launch_config.to_launch_params(
registration_id,
- event.version_id,
- &run,
+ &owner,
version.script_url.clone(),
scope_url,
storage_key,
version.script_kind,
);
Self::begin_version_event_locked(version);
- event.run = run;
+ event.owner = owner;
version
.pending_start_events
.push_back(ServiceWorkerPendingStartEvent::Notification(event));
@@ -531,7 +510,7 @@ impl ServiceWorkerRuntimeService {
storage_key: String,
mut event: ServiceWorkerPushEvent,
) -> ServiceWorkerPushStart {
- let Some(version) = state.versions.get_mut(&event.version_id) else {
+ let Some(version) = state.versions.get_mut(&event.owner.version_id()) else {
return ServiceWorkerPushStart::Dropped;
};
if version.registration_id != registration_id
@@ -544,33 +523,31 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerVersionRunningState::Running { host } if host.has_running_worker() => {
let host = host.clone();
Self::begin_version_event_locked(version);
- event.run = version.run.clone();
+ event.owner = version.run_owner();
ServiceWorkerPushStart::Dispatch(Box::new((host, event)))
}
ServiceWorkerVersionRunningState::Starting { .. } => {
Self::begin_version_event_locked(version);
- event.run = version.run.clone();
+ event.owner = version.run_owner();
version
.pending_start_events
.push_back(ServiceWorkerPendingStartEvent::Push(event));
ServiceWorkerPushStart::Queued
}
ServiceWorkerVersionRunningState::Stopped => {
- version.run = RendererServiceWorkerRunIdentity::fresh();
+ let owner = version.replace_run_owner();
version.last_start_error = None;
- let run = version.run.clone();
- let host = RendererServiceWorkerHost::new_loading(event.version_id, &run);
+ let host = RendererServiceWorkerHost::new_loading(&owner);
let params = version.launch_config.to_launch_params(
registration_id,
- event.version_id,
- &run,
+ &owner,
version.script_url.clone(),
scope_url,
storage_key,
version.script_kind,
);
Self::begin_version_event_locked(version);
- event.run = run;
+ event.owner = owner;
version
.pending_start_events
.push_back(ServiceWorkerPendingStartEvent::Push(event));
@@ -595,7 +572,7 @@ impl ServiceWorkerRuntimeService {
storage_key: String,
mut event: ServiceWorkerSyncEvent,
) -> ServiceWorkerSyncStart {
- let Some(version) = state.versions.get_mut(&event.version_id) else {
+ let Some(version) = state.versions.get_mut(&event.owner.version_id()) else {
return ServiceWorkerSyncStart::Dropped;
};
if version.registration_id != registration_id
@@ -608,33 +585,31 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerVersionRunningState::Running { host } if host.has_running_worker() => {
let host = host.clone();
Self::begin_version_event_locked(version);
- event.run = version.run.clone();
+ event.owner = version.run_owner();
ServiceWorkerSyncStart::Dispatch(Box::new((host, event)))
}
ServiceWorkerVersionRunningState::Starting { .. } => {
Self::begin_version_event_locked(version);
- event.run = version.run.clone();
+ event.owner = version.run_owner();
version
.pending_start_events
.push_back(ServiceWorkerPendingStartEvent::Sync(event));
ServiceWorkerSyncStart::Queued
}
ServiceWorkerVersionRunningState::Stopped => {
- version.run = RendererServiceWorkerRunIdentity::fresh();
+ let owner = version.replace_run_owner();
version.last_start_error = None;
- let run = version.run.clone();
- let host = RendererServiceWorkerHost::new_loading(event.version_id, &run);
+ let host = RendererServiceWorkerHost::new_loading(&owner);
let params = version.launch_config.to_launch_params(
registration_id,
- event.version_id,
- &run,
+ &owner,
version.script_url.clone(),
scope_url,
storage_key,
version.script_kind,
);
Self::begin_version_event_locked(version);
- event.run = run;
+ event.owner = owner;
version
.pending_start_events
.push_back(ServiceWorkerPendingStartEvent::Sync(event));
@@ -659,7 +634,7 @@ impl ServiceWorkerRuntimeService {
storage_key: String,
mut event: ServiceWorkerPeriodicSyncEvent,
) -> ServiceWorkerPeriodicSyncStart {
- let Some(version) = state.versions.get_mut(&event.version_id) else {
+ let Some(version) = state.versions.get_mut(&event.owner.version_id()) else {
return ServiceWorkerPeriodicSyncStart::Dropped;
};
if version.registration_id != registration_id
@@ -672,33 +647,31 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerVersionRunningState::Running { host } if host.has_running_worker() => {
let host = host.clone();
Self::begin_version_event_locked(version);
- event.run = version.run.clone();
+ event.owner = version.run_owner();
ServiceWorkerPeriodicSyncStart::Dispatch(Box::new((host, event)))
}
ServiceWorkerVersionRunningState::Starting { .. } => {
Self::begin_version_event_locked(version);
- event.run = version.run.clone();
+ event.owner = version.run_owner();
version
.pending_start_events
.push_back(ServiceWorkerPendingStartEvent::PeriodicSync(event));
ServiceWorkerPeriodicSyncStart::Queued
}
ServiceWorkerVersionRunningState::Stopped => {
- version.run = RendererServiceWorkerRunIdentity::fresh();
+ let owner = version.replace_run_owner();
version.last_start_error = None;
- let run = version.run.clone();
- let host = RendererServiceWorkerHost::new_loading(event.version_id, &run);
+ let host = RendererServiceWorkerHost::new_loading(&owner);
let params = version.launch_config.to_launch_params(
registration_id,
- event.version_id,
- &run,
+ &owner,
version.script_url.clone(),
scope_url,
storage_key,
version.script_kind,
);
Self::begin_version_event_locked(version);
- event.run = run;
+ event.owner = owner;
version
.pending_start_events
.push_back(ServiceWorkerPendingStartEvent::PeriodicSync(event));
diff --git a/moli-renderer-v8/src/service_worker_runtime/service/fetch_settlement.rs b/moli-renderer-v8/src/service_worker_runtime/service/fetch_settlement.rs
index d139ca181..fd16b183c 100644
--- a/moli-renderer-v8/src/service_worker_runtime/service/fetch_settlement.rs
+++ b/moli-renderer-v8/src/service_worker_runtime/service/fetch_settlement.rs
@@ -375,7 +375,7 @@ impl ServiceWorkerRuntimeService {
.pending_fetch_jobs
.get(&started.event_id)
.and_then(|job| {
- if job.version_id != started.version_id || !job.is_bound_to_run(&started.run) {
+ if !job.is_bound_to_owner(&started.owner) {
return None;
}
service_worker_fetch_can_forward_stream(job, &started.response_head).err()
@@ -391,7 +391,7 @@ impl ServiceWorkerRuntimeService {
let Some(job) = state.pending_fetch_jobs.get_mut(&started.event_id) else {
return;
};
- if job.version_id != started.version_id || !job.is_bound_to_run(&started.run) {
+ if !job.is_bound_to_owner(&started.owner) {
return;
}
match service_worker_fetch_can_forward_stream(job, &started.response_head) {
@@ -436,48 +436,51 @@ impl ServiceWorkerRuntimeService {
let rejected = {
let mut state = self.inner.state.lock();
{
- let Some(version) = state.versions.get(&started.version_id) else {
+ let Some(version) = state.versions.get(&started.owner.version_id()) else {
return;
};
- if version.run != started.run {
+ if &version.run != started.owner.run_identity() {
return;
}
}
let Some(job) = state.pending_fetch_jobs.remove(&started.event_id) else {
return;
};
- if job.version_id != started.version_id || !job.is_bound_to_run(&started.run) {
+ if !job.is_bound_to_owner(&started.owner) {
return;
}
- let stream_cancel = state.versions.get(&job.version_id).and_then(|version| {
- if !job.is_bound_to_run(&version.run) {
+ let stream_cancel = state.versions.get(&job.version_id()).and_then(|version| {
+ if version.run_owner() != *job.owner() {
return None;
}
let ServiceWorkerVersionRunningState::Running { host } = &version.running_state
else {
return None;
};
- (host.version_id() == job.version_id && job.is_bound_to_run(&host.run_identity()))
- .then_some((host.clone(), started.event_id, started.body_source_id))
+ (host.run_owner() == *job.owner()).then_some((
+ host.clone(),
+ started.event_id,
+ started.body_source_id,
+ ))
});
- if let Some(version) = state.versions.get_mut(&started.version_id) {
+ if let Some(version) = state.versions.get_mut(&started.owner.version_id()) {
version.in_flight_event_count = version.in_flight_event_count.saturating_sub(1);
}
job.cancel_handle.cancel();
let unregistration_progress = self.unregistration_progress_for_version_if_ready_locked(
&mut state,
- started.version_id,
+ started.owner.version_id(),
);
let activation_progress = if unregistration_progress.is_empty() {
self.activation_progress_for_active_version_if_ready_locked(
&mut state,
- started.version_id,
+ started.owner.version_id(),
)
} else {
Vec::new()
};
let idle_timeout =
- self.maybe_schedule_idle_timeout_locked(&mut state, started.version_id);
+ self.maybe_schedule_idle_timeout_locked(&mut state, started.owner.version_id());
let mut lifecycle_progress = unregistration_progress;
lifecycle_progress.extend(activation_progress);
Some((job, idle_timeout, lifecycle_progress, stream_cancel))
@@ -491,7 +494,11 @@ impl ServiceWorkerRuntimeService {
let result = ServiceWorkerFetchResult::Failure(message.clone());
let diagnostic =
super::event_completion::service_worker_fetch_diagnostic_from_job_result(&job, &result);
- self.enqueue_target_fetch_diagnostic(started.version_id, started.run, diagnostic);
+ self.enqueue_target_fetch_diagnostic(
+ started.owner.version_id(),
+ started.owner.cloned_run_identity(),
+ diagnostic,
+ );
for progress in lifecycle_progress {
self.run_lifecycle_progress(progress);
}
@@ -1098,7 +1105,6 @@ mod tests {
ServiceWorkerClient {
id: client_id,
exposed_id: service_worker_exposed_client_id(client_id),
- exposed_id_generation: 0,
creation_url: document_url.clone(),
document_url: document_url.clone(),
client_type: ServiceWorkerClientType::Window,
@@ -1146,8 +1152,7 @@ mod tests {
event_id,
ServiceWorkerFetchJob {
internal_id,
- version_id,
- run: Some(run.clone()),
+ owner: Some(ServiceWorkerRunOwner::new(version_id, run.clone())),
request_url: request_url.clone(),
request_method: "GET".to_owned(),
request_headers: vec![("accept".to_owned(), "text/plain".to_owned())],
@@ -1255,8 +1260,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: Some(final_url.clone()),
response_type: "default".to_owned(),
@@ -1309,8 +1313,10 @@ mod tests {
service.finish_fetch_stream_started(ServiceWorkerFetchStreamStarted {
event_id,
- version_id,
- run: run.clone(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ version_id,
+ run.clone(),
+ ),
body_source_id,
response_head: MaterializedServiceWorkerFetchResponseHead {
final_url: Some(final_url.clone()),
@@ -1348,8 +1354,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: Some(final_url),
response_type: "default".to_owned(),
@@ -1392,8 +1397,10 @@ mod tests {
service.finish_fetch_stream_started(ServiceWorkerFetchStreamStarted {
event_id,
- version_id,
- run: run.clone(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ version_id,
+ run.clone(),
+ ),
body_source_id,
response_head: MaterializedServiceWorkerFetchResponseHead {
final_url: Some(final_url),
@@ -1426,8 +1433,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Failure(
"FetchEvent.respondWith stream aborted".to_owned(),
),
@@ -1467,8 +1473,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: None,
response_type: "opaque".to_owned(),
@@ -1513,8 +1518,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: None,
response_type: "opaqueredirect".to_owned(),
@@ -1558,8 +1562,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: Some(final_url.clone()),
response_type: "default".to_owned(),
@@ -1602,8 +1605,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: Some(url("https://example.test/app/manual-final.txt")),
response_type: "default".to_owned(),
@@ -1651,8 +1653,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: None,
response_type: "default".to_owned(),
@@ -1701,8 +1702,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Failure(
"FetchEvent.respondWith promise rejected: Error: fetch-boom".to_owned(),
),
@@ -1740,8 +1740,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Failure(
"service worker fetch dispatch failed: worker is not running".to_owned(),
),
@@ -1777,8 +1776,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: None,
response_type: "default".to_owned(),
@@ -1830,14 +1828,16 @@ mod tests {
let mut state = service.inner.state.lock();
let version = state.versions.get_mut(&version_id).unwrap();
version.running_state = ServiceWorkerVersionRunningState::Starting {
- host: RendererServiceWorkerHost::new_loading(version_id, &run),
+ host: RendererServiceWorkerHost::new_loading(&ServiceWorkerRunOwner::new(
+ version_id,
+ run.clone(),
+ )),
};
}
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: None,
response_type: "default".to_owned(),
@@ -1891,8 +1891,7 @@ mod tests {
let request_url = url("https://example.test/app/post");
let mut job = ServiceWorkerFetchJob {
internal_id: 312,
- version_id: ServiceWorkerVersionId(1),
- run: Some(crate::runtime::RendererServiceWorkerRunIdentity::fresh()),
+ owner: Some(ServiceWorkerRunOwner::fresh(ServiceWorkerVersionId(1))),
request_url: request_url.clone(),
request_method: "POST".to_owned(),
request_headers: vec![
@@ -1980,8 +1979,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: None,
response_type: "default".to_owned(),
@@ -2028,8 +2026,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: Some(response_url.clone()),
response_type: "default".to_owned(),
@@ -2093,8 +2090,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: None,
response_type: "error".to_owned(),
@@ -2141,8 +2137,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: Some(url("https://cross-origin.test/data.txt")),
response_type: "cors".to_owned(),
@@ -2188,8 +2183,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: None,
response_type: "opaque".to_owned(),
@@ -2248,8 +2242,10 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run: run.clone(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ version_id,
+ run.clone(),
+ ),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: None,
response_type: "opaque".to_owned(),
@@ -2296,8 +2292,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: Some(url("https://cdn.example.test/app/image.png")),
response_type: "default".to_owned(),
@@ -2350,8 +2345,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: Some(url("https://cdn.example.test/app/image.png")),
response_type: "default".to_owned(),
@@ -2414,8 +2408,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: Some(url("https://cdn.example.test/app/pixel.png")),
response_type: "default".to_owned(),
@@ -2474,8 +2467,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: Some(url("https://cdn.example.test/app/pixel.png")),
response_type: "default".to_owned(),
@@ -2533,8 +2525,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: Some(url("https://cdn.example.test/app/pixel.png")),
response_type: "default".to_owned(),
@@ -2592,8 +2583,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: Some(url("https://cdn.example.test/app/pixel.png")),
response_type: "default".to_owned(),
@@ -2652,8 +2642,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: Some(url("https://cdn.example.test/app/pixel.png")),
response_type: "default".to_owned(),
@@ -2706,8 +2695,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: Some(url("https://cdn.example.test/app/pixel.png")),
response_type: "default".to_owned(),
@@ -2765,8 +2753,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: Some(url("https://cdn.example.test/app/pixel.png")),
response_type: "default".to_owned(),
@@ -2823,8 +2810,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: Some(url("https://cdn.example.test/app/pixel.png")),
response_type: "default".to_owned(),
@@ -2875,8 +2861,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: Some(url("https://cdn.example.test/app/pixel.png")),
response_type: "default".to_owned(),
@@ -2934,8 +2919,7 @@ mod tests {
service.finish_fetch_stream_started(ServiceWorkerFetchStreamStarted {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
body_source_id,
response_head: MaterializedServiceWorkerFetchResponseHead {
final_url: Some(url("https://cdn.example.test/app/pixel.png")),
@@ -3002,8 +2986,7 @@ mod tests {
service.finish_fetch_stream_started(ServiceWorkerFetchStreamStarted {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
body_source_id,
response_head: MaterializedServiceWorkerFetchResponseHead {
final_url: Some(url("https://cdn.example.test/app/pixel.png")),
@@ -3067,8 +3050,7 @@ mod tests {
service.finish_fetch_stream_started(ServiceWorkerFetchStreamStarted {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
body_source_id,
response_head: MaterializedServiceWorkerFetchResponseHead {
final_url: Some(url("https://cdn.example.test/app/pixel.png")),
@@ -3119,8 +3101,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: Some(url("https://cdn.example.test/app/data.json")),
response_type: "default".to_owned(),
@@ -3166,8 +3147,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: Some(url("https://cdn.example.test/app/data.json")),
response_type: "default".to_owned(),
@@ -3211,8 +3191,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Response(ServiceWorkerFetchResponse {
final_url: None,
response_type: "opaqueredirect".to_owned(),
@@ -3267,8 +3246,7 @@ mod tests {
service.finish_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
result: ServiceWorkerFetchResult::Fallback,
});
diff --git a/moli-renderer-v8/src/service_worker_runtime/service/functional_requests.rs b/moli-renderer-v8/src/service_worker_runtime/service/functional_requests.rs
index 0adcaea25..d97bb7c9b 100644
--- a/moli-renderer-v8/src/service_worker_runtime/service/functional_requests.rs
+++ b/moli-renderer-v8/src/service_worker_runtime/service/functional_requests.rs
@@ -222,8 +222,7 @@ impl ServiceWorkerRuntimeService {
let event = ServiceWorkerSyncEvent {
event_id,
registration_id: request.registration_id,
- version_id: request.version_id,
- run,
+ owner: ServiceWorkerRunOwner::new(request.version_id, run),
tag: request.tag.clone(),
last_chance: false,
};
diff --git a/moli-renderer-v8/src/service_worker_runtime/service/idle_scheduling.rs b/moli-renderer-v8/src/service_worker_runtime/service/idle_scheduling.rs
index 49ce6ea8c..eca9a6c7a 100644
--- a/moli-renderer-v8/src/service_worker_runtime/service/idle_scheduling.rs
+++ b/moli-renderer-v8/src/service_worker_runtime/service/idle_scheduling.rs
@@ -30,7 +30,7 @@ impl ServiceWorkerRuntimeService {
let _ = std::thread::Builder::new()
.name(format!(
"service-worker-idle-{}",
- timeout.version_id.as_u64()
+ timeout.owner.version_id().as_u64()
))
.spawn(move || {
std::thread::sleep(delay);
diff --git a/moli-renderer-v8/src/service_worker_runtime/service/lifecycle_completion.rs b/moli-renderer-v8/src/service_worker_runtime/service/lifecycle_completion.rs
index 6f5246515..c5c972c0c 100644
--- a/moli-renderer-v8/src/service_worker_runtime/service/lifecycle_completion.rs
+++ b/moli-renderer-v8/src/service_worker_runtime/service/lifecycle_completion.rs
@@ -5,6 +5,8 @@ impl ServiceWorkerRuntimeService {
&self,
completion: ServiceWorkerLifecycleCompletion,
) {
+ let version_id = completion.owner.version_id();
+ let run = completion.owner.cloned_run_identity();
let (
next_progress,
activated_pending_fetch_events,
@@ -12,10 +14,10 @@ impl ServiceWorkerRuntimeService {
failed_replaced_fetch_completions,
) = {
let mut state = self.inner.state.lock();
- let Some(version) = state.versions.get_mut(&completion.version_id) else {
+ let Some(version) = state.versions.get_mut(&version_id) else {
return;
};
- if version.run != completion.run {
+ if version.run != run {
return;
}
let mut activated_pending_fetch_events = Vec::new();
@@ -35,9 +37,7 @@ impl ServiceWorkerRuntimeService {
.get_mut(&registration_id)
.and_then(|registration| {
registration.installing_version_id = None;
- registration
- .pending_register_jobs
- .remove(&completion.version_id)
+ registration.pending_register_jobs.remove(&version_id)
})
.and_then(|mut pending_job| {
let callbacks =
@@ -57,7 +57,7 @@ impl ServiceWorkerRuntimeService {
&state,
registration_id,
vec![ServiceWorkerLifecycleClientEvent::WorkerStateChanged {
- version_id: completion.version_id,
+ version_id,
state: "redundant",
}],
);
@@ -69,31 +69,28 @@ impl ServiceWorkerRuntimeService {
.chain(register_failed)
.collect::<Vec<_>>();
progress.push(LifecycleProgress::ForceUpdatePageLoadCompleted(
- state.take_force_update_page_load_waiters_for_version(
- completion.version_id,
- ),
+ state.take_force_update_page_load_waiters_for_version(version_id),
));
progress.extend(self.cleanup_failed_install_version_locked(
&mut state,
registration_id,
- completion.version_id,
+ version_id,
));
progress
} else {
version.lifecycle_state = ServiceWorkerVersionLifecycleState::Installed;
let registration_id = version.registration_id;
let skip_waiting_requested = version.skip_waiting_requested;
- state.record_target_version_updated(completion.version_id);
+ state.record_target_version_updated(version_id);
let mut pending_register_job = None;
let previous_waiting_version_id = if let Some(registration) =
state.registrations.get_mut(&registration_id)
{
let previous_waiting_version_id = registration.waiting_version_id;
registration.installing_version_id = None;
- registration.waiting_version_id = Some(completion.version_id);
- pending_register_job = registration
- .pending_register_jobs
- .remove(&completion.version_id);
+ registration.waiting_version_id = Some(version_id);
+ pending_register_job =
+ registration.pending_register_jobs.remove(&version_id);
previous_waiting_version_id
} else {
None
@@ -101,21 +98,18 @@ impl ServiceWorkerRuntimeService {
match self.store_registration_resources_locked(
&state,
registration_id,
- completion.version_id,
+ version_id,
) {
Err(register_error) => {
let message = register_error.message.clone();
- if let Some(version) =
- state.versions.get_mut(&completion.version_id)
- {
+ if let Some(version) = state.versions.get_mut(&version_id) {
version.lifecycle_state =
ServiceWorkerVersionLifecycleState::Redundant;
version.last_start_error = Some(message.clone());
}
if let Some(registration) =
state.registrations.get_mut(&registration_id)
- && registration.waiting_version_id
- == Some(completion.version_id)
+ && registration.waiting_version_id == Some(version_id)
{
registration.waiting_version_id = previous_waiting_version_id;
}
@@ -139,7 +133,7 @@ impl ServiceWorkerRuntimeService {
registration_id,
vec![
ServiceWorkerLifecycleClientEvent::WorkerStateChanged {
- version_id: completion.version_id,
+ version_id,
state: "redundant",
},
],
@@ -153,13 +147,13 @@ impl ServiceWorkerRuntimeService {
.collect::<Vec<_>>();
progress.push(LifecycleProgress::ForceUpdatePageLoadCompleted(
state.take_force_update_page_load_waiters_for_version(
- completion.version_id,
+ version_id,
),
));
progress.extend(self.cleanup_failed_install_version_locked(
&mut state,
registration_id,
- completion.version_id,
+ version_id,
));
progress
}
@@ -194,14 +188,13 @@ impl ServiceWorkerRuntimeService {
registration_id,
vec![
ServiceWorkerLifecycleClientEvent::WorkerStateChanged {
- version_id: completion.version_id,
+ version_id,
state: "installed",
},
],
);
if should_skip_waiting
- && let Some(version) =
- state.versions.get_mut(&completion.version_id)
+ && let Some(version) = state.versions.get_mut(&version_id)
{
version.skip_waiting_requested = true;
}
@@ -240,35 +233,35 @@ impl ServiceWorkerRuntimeService {
version.pending_activation_fetch_events.drain(..).collect();
let should_claim_clients = version.clients_claim_requested;
let registration_id = version.registration_id;
- state.record_target_version_updated(completion.version_id);
+ state.record_target_version_updated(version_id);
let Some(registration) = state.registrations.get_mut(&registration_id) else {
return;
};
let previous_active_version_id = registration.active_version_id;
- if registration.installing_version_id == Some(completion.version_id) {
+ if registration.installing_version_id == Some(version_id) {
registration.installing_version_id = None;
}
- if registration.waiting_version_id == Some(completion.version_id) {
+ if registration.waiting_version_id == Some(version_id) {
registration.waiting_version_id = None;
}
- registration.active_version_id = Some(completion.version_id);
+ registration.active_version_id = Some(version_id);
let _ = registration;
let _ = self.store_registration_resources_locked(
&state,
registration_id,
- completion.version_id,
+ version_id,
);
let mut progress = Vec::new();
let mut previous_target_cleanup = None;
if let Some(previous_active_version_id) = previous_active_version_id
- && previous_active_version_id != completion.version_id
+ && previous_active_version_id != version_id
&& let Some(previous_version) =
state.versions.get_mut(&previous_active_version_id)
{
previous_version.lifecycle_state =
ServiceWorkerVersionLifecycleState::Redundant;
previous_version.skip_waiting_requested = false;
- let previous_run = previous_version.run.clone();
+ let previous_owner = previous_version.run_owner();
failed_replaced_pending_events =
previous_version.pending_start_events.drain(..).collect();
let failed_replaced_activation_fetch_events = previous_version
@@ -301,15 +294,16 @@ impl ServiceWorkerRuntimeService {
.pending_fetch_jobs
.iter()
.filter(|(event_id, job)| {
- job.version_id == previous_active_version_id
- && job.is_bound_to_run(&previous_run)
+ job.is_bound_to_owner(&previous_owner)
&& !pending_start_fetch_event_ids.contains(event_id)
&& !pending_activation_fetch_event_ids.contains(event_id)
})
.map(|(event_id, job)| ServiceWorkerFetchCompletion {
event_id: *event_id,
- version_id: job.version_id,
- run: job.run_identity().clone(),
+ owner: ServiceWorkerRunOwner::new(
+ job.version_id(),
+ job.run_identity().clone(),
+ ),
result: ServiceWorkerFetchResult::Failure(
"service worker was replaced by a newer active worker"
.to_owned(),
@@ -321,8 +315,7 @@ impl ServiceWorkerRuntimeService {
.into_iter()
.map(|event| ServiceWorkerFetchCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner,
result: ServiceWorkerFetchResult::Failure(
"service worker was replaced by a newer active worker"
.to_owned(),
@@ -344,11 +337,11 @@ impl ServiceWorkerRuntimeService {
}
let mut lifecycle_events =
vec![ServiceWorkerLifecycleClientEvent::WorkerStateChanged {
- version_id: completion.version_id,
+ version_id,
state: "activated",
}];
if let Some(previous_active_version_id) = previous_active_version_id
- && previous_active_version_id != completion.version_id
+ && previous_active_version_id != version_id
{
lifecycle_events.push(
ServiceWorkerLifecycleClientEvent::WorkerStateChanged {
@@ -358,7 +351,7 @@ impl ServiceWorkerRuntimeService {
);
}
if previous_active_version_id
- .is_some_and(|version_id| version_id != completion.version_id)
+ .is_some_and(|previous_version_id| previous_version_id != version_id)
{
progress.extend(
controller_change_deliveries_for_controlled_clients_locked(
@@ -381,8 +374,7 @@ impl ServiceWorkerRuntimeService {
}),
);
progress.push(LifecycleProgress::ForceUpdatePageLoadCompleted(
- state
- .take_force_update_page_load_waiters_for_version(completion.version_id),
+ state.take_force_update_page_load_waiters_for_version(version_id),
));
let mut pending_ready_jobs = std::mem::take(&mut state.pending_ready_jobs);
let Some(registration) = state.registrations.get(&registration_id) else {
@@ -434,13 +426,11 @@ impl ServiceWorkerRuntimeService {
progress
}
};
- let unregistration_progress = self.unregistration_progress_for_version_if_ready_locked(
- &mut state,
- completion.version_id,
- );
+ let unregistration_progress =
+ self.unregistration_progress_for_version_if_ready_locked(&mut state, version_id);
if unregistration_progress.is_empty() {
if let Some(idle_timeout) =
- self.maybe_schedule_idle_timeout_locked(&mut state, completion.version_id)
+ self.maybe_schedule_idle_timeout_locked(&mut state, version_id)
{
progress.push(LifecycleProgress::ScheduleIdleTimeout(idle_timeout));
}
diff --git a/moli-renderer-v8/src/service_worker_runtime/service/registration_jobs.rs b/moli-renderer-v8/src/service_worker_runtime/service/registration_jobs.rs
index c1eb66b67..a66cb225c 100644
--- a/moli-renderer-v8/src/service_worker_runtime/service/registration_jobs.rs
+++ b/moli-renderer-v8/src/service_worker_runtime/service/registration_jobs.rs
@@ -595,7 +595,7 @@ impl ServiceWorkerRuntimeService {
preloaded_script: Option<LoadedServiceWorkerScript>,
) -> Option<ServiceWorkerQueuedLaunch> {
let allow_identical_script_update = preloaded_script.is_none();
- let (version_id, run, launch_config, host) = self.create_installing_version_locked(
+ let (version_id, owner, launch_config, host) = self.create_installing_version_locked(
state,
registration_id,
&queued_job,
@@ -630,8 +630,7 @@ impl ServiceWorkerRuntimeService {
Some(ServiceWorkerQueuedLaunch {
params: ServiceWorkerLaunchParams {
registration_id,
- version_id,
- run,
+ run_owner: owner,
script_url: queued_job.script_url,
scope_url: queued_job.scope_url,
storage_key: queued_job.storage_key,
@@ -675,7 +674,7 @@ impl ServiceWorkerRuntimeService {
return None;
};
let host = host.clone();
- let run = version.run.clone();
+ let owner = version.run_owner();
let launch_config = version.launch_config.clone();
let register_callbacks = std::mem::take(&mut queued_job.callbacks);
let mut pending_register_job = ServiceWorkerPendingRegisterJob::new_with_options(
@@ -701,8 +700,7 @@ impl ServiceWorkerRuntimeService {
Some(ServiceWorkerQueuedLaunch {
params: ServiceWorkerLaunchParams {
registration_id,
- version_id: new_version_id,
- run,
+ run_owner: owner,
script_url: queued_job.script_url,
scope_url: queued_job.scope_url,
storage_key: queued_job.storage_key,
@@ -730,7 +728,7 @@ impl ServiceWorkerRuntimeService {
allow_identical_script_update: bool,
) -> Option<(
ServiceWorkerVersionId,
- RendererServiceWorkerRunIdentity,
+ ServiceWorkerRunOwner,
ServiceWorkerVersionLaunchConfig,
SharedRendererServiceWorkerHost,
)> {
@@ -741,7 +739,7 @@ impl ServiceWorkerRuntimeService {
break id;
}
};
- let run = RendererServiceWorkerRunIdentity::fresh();
+ let owner = ServiceWorkerRunOwner::fresh(version_id);
let registration = state.registrations.get_mut(&registration_id)?;
registration.script_url = queued_job.script_url.clone();
registration.scope_url = queued_job.scope_url.clone();
@@ -749,7 +747,7 @@ impl ServiceWorkerRuntimeService {
registration.installing_version_id = Some(version_id);
registration.pending_unregistration = false;
let launch_config = ServiceWorkerVersionLaunchConfig::from_queued_register_job(queued_job);
- let host = RendererServiceWorkerHost::new_loading(version_id, &run);
+ let host = RendererServiceWorkerHost::new_loading(&owner);
let should_pause_on_start_for_devtools = self
.should_pause_new_worker_on_start_for_devtools_locked(
state,
@@ -778,7 +776,7 @@ impl ServiceWorkerRuntimeService {
pending_start_events: VecDeque::new(),
pending_activation_fetch_events: VecDeque::new(),
in_flight_event_count: 0,
- run: run.clone(),
+ run: owner.cloned_run_identity(),
idle_timeout_token: None,
skip_waiting_requested: false,
clients_claim_requested: false,
@@ -791,7 +789,7 @@ impl ServiceWorkerRuntimeService {
queued_job.script_url.clone(),
queued_job.scope_url.clone(),
);
- Some((version_id, run, launch_config, host))
+ Some((version_id, owner, launch_config, host))
}
pub(super) fn cleanup_precreated_update_check_version_locked(
diff --git a/moli-renderer-v8/src/service_worker_runtime/service/service_lane_completions.rs b/moli-renderer-v8/src/service_worker_runtime/service/service_lane_completions.rs
index 3e9e0d9a4..d26ee5dc4 100644
--- a/moli-renderer-v8/src/service_worker_runtime/service/service_lane_completions.rs
+++ b/moli-renderer-v8/src/service_worker_runtime/service/service_lane_completions.rs
@@ -3,8 +3,7 @@ use super::*;
impl ServiceWorkerRuntimeService {
pub(in crate::service_worker_runtime) fn enqueue_worker_start_completed(
&self,
- version_id: ServiceWorkerVersionId,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
final_script_url: String,
script_resource: ServiceWorkerScriptResource,
fetch_handler_type: ServiceWorkerFetchHandlerType,
@@ -12,8 +11,7 @@ impl ServiceWorkerRuntimeService {
self.enqueue_service_lane_completion(
ServiceWorkerRuntimeCompletion::version_start_completed(
self.downgrade(),
- version_id,
- run,
+ owner,
final_script_url,
script_resource,
fetch_handler_type,
@@ -24,14 +22,12 @@ impl ServiceWorkerRuntimeService {
pub(in crate::service_worker_runtime) fn enqueue_worker_start_failed(
&self,
- version_id: ServiceWorkerVersionId,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
failure: ServiceWorkerVersionStartFailure,
) {
self.enqueue_service_lane_completion(ServiceWorkerRuntimeCompletion::version_start_failed(
self.downgrade(),
- version_id,
- run,
+ owner,
failure,
));
self.signal_service_lane_wake();
@@ -40,16 +36,14 @@ impl ServiceWorkerRuntimeService {
pub(in crate::service_worker_runtime) fn enqueue_imported_script_loaded(
&self,
registration_id: ServiceWorkerRegistrationId,
- version_id: ServiceWorkerVersionId,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
resource: WorkerScriptResource,
) {
self.enqueue_service_lane_completion(
ServiceWorkerRuntimeCompletion::imported_script_loaded(
self.downgrade(),
registration_id,
- version_id,
- run,
+ owner,
resource,
),
);
@@ -174,14 +168,12 @@ impl ServiceWorkerRuntimeService {
pub(in crate::service_worker_runtime) fn enqueue_show_notification_requested(
&self,
request: ServiceWorkerShowNotification,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
) {
self.enqueue_service_lane_completion(
ServiceWorkerRuntimeCompletion::show_notification_requested(
self.downgrade(),
request,
- run,
source_host,
),
);
@@ -191,14 +183,12 @@ impl ServiceWorkerRuntimeService {
pub(in crate::service_worker_runtime) fn enqueue_get_notifications_requested(
&self,
request: ServiceWorkerGetNotifications,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
) {
self.enqueue_service_lane_completion(
ServiceWorkerRuntimeCompletion::get_notifications_requested(
self.downgrade(),
request,
- run,
source_host,
),
);
@@ -208,14 +198,12 @@ impl ServiceWorkerRuntimeService {
pub(in crate::service_worker_runtime) fn enqueue_sync_registration_requested(
&self,
request: ServiceWorkerSyncRegistration,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
) {
self.enqueue_service_lane_completion(
ServiceWorkerRuntimeCompletion::sync_registration_requested(
self.downgrade(),
request,
- run,
source_host,
),
);
@@ -225,14 +213,12 @@ impl ServiceWorkerRuntimeService {
pub(in crate::service_worker_runtime) fn enqueue_sync_get_tags_requested(
&self,
request: ServiceWorkerSyncGetTags,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
) {
self.enqueue_service_lane_completion(
ServiceWorkerRuntimeCompletion::sync_get_tags_requested(
self.downgrade(),
request,
- run,
source_host,
),
);
@@ -242,14 +228,12 @@ impl ServiceWorkerRuntimeService {
pub(in crate::service_worker_runtime) fn enqueue_periodic_sync_registration_requested(
&self,
request: ServiceWorkerPeriodicSyncRegistration,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
) {
self.enqueue_service_lane_completion(
ServiceWorkerRuntimeCompletion::periodic_sync_registration_requested(
self.downgrade(),
request,
- run,
source_host,
),
);
@@ -259,14 +243,12 @@ impl ServiceWorkerRuntimeService {
pub(in crate::service_worker_runtime) fn enqueue_periodic_sync_get_tags_requested(
&self,
request: ServiceWorkerPeriodicSyncGetTags,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
) {
self.enqueue_service_lane_completion(
ServiceWorkerRuntimeCompletion::periodic_sync_get_tags_requested(
self.downgrade(),
request,
- run,
source_host,
),
);
@@ -276,14 +258,12 @@ impl ServiceWorkerRuntimeService {
pub(in crate::service_worker_runtime) fn enqueue_periodic_sync_unregistration_requested(
&self,
request: ServiceWorkerPeriodicSyncUnregistration,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
) {
self.enqueue_service_lane_completion(
ServiceWorkerRuntimeCompletion::periodic_sync_unregistration_requested(
self.downgrade(),
request,
- run,
source_host,
),
);
@@ -293,14 +273,12 @@ impl ServiceWorkerRuntimeService {
pub(in crate::service_worker_runtime) fn enqueue_push_subscribe_requested(
&self,
request: ServiceWorkerPushSubscribe,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
) {
self.enqueue_service_lane_completion(
ServiceWorkerRuntimeCompletion::push_subscribe_requested(
self.downgrade(),
request,
- run,
source_host,
),
);
@@ -310,14 +288,12 @@ impl ServiceWorkerRuntimeService {
pub(in crate::service_worker_runtime) fn enqueue_push_get_subscription_requested(
&self,
request: ServiceWorkerPushGetSubscription,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
) {
self.enqueue_service_lane_completion(
ServiceWorkerRuntimeCompletion::push_get_subscription_requested(
self.downgrade(),
request,
- run,
source_host,
),
);
@@ -327,14 +303,12 @@ impl ServiceWorkerRuntimeService {
pub(in crate::service_worker_runtime) fn enqueue_push_unsubscribe_requested(
&self,
request: ServiceWorkerPushUnsubscribe,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
) {
self.enqueue_service_lane_completion(
ServiceWorkerRuntimeCompletion::push_unsubscribe_requested(
self.downgrade(),
request,
- run,
source_host,
),
);
@@ -344,13 +318,13 @@ impl ServiceWorkerRuntimeService {
pub(in crate::service_worker_runtime) fn enqueue_close_notification_requested(
&self,
request: ServiceWorkerCloseNotification,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
) {
self.enqueue_service_lane_completion(
ServiceWorkerRuntimeCompletion::close_notification_requested(
self.downgrade(),
request,
- run,
+ owner,
),
);
self.signal_service_lane_wake();
@@ -375,12 +349,12 @@ impl ServiceWorkerRuntimeService {
pub(crate) fn enqueue_client_query(
&self,
query: ServiceWorkerClientQuery,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
) {
self.enqueue_service_lane_completion(ServiceWorkerRuntimeCompletion::client_query(
self.downgrade(),
query,
- run,
+ owner,
));
self.signal_service_lane_wake();
}
@@ -388,12 +362,12 @@ impl ServiceWorkerRuntimeService {
pub(crate) fn enqueue_client_navigate(
&self,
navigate: ServiceWorkerClientNavigate,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
) {
self.enqueue_service_lane_completion(ServiceWorkerRuntimeCompletion::client_navigate(
self.downgrade(),
navigate,
- run,
+ owner,
));
self.signal_service_lane_wake();
}
@@ -401,12 +375,12 @@ impl ServiceWorkerRuntimeService {
pub(crate) fn enqueue_client_focus(
&self,
focus: ServiceWorkerClientFocus,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
) {
self.enqueue_service_lane_completion(ServiceWorkerRuntimeCompletion::client_focus(
self.downgrade(),
focus,
- run,
+ owner,
));
self.signal_service_lane_wake();
}
@@ -414,12 +388,12 @@ impl ServiceWorkerRuntimeService {
pub(crate) fn enqueue_clients_open_window(
&self,
open_window: ServiceWorkerClientsOpenWindow,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
) {
self.enqueue_service_lane_completion(ServiceWorkerRuntimeCompletion::clients_open_window(
self.downgrade(),
open_window,
- run,
+ owner,
));
self.signal_service_lane_wake();
}
diff --git a/moli-renderer-v8/src/service_worker_runtime/service/worker_completion.rs b/moli-renderer-v8/src/service_worker_runtime/service/worker_completion.rs
index a5dafc360..cdd47330e 100644
--- a/moli-renderer-v8/src/service_worker_runtime/service/worker_completion.rs
+++ b/moli-renderer-v8/src/service_worker_runtime/service/worker_completion.rs
@@ -145,24 +145,27 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerPendingStartEvent::Fetch(event) => {
let dispatch = {
let state = self.inner.state.lock();
- state.versions.get(&event.version_id).and_then(|version| {
- if version.run != event.run {
- return None;
- }
- if version.fetch_handler_existence
- != ServiceWorkerFetchHandlerExistence::Unknown
- && version.fetch_handler_type.allows_fetch_event_skip()
- {
- return Some(Err(()));
- }
- match &version.running_state {
- ServiceWorkerVersionRunningState::Running { host } => {
- Some(Ok(host.clone()))
+ state
+ .versions
+ .get(&event.owner.version_id())
+ .and_then(|version| {
+ if &version.run != event.owner.run_identity() {
+ return None;
}
- ServiceWorkerVersionRunningState::Stopped
- | ServiceWorkerVersionRunningState::Starting { .. } => None,
- }
- })
+ if version.fetch_handler_existence
+ != ServiceWorkerFetchHandlerExistence::Unknown
+ && version.fetch_handler_type.allows_fetch_event_skip()
+ {
+ return Some(Err(()));
+ }
+ match &version.running_state {
+ ServiceWorkerVersionRunningState::Running { host } => {
+ Some(Ok(host.clone()))
+ }
+ ServiceWorkerVersionRunningState::Stopped
+ | ServiceWorkerVersionRunningState::Starting { .. } => None,
+ }
+ })
};
match dispatch {
Some(Ok(host)) => {
@@ -171,16 +174,14 @@ impl ServiceWorkerRuntimeService {
Some(Err(())) => {
self.enqueue_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
result: ServiceWorkerFetchResult::Fallback,
});
}
None => {
self.enqueue_fetch_event_completed(ServiceWorkerFetchCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
result: ServiceWorkerFetchResult::Failure(
"service worker fetch dispatch failed: worker did not start"
.to_owned(),
@@ -192,26 +193,28 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerPendingStartEvent::Lifecycle(event) => {
let host = {
let state = self.inner.state.lock();
- state.versions.get(&event.version_id).and_then(|version| {
- if version.run != event.run {
- return None;
- }
- match &version.running_state {
- ServiceWorkerVersionRunningState::Running { host } => {
- Some(host.clone())
+ state
+ .versions
+ .get(&event.owner.version_id())
+ .and_then(|version| {
+ if &version.run != event.owner.run_identity() {
+ return None;
}
- ServiceWorkerVersionRunningState::Stopped
- | ServiceWorkerVersionRunningState::Starting { .. } => None,
- }
- })
+ match &version.running_state {
+ ServiceWorkerVersionRunningState::Running { host } => {
+ Some(host.clone())
+ }
+ ServiceWorkerVersionRunningState::Stopped
+ | ServiceWorkerVersionRunningState::Starting { .. } => None,
+ }
+ })
};
if let Some(host) = host {
self.dispatch_lifecycle_event(host, event);
} else {
self.enqueue_lifecycle_event_completed(ServiceWorkerLifecycleCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
kind: event.kind,
result: Err(
"service worker lifecycle dispatch failed: worker did not start"
@@ -223,26 +226,28 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerPendingStartEvent::Message(event) => {
let host = {
let state = self.inner.state.lock();
- state.versions.get(&event.version_id).and_then(|version| {
- if version.run != event.run {
- return None;
- }
- match &version.running_state {
- ServiceWorkerVersionRunningState::Running { host } => {
- Some(host.clone())
+ state
+ .versions
+ .get(&event.owner.version_id())
+ .and_then(|version| {
+ if &version.run != event.owner.run_identity() {
+ return None;
}
- ServiceWorkerVersionRunningState::Stopped
- | ServiceWorkerVersionRunningState::Starting { .. } => None,
- }
- })
+ match &version.running_state {
+ ServiceWorkerVersionRunningState::Running { host } => {
+ Some(host.clone())
+ }
+ ServiceWorkerVersionRunningState::Stopped
+ | ServiceWorkerVersionRunningState::Starting { .. } => None,
+ }
+ })
};
if let Some(host) = host {
self.dispatch_message_event(host, event);
} else {
self.enqueue_message_event_completed(ServiceWorkerMessageCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
result: Err(
"service worker message dispatch failed: worker did not start"
.to_owned(),
@@ -253,18 +258,21 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerPendingStartEvent::Notification(event) => {
let host = {
let state = self.inner.state.lock();
- state.versions.get(&event.version_id).and_then(|version| {
- if version.run != event.run {
- return None;
- }
- match &version.running_state {
- ServiceWorkerVersionRunningState::Running { host } => {
- Some(host.clone())
+ state
+ .versions
+ .get(&event.owner.version_id())
+ .and_then(|version| {
+ if &version.run != event.owner.run_identity() {
+ return None;
}
- ServiceWorkerVersionRunningState::Stopped
- | ServiceWorkerVersionRunningState::Starting { .. } => None,
- }
- })
+ match &version.running_state {
+ ServiceWorkerVersionRunningState::Running { host } => {
+ Some(host.clone())
+ }
+ ServiceWorkerVersionRunningState::Stopped
+ | ServiceWorkerVersionRunningState::Starting { .. } => None,
+ }
+ })
};
if let Some(host) = host {
self.dispatch_notification_event_to_host(host, event);
@@ -272,8 +280,7 @@ impl ServiceWorkerRuntimeService {
self.enqueue_notification_event_completed(
ServiceWorkerNotificationCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
result: Err(
"service worker notification dispatch failed: worker did not start"
.to_owned(),
@@ -285,26 +292,28 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerPendingStartEvent::Push(event) => {
let host = {
let state = self.inner.state.lock();
- state.versions.get(&event.version_id).and_then(|version| {
- if version.run != event.run {
- return None;
- }
- match &version.running_state {
- ServiceWorkerVersionRunningState::Running { host } => {
- Some(host.clone())
+ state
+ .versions
+ .get(&event.owner.version_id())
+ .and_then(|version| {
+ if &version.run != event.owner.run_identity() {
+ return None;
}
- ServiceWorkerVersionRunningState::Stopped
- | ServiceWorkerVersionRunningState::Starting { .. } => None,
- }
- })
+ match &version.running_state {
+ ServiceWorkerVersionRunningState::Running { host } => {
+ Some(host.clone())
+ }
+ ServiceWorkerVersionRunningState::Stopped
+ | ServiceWorkerVersionRunningState::Starting { .. } => None,
+ }
+ })
};
if let Some(host) = host {
self.dispatch_push_event_to_host(host, event);
} else {
self.enqueue_push_event_completed(ServiceWorkerPushCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
result: Err(
"service worker push dispatch failed: worker did not start"
.to_owned(),
@@ -315,18 +324,21 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerPendingStartEvent::Sync(event) => {
let host = {
let state = self.inner.state.lock();
- state.versions.get(&event.version_id).and_then(|version| {
- if version.run != event.run {
- return None;
- }
- match &version.running_state {
- ServiceWorkerVersionRunningState::Running { host } => {
- Some(host.clone())
+ state
+ .versions
+ .get(&event.owner.version_id())
+ .and_then(|version| {
+ if &version.run != event.owner.run_identity() {
+ return None;
}
- ServiceWorkerVersionRunningState::Stopped
- | ServiceWorkerVersionRunningState::Starting { .. } => None,
- }
- })
+ match &version.running_state {
+ ServiceWorkerVersionRunningState::Running { host } => {
+ Some(host.clone())
+ }
+ ServiceWorkerVersionRunningState::Stopped
+ | ServiceWorkerVersionRunningState::Starting { .. } => None,
+ }
+ })
};
if let Some(host) = host {
self.dispatch_sync_event_to_host(host, event);
@@ -334,8 +346,7 @@ impl ServiceWorkerRuntimeService {
self.enqueue_sync_event_completed(ServiceWorkerSyncCompletion {
event_id: event.event_id,
registration_id: event.registration_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
tag: event.tag,
result: Err(
"service worker sync dispatch failed: worker did not start"
@@ -347,18 +358,21 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerPendingStartEvent::PeriodicSync(event) => {
let host = {
let state = self.inner.state.lock();
- state.versions.get(&event.version_id).and_then(|version| {
- if version.run != event.run {
- return None;
- }
- match &version.running_state {
- ServiceWorkerVersionRunningState::Running { host } => {
- Some(host.clone())
+ state
+ .versions
+ .get(&event.owner.version_id())
+ .and_then(|version| {
+ if &version.run != event.owner.run_identity() {
+ return None;
}
- ServiceWorkerVersionRunningState::Stopped
- | ServiceWorkerVersionRunningState::Starting { .. } => None,
- }
- })
+ match &version.running_state {
+ ServiceWorkerVersionRunningState::Running { host } => {
+ Some(host.clone())
+ }
+ ServiceWorkerVersionRunningState::Stopped
+ | ServiceWorkerVersionRunningState::Starting { .. } => None,
+ }
+ })
};
if let Some(host) = host {
self.dispatch_periodic_sync_event_to_host(host, event);
@@ -367,8 +381,7 @@ impl ServiceWorkerRuntimeService {
ServiceWorkerPeriodicSyncCompletion {
event_id: event.event_id,
registration_id: event.registration_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
tag: event.tag,
result: Err(
"service worker periodic sync dispatch failed: worker did not start"
@@ -891,13 +904,13 @@ impl ServiceWorkerRuntimeService {
}
pub(super) fn finish_worker_idle_timeout(&self, timeout: ServiceWorkerIdleTimeout) {
- let version_id = timeout.version_id;
+ let version_id = timeout.owner.version_id();
let host = {
let mut state = self.inner.state.lock();
let Some(version) = state.versions.get(&version_id) else {
return;
};
- if version.run != timeout.run
+ if &version.run != timeout.owner.run_identity()
|| version.idle_timeout_token.as_ref() != Some(&timeout.token)
|| version.lifecycle_state != ServiceWorkerVersionLifecycleState::Activated
|| version.in_flight_event_count != 0
diff --git a/moli-renderer-v8/src/service_worker_runtime/start_completion.rs b/moli-renderer-v8/src/service_worker_runtime/start_completion.rs
index ed8c5be74..9eafad303 100644
--- a/moli-renderer-v8/src/service_worker_runtime/start_completion.rs
+++ b/moli-renderer-v8/src/service_worker_runtime/start_completion.rs
@@ -17,13 +17,14 @@ use super::{
},
host::SharedRendererServiceWorkerHost,
ids::{ServiceWorkerRegistrationId, ServiceWorkerVersionId},
+ run_owner::ServiceWorkerRunOwner,
script_loading::{ServiceWorkerScriptResource, ServiceWorkerScriptUpdateCheckCompletion},
state::WeakServiceWorkerRuntimeService,
version::{
ServiceWorkerFetchHandlerType, ServiceWorkerIdleTimeout, ServiceWorkerVersionStartFailure,
},
};
-use crate::{runtime::RendererServiceWorkerRunIdentity, worker::WorkerScriptResource};
+use crate::worker::WorkerScriptResource;
pub(super) struct ServiceWorkerRuntimeCompletion {
runtime_service: WeakServiceWorkerRuntimeService,
@@ -32,21 +33,18 @@ pub(super) struct ServiceWorkerRuntimeCompletion {
enum ServiceWorkerRuntimeCompletionKind {
VersionStartCompleted {
- version_id: ServiceWorkerVersionId,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
final_script_url: String,
script_resource: ServiceWorkerScriptResource,
fetch_handler_type: ServiceWorkerFetchHandlerType,
},
VersionStartFailed {
- version_id: ServiceWorkerVersionId,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
failure: ServiceWorkerVersionStartFailure,
},
ImportedScriptLoaded {
registration_id: ServiceWorkerRegistrationId,
- version_id: ServiceWorkerVersionId,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
resource: WorkerScriptResource,
},
MainScriptUpdateCheckCompleted {
@@ -82,57 +80,47 @@ enum ServiceWorkerRuntimeCompletionKind {
},
ShowNotificationRequested {
request: Box<ServiceWorkerShowNotification>,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
},
GetNotificationsRequested {
request: ServiceWorkerGetNotifications,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
},
SyncRegistrationRequested {
request: ServiceWorkerSyncRegistration,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
},
SyncGetTagsRequested {
request: ServiceWorkerSyncGetTags,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
},
PeriodicSyncRegistrationRequested {
request: ServiceWorkerPeriodicSyncRegistration,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
},
PeriodicSyncGetTagsRequested {
request: ServiceWorkerPeriodicSyncGetTags,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
},
PeriodicSyncUnregistrationRequested {
request: ServiceWorkerPeriodicSyncUnregistration,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
},
PushSubscribeRequested {
request: ServiceWorkerPushSubscribe,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
},
PushGetSubscriptionRequested {
request: ServiceWorkerPushGetSubscription,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
},
PushUnsubscribeRequested {
request: ServiceWorkerPushUnsubscribe,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
},
CloseNotificationRequested {
request: ServiceWorkerCloseNotification,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
},
ClientMessage {
message: ServiceWorkerClientMessage,
@@ -142,25 +130,25 @@ enum ServiceWorkerRuntimeCompletionKind {
},
ClientQuery {
query: ServiceWorkerClientQuery,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
},
ClientNavigate {
navigate: ServiceWorkerClientNavigate,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
},
ClientNavigateCompleted {
completion: crate::types::ServiceWorkerClientNavigateCompletion,
},
ClientFocus {
focus: ServiceWorkerClientFocus,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
},
ClientFocusCompleted {
completion: crate::types::ServiceWorkerClientFocusCompletion,
},
ClientsOpenWindow {
open_window: ServiceWorkerClientsOpenWindow,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
},
ClientsOpenWindowCompleted {
completion: crate::types::ServiceWorkerClientsOpenWindowCompletion,
@@ -179,8 +167,7 @@ enum ServiceWorkerRuntimeCompletionKind {
impl ServiceWorkerRuntimeCompletion {
pub(super) fn version_start_completed(
runtime_service: WeakServiceWorkerRuntimeService,
- version_id: ServiceWorkerVersionId,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
final_script_url: String,
script_resource: ServiceWorkerScriptResource,
fetch_handler_type: ServiceWorkerFetchHandlerType,
@@ -188,8 +175,7 @@ impl ServiceWorkerRuntimeCompletion {
Self {
runtime_service,
kind: ServiceWorkerRuntimeCompletionKind::VersionStartCompleted {
- version_id,
- run,
+ owner,
final_script_url,
script_resource,
fetch_handler_type,
@@ -199,33 +185,26 @@ impl ServiceWorkerRuntimeCompletion {
pub(super) fn version_start_failed(
runtime_service: WeakServiceWorkerRuntimeService,
- version_id: ServiceWorkerVersionId,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
failure: ServiceWorkerVersionStartFailure,
) -> Self {
Self {
runtime_service,
- kind: ServiceWorkerRuntimeCompletionKind::VersionStartFailed {
- version_id,
- run,
- failure,
- },
+ kind: ServiceWorkerRuntimeCompletionKind::VersionStartFailed { owner, failure },
}
}
pub(super) fn imported_script_loaded(
runtime_service: WeakServiceWorkerRuntimeService,
registration_id: ServiceWorkerRegistrationId,
- version_id: ServiceWorkerVersionId,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
resource: WorkerScriptResource,
) -> Self {
Self {
runtime_service,
kind: ServiceWorkerRuntimeCompletionKind::ImportedScriptLoaded {
registration_id,
- version_id,
- run,
+ owner,
resource,
},
}
@@ -338,14 +317,12 @@ impl ServiceWorkerRuntimeCompletion {
pub(super) fn show_notification_requested(
runtime_service: WeakServiceWorkerRuntimeService,
request: ServiceWorkerShowNotification,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
) -> Self {
Self {
runtime_service,
kind: ServiceWorkerRuntimeCompletionKind::ShowNotificationRequested {
request: Box::new(request),
- run,
source_host,
},
}
@@ -354,14 +331,12 @@ impl ServiceWorkerRuntimeCompletion {
pub(super) fn get_notifications_requested(
runtime_service: WeakServiceWorkerRuntimeService,
request: ServiceWorkerGetNotifications,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
) -> Self {
Self {
runtime_service,
kind: ServiceWorkerRuntimeCompletionKind::GetNotificationsRequested {
request,
- run,
source_host,
},
}
@@ -370,14 +345,12 @@ impl ServiceWorkerRuntimeCompletion {
pub(super) fn sync_registration_requested(
runtime_service: WeakServiceWorkerRuntimeService,
request: ServiceWorkerSyncRegistration,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
) -> Self {
Self {
runtime_service,
kind: ServiceWorkerRuntimeCompletionKind::SyncRegistrationRequested {
request,
- run,
source_host,
},
}
@@ -386,14 +359,12 @@ impl ServiceWorkerRuntimeCompletion {
pub(super) fn sync_get_tags_requested(
runtime_service: WeakServiceWorkerRuntimeService,
request: ServiceWorkerSyncGetTags,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
) -> Self {
Self {
runtime_service,
kind: ServiceWorkerRuntimeCompletionKind::SyncGetTagsRequested {
request,
- run,
source_host,
},
}
@@ -402,14 +373,12 @@ impl ServiceWorkerRuntimeCompletion {
pub(super) fn periodic_sync_registration_requested(
runtime_service: WeakServiceWorkerRuntimeService,
request: ServiceWorkerPeriodicSyncRegistration,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
) -> Self {
Self {
runtime_service,
kind: ServiceWorkerRuntimeCompletionKind::PeriodicSyncRegistrationRequested {
request,
- run,
source_host,
},
}
@@ -418,14 +387,12 @@ impl ServiceWorkerRuntimeCompletion {
pub(super) fn periodic_sync_get_tags_requested(
runtime_service: WeakServiceWorkerRuntimeService,
request: ServiceWorkerPeriodicSyncGetTags,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
) -> Self {
Self {
runtime_service,
kind: ServiceWorkerRuntimeCompletionKind::PeriodicSyncGetTagsRequested {
request,
- run,
source_host,
},
}
@@ -434,14 +401,12 @@ impl ServiceWorkerRuntimeCompletion {
pub(super) fn periodic_sync_unregistration_requested(
runtime_service: WeakServiceWorkerRuntimeService,
request: ServiceWorkerPeriodicSyncUnregistration,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
) -> Self {
Self {
runtime_service,
kind: ServiceWorkerRuntimeCompletionKind::PeriodicSyncUnregistrationRequested {
request,
- run,
source_host,
},
}
@@ -450,14 +415,12 @@ impl ServiceWorkerRuntimeCompletion {
pub(super) fn push_subscribe_requested(
runtime_service: WeakServiceWorkerRuntimeService,
request: ServiceWorkerPushSubscribe,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
) -> Self {
Self {
runtime_service,
kind: ServiceWorkerRuntimeCompletionKind::PushSubscribeRequested {
request,
- run,
source_host,
},
}
@@ -466,14 +429,12 @@ impl ServiceWorkerRuntimeCompletion {
pub(super) fn push_get_subscription_requested(
runtime_service: WeakServiceWorkerRuntimeService,
request: ServiceWorkerPushGetSubscription,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
) -> Self {
Self {
runtime_service,
kind: ServiceWorkerRuntimeCompletionKind::PushGetSubscriptionRequested {
request,
- run,
source_host,
},
}
@@ -482,14 +443,12 @@ impl ServiceWorkerRuntimeCompletion {
pub(super) fn push_unsubscribe_requested(
runtime_service: WeakServiceWorkerRuntimeService,
request: ServiceWorkerPushUnsubscribe,
- run: RendererServiceWorkerRunIdentity,
source_host: SharedRendererServiceWorkerHost,
) -> Self {
Self {
runtime_service,
kind: ServiceWorkerRuntimeCompletionKind::PushUnsubscribeRequested {
request,
- run,
source_host,
},
}
@@ -498,11 +457,11 @@ impl ServiceWorkerRuntimeCompletion {
pub(super) fn close_notification_requested(
runtime_service: WeakServiceWorkerRuntimeService,
request: ServiceWorkerCloseNotification,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
) -> Self {
Self {
runtime_service,
- kind: ServiceWorkerRuntimeCompletionKind::CloseNotificationRequested { request, run },
+ kind: ServiceWorkerRuntimeCompletionKind::CloseNotificationRequested { request, owner },
}
}
@@ -529,22 +488,22 @@ impl ServiceWorkerRuntimeCompletion {
pub(super) fn client_query(
runtime_service: WeakServiceWorkerRuntimeService,
query: ServiceWorkerClientQuery,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
) -> Self {
Self {
runtime_service,
- kind: ServiceWorkerRuntimeCompletionKind::ClientQuery { query, run },
+ kind: ServiceWorkerRuntimeCompletionKind::ClientQuery { query, owner },
}
}
pub(super) fn client_navigate(
runtime_service: WeakServiceWorkerRuntimeService,
navigate: ServiceWorkerClientNavigate,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
) -> Self {
Self {
runtime_service,
- kind: ServiceWorkerRuntimeCompletionKind::ClientNavigate { navigate, run },
+ kind: ServiceWorkerRuntimeCompletionKind::ClientNavigate { navigate, owner },
}
}
@@ -561,11 +520,11 @@ impl ServiceWorkerRuntimeCompletion {
pub(super) fn client_focus(
runtime_service: WeakServiceWorkerRuntimeService,
focus: ServiceWorkerClientFocus,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
) -> Self {
Self {
runtime_service,
- kind: ServiceWorkerRuntimeCompletionKind::ClientFocus { focus, run },
+ kind: ServiceWorkerRuntimeCompletionKind::ClientFocus { focus, owner },
}
}
@@ -582,11 +541,11 @@ impl ServiceWorkerRuntimeCompletion {
pub(super) fn clients_open_window(
runtime_service: WeakServiceWorkerRuntimeService,
open_window: ServiceWorkerClientsOpenWindow,
- run: RendererServiceWorkerRunIdentity,
+ owner: ServiceWorkerRunOwner,
) -> Self {
Self {
runtime_service,
- kind: ServiceWorkerRuntimeCompletionKind::ClientsOpenWindow { open_window, run },
+ kind: ServiceWorkerRuntimeCompletionKind::ClientsOpenWindow { open_window, owner },
}
}
@@ -641,36 +600,38 @@ impl ServiceWorkerRuntimeCompletion {
pub(super) fn complete(self) {
match self.kind {
ServiceWorkerRuntimeCompletionKind::VersionStartCompleted {
- version_id,
- run,
+ owner,
final_script_url,
script_resource,
fetch_handler_type,
- } => self.runtime_service.finish_worker_start_completed(
- version_id,
- run,
- final_script_url,
- Some(script_resource),
- fetch_handler_type,
- ),
- ServiceWorkerRuntimeCompletionKind::VersionStartFailed {
- version_id,
- run,
- failure,
- } => self
- .runtime_service
- .finish_worker_start_failed(version_id, run, failure),
+ } => {
+ let (version_id, run) = owner.into_parts();
+ self.runtime_service.finish_worker_start_completed(
+ version_id,
+ run,
+ final_script_url,
+ Some(script_resource),
+ fetch_handler_type,
+ )
+ }
+ ServiceWorkerRuntimeCompletionKind::VersionStartFailed { owner, failure } => {
+ let (version_id, run) = owner.into_parts();
+ self.runtime_service
+ .finish_worker_start_failed(version_id, run, failure)
+ }
ServiceWorkerRuntimeCompletionKind::ImportedScriptLoaded {
registration_id,
- version_id,
- run,
+ owner,
resource,
- } => self.runtime_service.finish_imported_script_loaded(
- registration_id,
- version_id,
- run,
- resource,
- ),
+ } => {
+ let (version_id, run) = owner.into_parts();
+ self.runtime_service.finish_imported_script_loaded(
+ registration_id,
+ version_id,
+ run,
+ resource,
+ )
+ }
ServiceWorkerRuntimeCompletionKind::MainScriptUpdateCheckCompleted {
registration_id,
result,
@@ -711,73 +672,73 @@ impl ServiceWorkerRuntimeCompletion {
}
ServiceWorkerRuntimeCompletionKind::ShowNotificationRequested {
request,
- run,
source_host,
} => {
+ let run = source_host.run_identity();
self.runtime_service
.finish_show_notification_requested(*request, run, source_host);
}
ServiceWorkerRuntimeCompletionKind::GetNotificationsRequested {
request,
- run,
source_host,
} => {
+ let run = source_host.run_identity();
self.runtime_service
.finish_get_notifications_requested(request, run, source_host);
}
ServiceWorkerRuntimeCompletionKind::SyncRegistrationRequested {
request,
- run,
source_host,
} => {
+ let run = source_host.run_identity();
self.runtime_service
.finish_sync_registration_requested(request, run, source_host);
}
ServiceWorkerRuntimeCompletionKind::SyncGetTagsRequested {
request,
- run,
source_host,
} => {
+ let run = source_host.run_identity();
self.runtime_service
.finish_sync_get_tags_requested(request, run, source_host);
}
ServiceWorkerRuntimeCompletionKind::PeriodicSyncRegistrationRequested {
request,
- run,
source_host,
} => {
+ let run = source_host.run_identity();
self.runtime_service
.finish_periodic_sync_registration_requested(request, run, source_host);
}
ServiceWorkerRuntimeCompletionKind::PeriodicSyncGetTagsRequested {
request,
- run,
source_host,
} => {
+ let run = source_host.run_identity();
self.runtime_service
.finish_periodic_sync_get_tags_requested(request, run, source_host);
}
ServiceWorkerRuntimeCompletionKind::PeriodicSyncUnregistrationRequested {
request,
- run,
source_host,
} => {
+ let run = source_host.run_identity();
self.runtime_service
.finish_periodic_sync_unregistration_requested(request, run, source_host);
}
ServiceWorkerRuntimeCompletionKind::PushSubscribeRequested {
request,
- run,
source_host,
} => {
+ let run = source_host.run_identity();
self.runtime_service
.finish_push_subscribe_requested(request, run, source_host);
}
ServiceWorkerRuntimeCompletionKind::PushGetSubscriptionRequested {
request,
- run,
source_host,
} => {
+ let run = source_host.run_identity();
self.runtime_service.finish_push_get_subscription_requested(
request,
run,
@@ -786,15 +747,18 @@ impl ServiceWorkerRuntimeCompletion {
}
ServiceWorkerRuntimeCompletionKind::PushUnsubscribeRequested {
request,
- run,
source_host,
} => {
+ let run = source_host.run_identity();
self.runtime_service
.finish_push_unsubscribe_requested(request, run, source_host);
}
- ServiceWorkerRuntimeCompletionKind::CloseNotificationRequested { request, run } => {
+ ServiceWorkerRuntimeCompletionKind::CloseNotificationRequested { request, owner } => {
+ if owner.version_id() != request.version_id {
+ return;
+ }
self.runtime_service
- .finish_close_notification_requested(request, run);
+ .finish_close_notification_requested(request, owner.cloned_run_identity());
}
ServiceWorkerRuntimeCompletionKind::ClientMessage { message } => {
self.runtime_service.finish_client_message(message);
@@ -802,29 +766,41 @@ impl ServiceWorkerRuntimeCompletion {
ServiceWorkerRuntimeCompletionKind::WorkerMessage { message } => {
self.runtime_service.finish_worker_message(message);
}
- ServiceWorkerRuntimeCompletionKind::ClientQuery { query, run } => {
+ ServiceWorkerRuntimeCompletionKind::ClientQuery { query, owner } => {
+ if owner.version_id() != query.version_id {
+ return;
+ }
self.runtime_service
- .finish_client_query_requested(query, run);
+ .finish_client_query_requested(query, owner.cloned_run_identity());
}
- ServiceWorkerRuntimeCompletionKind::ClientNavigate { navigate, run } => {
+ ServiceWorkerRuntimeCompletionKind::ClientNavigate { navigate, owner } => {
+ if owner.version_id() != navigate.source_version_id {
+ return;
+ }
self.runtime_service
- .finish_client_navigate_requested(navigate, run);
+ .finish_client_navigate_requested(navigate, owner.cloned_run_identity());
}
ServiceWorkerRuntimeCompletionKind::ClientNavigateCompleted { completion } => {
self.runtime_service
.finish_client_navigate_completed(completion);
}
- ServiceWorkerRuntimeCompletionKind::ClientFocus { focus, run } => {
+ ServiceWorkerRuntimeCompletionKind::ClientFocus { focus, owner } => {
+ if owner.version_id() != focus.source_version_id {
+ return;
+ }
self.runtime_service
- .finish_client_focus_requested(focus, run);
+ .finish_client_focus_requested(focus, owner.cloned_run_identity());
}
ServiceWorkerRuntimeCompletionKind::ClientFocusCompleted { completion } => {
self.runtime_service
.finish_client_focus_completed(completion);
}
- ServiceWorkerRuntimeCompletionKind::ClientsOpenWindow { open_window, run } => {
+ ServiceWorkerRuntimeCompletionKind::ClientsOpenWindow { open_window, owner } => {
+ if owner.version_id() != open_window.source_version_id {
+ return;
+ }
self.runtime_service
- .finish_clients_open_window_requested(open_window, run);
+ .finish_clients_open_window_requested(open_window, owner.cloned_run_identity());
}
ServiceWorkerRuntimeCompletionKind::ClientsOpenWindowCompleted { completion } => {
self.runtime_service
@@ -852,30 +828,22 @@ impl ServiceWorkerRuntimeCompletion {
impl fmt::Debug for ServiceWorkerRuntimeCompletion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.kind {
- ServiceWorkerRuntimeCompletionKind::VersionStartCompleted {
- version_id, run, ..
- } => f
+ ServiceWorkerRuntimeCompletionKind::VersionStartCompleted { owner, .. } => f
.debug_struct("ServiceWorkerRuntimeCompletion::VersionStartCompleted")
- .field("version_id", version_id)
- .field("run", run)
+ .field("owner", owner)
.finish_non_exhaustive(),
- ServiceWorkerRuntimeCompletionKind::VersionStartFailed {
- version_id, run, ..
- } => f
+ ServiceWorkerRuntimeCompletionKind::VersionStartFailed { owner, .. } => f
.debug_struct("ServiceWorkerRuntimeCompletion::VersionStartFailed")
- .field("version_id", version_id)
- .field("run", run)
+ .field("owner", owner)
.finish_non_exhaustive(),
ServiceWorkerRuntimeCompletionKind::ImportedScriptLoaded {
registration_id,
- version_id,
- run,
+ owner,
..
} => f
.debug_struct("ServiceWorkerRuntimeCompletion::ImportedScriptLoaded")
.field("registration_id", registration_id)
- .field("version_id", version_id)
- .field("run", run)
+ .field("owner", owner)
.finish_non_exhaustive(),
ServiceWorkerRuntimeCompletionKind::MainScriptUpdateCheckCompleted {
registration_id,
@@ -888,21 +856,18 @@ impl fmt::Debug for ServiceWorkerRuntimeCompletion {
ServiceWorkerRuntimeCompletionKind::LifecycleEventCompleted { completion } => f
.debug_struct("ServiceWorkerRuntimeCompletion::LifecycleEventCompleted")
.field("event_id", &completion.event_id)
- .field("version_id", &completion.version_id)
- .field("run", &completion.run)
+ .field("owner", &completion.owner)
.field("kind", &completion.kind)
.finish_non_exhaustive(),
ServiceWorkerRuntimeCompletionKind::FetchEventCompleted { completion } => f
.debug_struct("ServiceWorkerRuntimeCompletion::FetchEventCompleted")
.field("event_id", &completion.event_id)
- .field("version_id", &completion.version_id)
- .field("run", &completion.run)
+ .field("owner", &completion.owner)
.finish_non_exhaustive(),
ServiceWorkerRuntimeCompletionKind::FetchStreamStarted { started } => f
.debug_struct("ServiceWorkerRuntimeCompletion::FetchStreamStarted")
.field("event_id", &started.event_id)
- .field("version_id", &started.version_id)
- .field("run", &started.run)
+ .field("owner", &started.owner)
.field("body_source_id", &started.body_source_id)
.finish_non_exhaustive(),
ServiceWorkerRuntimeCompletionKind::FetchStreamChunk { chunk } => f
@@ -914,111 +879,109 @@ impl fmt::Debug for ServiceWorkerRuntimeCompletion {
ServiceWorkerRuntimeCompletionKind::MessageEventCompleted { completion } => f
.debug_struct("ServiceWorkerRuntimeCompletion::MessageEventCompleted")
.field("event_id", &completion.event_id)
- .field("version_id", &completion.version_id)
- .field("run", &completion.run)
+ .field("owner", &completion.owner)
.finish_non_exhaustive(),
ServiceWorkerRuntimeCompletionKind::NotificationEventCompleted { completion } => f
.debug_struct("ServiceWorkerRuntimeCompletion::NotificationEventCompleted")
.field("event_id", &completion.event_id)
- .field("version_id", &completion.version_id)
- .field("run", &completion.run)
+ .field("owner", &completion.owner)
.finish_non_exhaustive(),
ServiceWorkerRuntimeCompletionKind::PushEventCompleted { completion } => f
.debug_struct("ServiceWorkerRuntimeCompletion::PushEventCompleted")
.field("event_id", &completion.event_id)
- .field("version_id", &completion.version_id)
- .field("run", &completion.run)
+ .field("owner", &completion.owner)
.finish_non_exhaustive(),
ServiceWorkerRuntimeCompletionKind::SyncEventCompleted { completion } => f
.debug_struct("ServiceWorkerRuntimeCompletion::SyncEventCompleted")
.field("event_id", &completion.event_id)
- .field("version_id", &completion.version_id)
- .field("run", &completion.run)
+ .field("owner", &completion.owner)
.field("tag", &completion.tag)
.finish_non_exhaustive(),
ServiceWorkerRuntimeCompletionKind::PeriodicSyncEventCompleted { completion } => f
.debug_struct("ServiceWorkerRuntimeCompletion::PeriodicSyncEventCompleted")
.field("event_id", &completion.event_id)
- .field("version_id", &completion.version_id)
- .field("run", &completion.run)
+ .field("owner", &completion.owner)
.field("tag", &completion.tag)
.finish_non_exhaustive(),
ServiceWorkerRuntimeCompletionKind::ShowNotificationRequested {
- request, run, ..
+ request,
+ source_host,
} => f
.debug_struct("ServiceWorkerRuntimeCompletion::ShowNotificationRequested")
.field("request_id", &request.request_id)
.field("registration_id", &request.registration_id)
.field("version_id", &request.version_id)
- .field("run", run)
+ .field("owner", &source_host.run_owner())
.finish_non_exhaustive(),
ServiceWorkerRuntimeCompletionKind::GetNotificationsRequested {
- request, run, ..
+ request,
+ source_host,
} => f
.debug_struct("ServiceWorkerRuntimeCompletion::GetNotificationsRequested")
.field("request_id", &request.request_id)
.field("registration_id", &request.registration_id)
.field("version_id", &request.version_id)
- .field("run", run)
+ .field("owner", &source_host.run_owner())
.finish_non_exhaustive(),
ServiceWorkerRuntimeCompletionKind::SyncRegistrationRequested {
- request, run, ..
+ request,
+ source_host,
} => f
.debug_struct("ServiceWorkerRuntimeCompletion::SyncRegistrationRequested")
.field("request_id", &request.request_id)
.field("registration_id", &request.registration_id)
.field("version_id", &request.version_id)
- .field("run", run)
+ .field("owner", &source_host.run_owner())
.field("tag", &request.tag)
.finish_non_exhaustive(),
- ServiceWorkerRuntimeCompletionKind::SyncGetTagsRequested { request, run, .. } => f
+ ServiceWorkerRuntimeCompletionKind::SyncGetTagsRequested {
+ request,
+ source_host,
+ } => f
.debug_struct("ServiceWorkerRuntimeCompletion::SyncGetTagsRequested")
.field("request_id", &request.request_id)
.field("registration_id", &request.registration_id)
.field("version_id", &request.version_id)
- .field("run", run)
+ .field("owner", &source_host.run_owner())
.finish_non_exhaustive(),
ServiceWorkerRuntimeCompletionKind::PeriodicSyncRegistrationRequested {
request,
- run,
- ..
+ source_host,
} => f
.debug_struct("ServiceWorkerRuntimeCompletion::PeriodicSyncRegistrationRequested")
.field("request_id", &request.request_id)
.field("registration_id", &request.registration_id)
.field("version_id", &request.version_id)
- .field("run", run)
+ .field("owner", &source_host.run_owner())
.field("tag", &request.tag)
.finish_non_exhaustive(),
ServiceWorkerRuntimeCompletionKind::PeriodicSyncGetTagsRequested {
request,
- run,
- ..
+ source_host,
} => f
.debug_struct("ServiceWorkerRuntimeCompletion::PeriodicSyncGetTagsRequested")
.field("request_id", &request.request_id)
.field("registration_id", &request.registration_id)
.field("version_id", &request.version_id)
- .field("run", run)
+ .field("owner", &source_host.run_owner())
.finish_non_exhaustive(),
ServiceWorkerRuntimeCompletionKind::PeriodicSyncUnregistrationRequested {
request,
- run,
- ..
+ source_host,
} => f
.debug_struct("ServiceWorkerRuntimeCompletion::PeriodicSyncUnregistrationRequested")
.field("request_id", &request.request_id)
.field("registration_id", &request.registration_id)
.field("version_id", &request.version_id)
- .field("run", run)
+ .field("owner", &source_host.run_owner())
.field("tag", &request.tag)
.finish_non_exhaustive(),
- ServiceWorkerRuntimeCompletionKind::CloseNotificationRequested { request, run } => f
+ ServiceWorkerRuntimeCompletionKind::CloseNotificationRequested { request, owner } => f
.debug_struct("ServiceWorkerRuntimeCompletion::CloseNotificationRequested")
.field("registration_id", &request.registration_id)
.field("version_id", &request.version_id)
.field("notification_id", &request.notification_id)
- .field("run", run)
+ .field("owner", owner)
.finish_non_exhaustive(),
ServiceWorkerRuntimeCompletionKind::ClientMessage { message } => f
.debug_struct("ServiceWorkerRuntimeCompletion::ClientMessage")
@@ -1030,18 +993,18 @@ impl fmt::Debug for ServiceWorkerRuntimeCompletion {
.field("source_version_id", &message.source_version_id)
.field("target_version_id", &message.target_version_id)
.finish_non_exhaustive(),
- ServiceWorkerRuntimeCompletionKind::ClientQuery { query, run } => f
+ ServiceWorkerRuntimeCompletionKind::ClientQuery { query, owner } => f
.debug_struct("ServiceWorkerRuntimeCompletion::ClientQuery")
.field("request_id", &query.request_id)
.field("registration_id", &query.registration_id)
.field("version_id", &query.version_id)
- .field("run", run)
+ .field("owner", owner)
.finish_non_exhaustive(),
- ServiceWorkerRuntimeCompletionKind::ClientNavigate { navigate, run } => f
+ ServiceWorkerRuntimeCompletionKind::ClientNavigate { navigate, owner } => f
.debug_struct("ServiceWorkerRuntimeCompletion::ClientNavigate")
.field("request_id", &navigate.request_id)
.field("source_version_id", &navigate.source_version_id)
- .field("run", run)
+ .field("owner", owner)
.field("target_client_id", &navigate.target_client_id)
.finish_non_exhaustive(),
ServiceWorkerRuntimeCompletionKind::ClientNavigateCompleted { completion } => f
@@ -1049,11 +1012,11 @@ impl fmt::Debug for ServiceWorkerRuntimeCompletion {
.field("request_id", &completion.request_id)
.field("source_version_id", &completion.source_version_id)
.finish_non_exhaustive(),
- ServiceWorkerRuntimeCompletionKind::ClientFocus { focus, run } => f
+ ServiceWorkerRuntimeCompletionKind::ClientFocus { focus, owner } => f
.debug_struct("ServiceWorkerRuntimeCompletion::ClientFocus")
.field("request_id", &focus.request_id)
.field("source_version_id", &focus.source_version_id)
- .field("run", run)
+ .field("owner", owner)
.field("target_client_id", &focus.target_client_id)
.finish_non_exhaustive(),
ServiceWorkerRuntimeCompletionKind::ClientFocusCompleted { completion } => f
@@ -1061,48 +1024,50 @@ impl fmt::Debug for ServiceWorkerRuntimeCompletion {
.field("request_id", &completion.request_id)
.field("source_version_id", &completion.source_version_id)
.finish_non_exhaustive(),
- ServiceWorkerRuntimeCompletionKind::ClientsOpenWindow { open_window, run } => f
+ ServiceWorkerRuntimeCompletionKind::ClientsOpenWindow { open_window, owner } => f
.debug_struct("ServiceWorkerRuntimeCompletion::ClientsOpenWindow")
.field("request_id", &open_window.request_id)
.field("source_version_id", &open_window.source_version_id)
- .field("run", run)
+ .field("owner", owner)
.finish_non_exhaustive(),
ServiceWorkerRuntimeCompletionKind::ClientsOpenWindowCompleted { completion } => f
.debug_struct("ServiceWorkerRuntimeCompletion::ClientsOpenWindowCompleted")
.field("request_id", &completion.request_id)
.field("source_version_id", &completion.source_version_id)
.finish_non_exhaustive(),
- ServiceWorkerRuntimeCompletionKind::PushSubscribeRequested { request, run, .. } => f
+ ServiceWorkerRuntimeCompletionKind::PushSubscribeRequested {
+ request,
+ source_host,
+ } => f
.debug_struct("ServiceWorkerRuntimeCompletion::PushSubscribeRequested")
.field("request_id", &request.request_id)
.field("registration_id", &request.registration_id)
.field("version_id", &request.version_id)
- .field("run", run)
+ .field("owner", &source_host.run_owner())
.finish_non_exhaustive(),
ServiceWorkerRuntimeCompletionKind::PushGetSubscriptionRequested {
request,
- run,
- ..
+ source_host,
} => f
.debug_struct("ServiceWorkerRuntimeCompletion::PushGetSubscriptionRequested")
.field("request_id", &request.request_id)
.field("registration_id", &request.registration_id)
.field("version_id", &request.version_id)
- .field("run", run)
+ .field("owner", &source_host.run_owner())
.finish_non_exhaustive(),
ServiceWorkerRuntimeCompletionKind::PushUnsubscribeRequested {
- request, run, ..
+ request,
+ source_host,
} => f
.debug_struct("ServiceWorkerRuntimeCompletion::PushUnsubscribeRequested")
.field("request_id", &request.request_id)
.field("registration_id", &request.registration_id)
.field("version_id", &request.version_id)
- .field("run", run)
+ .field("owner", &source_host.run_owner())
.finish_non_exhaustive(),
ServiceWorkerRuntimeCompletionKind::IdleTimeout(timeout) => f
.debug_struct("ServiceWorkerRuntimeCompletion::IdleTimeout")
- .field("version_id", &timeout.version_id)
- .field("run", &timeout.run)
+ .field("owner", &timeout.owner)
.finish_non_exhaustive(),
ServiceWorkerRuntimeCompletionKind::SkipWaitingRequested {
registration_id,
diff --git a/moli-renderer-v8/src/service_worker_runtime/state.rs b/moli-renderer-v8/src/service_worker_runtime/state.rs
index 24a3c2d53..13c1e334b 100644
--- a/moli-renderer-v8/src/service_worker_runtime/state.rs
+++ b/moli-renderer-v8/src/service_worker_runtime/state.rs
@@ -58,6 +58,7 @@ use super::{
owner_wake::ServiceWorkerOwnerWake,
registration::ServiceWorkerRegistration,
resource_store::{ServiceWorkerStoredRegistration, SharedServiceWorkerResourceStore},
+ run_owner::ServiceWorkerRunOwner,
script_loading::{LoadedServiceWorkerScript, ServiceWorkerScriptUpdateCheckParams},
service_lane::ServiceWorkerServiceLane,
snapshots::ServiceWorkerRegistrationSnapshot,
@@ -760,8 +761,7 @@ pub(super) enum ServiceWorkerPeriodicSyncStart {
pub(super) struct ServiceWorkerFetchJob {
pub(super) internal_id: u64,
- pub(super) version_id: ServiceWorkerVersionId,
- pub(super) run: Option<RendererServiceWorkerRunIdentity>,
+ pub(super) owner: Option<ServiceWorkerRunOwner>,
pub(super) request_url: Url,
pub(super) request_method: String,
pub(super) request_headers: Vec<(String, String)>,
@@ -792,18 +792,26 @@ pub(super) struct ServiceWorkerFetchJob {
}
impl ServiceWorkerFetchJob {
- pub(super) fn bind_to_run(&mut self, run: RendererServiceWorkerRunIdentity) {
- self.run = Some(run);
+ pub(super) fn bind_to_owner(&mut self, owner: ServiceWorkerRunOwner) {
+ self.owner = Some(owner);
}
- pub(super) fn is_bound_to_run(&self, run: &RendererServiceWorkerRunIdentity) -> bool {
- self.run.as_ref() == Some(run)
+ pub(super) fn owner(&self) -> &ServiceWorkerRunOwner {
+ self.owner
+ .as_ref()
+ .expect("pending ServiceWorker fetch jobs must have an exact run owner")
+ }
+
+ pub(super) fn version_id(&self) -> ServiceWorkerVersionId {
+ self.owner().version_id()
+ }
+
+ pub(super) fn is_bound_to_owner(&self, owner: &ServiceWorkerRunOwner) -> bool {
+ self.owner.as_ref() == Some(owner)
}
pub(super) fn run_identity(&self) -> &RendererServiceWorkerRunIdentity {
- self.run
- .as_ref()
- .expect("pending ServiceWorker fetch jobs must be bound to an exact run")
+ self.owner().run_identity()
}
pub(super) fn cancel_pending_navigation_preload(&mut self) {
@@ -952,7 +960,6 @@ impl ServiceWorkerClientEndpoint {
pub(super) struct ServiceWorkerClient {
pub(super) id: ServiceWorkerClientId,
pub(super) exposed_id: String,
- pub(super) exposed_id_generation: u64,
pub(super) creation_url: Url,
pub(super) document_url: Url,
pub(super) client_type: ServiceWorkerClientType,
diff --git a/moli-renderer-v8/src/service_worker_runtime/version.rs b/moli-renderer-v8/src/service_worker_runtime/version.rs
index 71704df93..b70790e9c 100644
--- a/moli-renderer-v8/src/service_worker_runtime/version.rs
+++ b/moli-renderer-v8/src/service_worker_runtime/version.rs
@@ -19,13 +19,13 @@ use super::{
host::SharedRendererServiceWorkerHost,
ids::{ServiceWorkerRegistrationId, ServiceWorkerVersionId},
jobs::ServiceWorkerVersionLaunchConfig,
+ run_owner::ServiceWorkerRunOwner,
script_loading::ServiceWorkerScriptResource,
};
#[derive(Clone, Debug)]
pub(super) struct ServiceWorkerIdleTimeout {
- pub(super) version_id: ServiceWorkerVersionId,
- pub(super) run: RendererServiceWorkerRunIdentity,
+ pub(super) owner: ServiceWorkerRunOwner,
pub(super) token: ServiceWorkerIdleTimeoutToken,
}
@@ -72,6 +72,17 @@ pub(super) struct ServiceWorkerVersion {
pub(super) last_start_error: Option<String>,
}
+impl ServiceWorkerVersion {
+ pub(super) fn run_owner(&self) -> ServiceWorkerRunOwner {
+ ServiceWorkerRunOwner::new(self.id, self.run.clone())
+ }
+
+ pub(super) fn replace_run_owner(&mut self) -> ServiceWorkerRunOwner {
+ self.run = RendererServiceWorkerRunIdentity::fresh();
+ self.run_owner()
+ }
+}
+
#[derive(Clone, Debug)]
pub(super) enum ServiceWorkerPendingStartEvent {
Fetch(ServiceWorkerFetchEvent),
diff --git a/moli-renderer-v8/src/worker/global_scope/mod.rs b/moli-renderer-v8/src/worker/global_scope/mod.rs
index f95fa177e..dc76e7cad 100644
--- a/moli-renderer-v8/src/worker/global_scope/mod.rs
+++ b/moli-renderer-v8/src/worker/global_scope/mod.rs
@@ -1364,8 +1364,7 @@ impl PendingServiceWorkerFetchEvent {
}
pub(super) struct PendingServiceWorkerNavigationPreload {
- pub(super) version_id: crate::service_worker_runtime::ServiceWorkerVersionId,
- pub(super) run: crate::runtime::RendererServiceWorkerRunIdentity,
+ pub(super) owner: crate::service_worker_runtime::ServiceWorkerRunOwner,
pub(super) _promise: v8::Global<v8::Promise>,
pub(super) resolver: Option<v8::Global<v8::PromiseResolver>>,
pub(super) body_source_id: Option<NetworkBodySourceId>,
diff --git a/moli-renderer-v8/src/worker/thread/dispatch.rs b/moli-renderer-v8/src/worker/thread/dispatch.rs
index 14fd44736..809ba7210 100644
--- a/moli-renderer-v8/src/worker/thread/dispatch.rs
+++ b/moli-renderer-v8/src/worker/thread/dispatch.rs
@@ -1281,8 +1281,7 @@ fn dispatch_service_worker_lifecycle_event_in_context<'s>(
PendingServiceWorkerLifecycleEvent {
completion: ServiceWorkerLifecycleCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
kind: event.kind,
result: Ok(()),
},
@@ -1350,8 +1349,7 @@ fn dispatch_service_worker_fetch_event_in_context<'s>(
let _ = parent_tx.send(WorkerToParentMessage::ServiceWorkerFetchCompleted(
ServiceWorkerFetchCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
result: ServiceWorkerFetchResult::Failure(
"failed to construct service worker FetchEvent request".to_owned(),
),
@@ -1363,8 +1361,7 @@ fn dispatch_service_worker_fetch_event_in_context<'s>(
let _ = parent_tx.send(WorkerToParentMessage::ServiceWorkerFetchCompleted(
ServiceWorkerFetchCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
result: ServiceWorkerFetchResult::Failure(
"failed to construct service worker FetchEvent.handled promise".to_owned(),
),
@@ -1379,8 +1376,7 @@ fn dispatch_service_worker_fetch_event_in_context<'s>(
let _ = parent_tx.send(WorkerToParentMessage::ServiceWorkerFetchCompleted(
ServiceWorkerFetchCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
result: ServiceWorkerFetchResult::Failure(
"failed to construct service worker FetchEvent.preloadResponse promise"
.to_owned(),
@@ -1398,8 +1394,7 @@ fn dispatch_service_worker_fetch_event_in_context<'s>(
let mut pending = PendingServiceWorkerFetchEvent::fallback(
ServiceWorkerFetchCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
result: ServiceWorkerFetchResult::Fallback,
},
event.request.request_mode,
@@ -1410,8 +1405,7 @@ fn dispatch_service_worker_fetch_event_in_context<'s>(
state.pending_service_worker_navigation_preloads.insert(
event.event_id,
PendingServiceWorkerNavigationPreload {
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
_promise: v8::Global::new(scope, preload_response),
resolver: Some(v8::Global::new(scope, preload_response_resolver)),
body_source_id: None,
@@ -1500,8 +1494,7 @@ fn dispatch_service_worker_message_event_in_context<'s>(
PendingServiceWorkerMessageEvent {
completion: ServiceWorkerMessageCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
result: Ok(()),
},
pending_wait_until_count: 0,
@@ -1571,8 +1564,7 @@ fn dispatch_service_worker_notification_event_in_context<'s>(
let _ = parent_tx.send(WorkerToParentMessage::ServiceWorkerNotificationCompleted(
ServiceWorkerNotificationCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
result: Err("failed to construct service worker notification event".to_owned()),
},
));
@@ -1588,8 +1580,7 @@ fn dispatch_service_worker_notification_event_in_context<'s>(
PendingServiceWorkerNotificationEvent {
completion: ServiceWorkerNotificationCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
result: Ok(()),
},
pending_wait_until_count: 0,
@@ -1660,8 +1651,7 @@ fn dispatch_service_worker_push_event_in_context<'s>(
let _ = parent_tx.send(WorkerToParentMessage::ServiceWorkerPushCompleted(
ServiceWorkerPushCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
result: Err("failed to construct service worker push event".to_owned()),
},
));
@@ -1676,8 +1666,7 @@ fn dispatch_service_worker_push_event_in_context<'s>(
PendingServiceWorkerPushEvent {
completion: ServiceWorkerPushCompletion {
event_id: event.event_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
result: Ok(()),
},
pending_wait_until_count: 0,
@@ -1738,8 +1727,7 @@ fn dispatch_service_worker_sync_event_in_context<'s>(
ServiceWorkerSyncCompletion {
event_id: event.event_id,
registration_id: event.registration_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
tag: event.tag,
result: Err("failed to construct service worker sync event".to_owned()),
},
@@ -1756,8 +1744,7 @@ fn dispatch_service_worker_sync_event_in_context<'s>(
completion: ServiceWorkerSyncCompletion {
event_id: event.event_id,
registration_id: event.registration_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
tag: event.tag.clone(),
result: Ok(()),
},
@@ -1819,8 +1806,7 @@ fn dispatch_service_worker_periodic_sync_event_in_context<'s>(
ServiceWorkerPeriodicSyncCompletion {
event_id: event.event_id,
registration_id: event.registration_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
tag: event.tag,
result: Err("failed to construct service worker periodic sync event".to_owned()),
},
@@ -1837,8 +1823,7 @@ fn dispatch_service_worker_periodic_sync_event_in_context<'s>(
completion: ServiceWorkerPeriodicSyncCompletion {
event_id: event.event_id,
registration_id: event.registration_id,
- version_id: event.version_id,
- run: event.run.clone(),
+ owner: event.owner.clone(),
tag: event.tag.clone(),
result: Ok(()),
},
@@ -3395,8 +3380,8 @@ fn send_service_worker_fetch_stream_started(
.map(|pending| {
(
state.parent_tx.clone(),
- pending.completion.version_id,
- pending.completion.run.clone(),
+ pending.completion.owner.version_id(),
+ pending.completion.owner.cloned_run_identity(),
)
})
}) else {
@@ -3405,8 +3390,7 @@ fn send_service_worker_fetch_stream_started(
let _ = parent_tx.send(WorkerToParentMessage::ServiceWorkerFetchStreamStarted(
ServiceWorkerFetchStreamStarted {
event_id,
- version_id,
- run,
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(version_id, run),
body_source_id,
response_head,
},
@@ -3552,10 +3536,7 @@ fn start_service_worker_navigation_preload_response_in_context(
else {
return;
};
- if preload.version_id != started.version_id
- || preload.run != started.run
- || preload.body_source_id.is_some()
- {
+ if preload.owner != started.owner || preload.body_source_id.is_some() {
return;
}
preload.body_source_id = Some(started.body_source_id);
@@ -3666,10 +3647,7 @@ fn service_worker_navigation_preload_finish_matches_pending_event(
else {
return false;
};
- if preload.version_id != finished.version_id
- || preload.run != finished.run
- || preload.body_source_id != Some(finished.body_source_id)
- {
+ if preload.owner != finished.owner || preload.body_source_id != Some(finished.body_source_id) {
return false;
}
true
@@ -3701,7 +3679,7 @@ fn fail_service_worker_navigation_preload_response_in_context(
else {
return;
};
- if preload.version_id != failure.version_id || preload.run != failure.run {
+ if preload.owner != failure.owner {
return;
}
preload.resolver.take()
diff --git a/moli-renderer-v8/src/worker/thread/tests/lifecycle.rs b/moli-renderer-v8/src/worker/thread/tests/lifecycle.rs
index 52b6d64fa..7ba4c1be6 100644
--- a/moli-renderer-v8/src/worker/thread/tests/lifecycle.rs
+++ b/moli-renderer-v8/src/worker/thread/tests/lifecycle.rs
@@ -614,7 +614,7 @@ async fn service_worker_install_wait_until_resolution_completes_lifecycle_event(
ServiceWorkerEventId::from_u64_for_worker(1)
);
assert_eq!(
- completion.version_id,
+ completion.owner.version_id(),
ServiceWorkerVersionId::from_u64_for_test(1)
);
assert_eq!(completion.kind, ServiceWorkerLifecycleEventKind::Install);
@@ -685,8 +685,10 @@ async fn service_worker_fetch_event_preload_response_resolves_network_response()
request.request_mode = moli_fetch::RequestMode::Navigate;
handle.dispatch_service_worker_fetch_event(ServiceWorkerFetchEvent {
event_id,
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: run.clone(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ run.clone(),
+ ),
request,
navigation_preload_sent: true,
});
@@ -694,8 +696,10 @@ async fn service_worker_fetch_event_preload_response_resolves_network_response()
handle.start_service_worker_navigation_preload_response(
ServiceWorkerNavigationPreloadResponseStarted {
event_id,
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: run.clone(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ run.clone(),
+ ),
request_url,
request_mode: moli_fetch::RequestMode::Navigate,
body_source_id,
@@ -728,8 +732,10 @@ async fn service_worker_fetch_event_preload_response_resolves_network_response()
handle.finish_service_worker_navigation_preload_stream(
ServiceWorkerNavigationPreloadStreamFinished {
event_id,
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: run.clone(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ run.clone(),
+ ),
body_source_id,
result: Ok(()),
},
@@ -793,8 +799,10 @@ async fn service_worker_fetch_event_preload_response_opaqueredirect_exposes_requ
request.request_mode = moli_fetch::RequestMode::Navigate;
handle.dispatch_service_worker_fetch_event(ServiceWorkerFetchEvent {
event_id,
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: run.clone(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ run.clone(),
+ ),
request,
navigation_preload_sent: true,
});
@@ -802,8 +810,10 @@ async fn service_worker_fetch_event_preload_response_opaqueredirect_exposes_requ
handle.start_service_worker_navigation_preload_response(
ServiceWorkerNavigationPreloadResponseStarted {
event_id,
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: run.clone(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ run.clone(),
+ ),
request_url: request_url.clone(),
request_mode: moli_fetch::RequestMode::Navigate,
body_source_id,
@@ -819,8 +829,10 @@ async fn service_worker_fetch_event_preload_response_opaqueredirect_exposes_requ
handle.finish_service_worker_navigation_preload_stream(
ServiceWorkerNavigationPreloadStreamFinished {
event_id,
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: run.clone(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ run.clone(),
+ ),
body_source_id,
result: Ok(()),
},
@@ -879,15 +891,19 @@ async fn service_worker_fetch_event_preload_response_rejects_before_response() {
request.request_mode = moli_fetch::RequestMode::Navigate;
handle.dispatch_service_worker_fetch_event(ServiceWorkerFetchEvent {
event_id,
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: run.clone(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ run.clone(),
+ ),
request,
navigation_preload_sent: true,
});
handle.fail_service_worker_navigation_preload(ServiceWorkerNavigationPreloadFailure {
event_id,
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: run.clone(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ run.clone(),
+ ),
message: "navigation preload failed".to_owned(),
});
@@ -953,8 +969,10 @@ async fn service_worker_fetch_event_preload_response_body_errors_after_response(
request.request_mode = moli_fetch::RequestMode::Navigate;
handle.dispatch_service_worker_fetch_event(ServiceWorkerFetchEvent {
event_id,
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: run.clone(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ run.clone(),
+ ),
request,
navigation_preload_sent: true,
});
@@ -962,8 +980,10 @@ async fn service_worker_fetch_event_preload_response_body_errors_after_response(
handle.start_service_worker_navigation_preload_response(
ServiceWorkerNavigationPreloadResponseStarted {
event_id,
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: run.clone(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ run.clone(),
+ ),
request_url,
request_mode: moli_fetch::RequestMode::Navigate,
body_source_id,
@@ -989,8 +1009,10 @@ async fn service_worker_fetch_event_preload_response_body_errors_after_response(
handle.finish_service_worker_navigation_preload_stream(
ServiceWorkerNavigationPreloadStreamFinished {
event_id,
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: run.clone(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ run.clone(),
+ ),
body_source_id,
result: Err("navigation preload stream failed".to_owned()),
},
@@ -1060,8 +1082,10 @@ async fn service_worker_fetch_event_preload_response_body_completes_after_fetch_
request.request_mode = moli_fetch::RequestMode::Navigate;
handle.dispatch_service_worker_fetch_event(ServiceWorkerFetchEvent {
event_id,
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: run.clone(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ run.clone(),
+ ),
request,
navigation_preload_sent: true,
});
@@ -1069,8 +1093,10 @@ async fn service_worker_fetch_event_preload_response_body_completes_after_fetch_
handle.start_service_worker_navigation_preload_response(
ServiceWorkerNavigationPreloadResponseStarted {
event_id,
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: run.clone(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ run.clone(),
+ ),
request_url,
request_mode: moli_fetch::RequestMode::Navigate,
body_source_id,
@@ -1128,8 +1154,10 @@ async fn service_worker_fetch_event_preload_response_body_completes_after_fetch_
handle.finish_service_worker_navigation_preload_stream(
ServiceWorkerNavigationPreloadStreamFinished {
event_id,
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: run.clone(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ run.clone(),
+ ),
body_source_id,
result: Ok(()),
},
@@ -1239,8 +1267,10 @@ async fn dispatch_service_worker_lifecycle_event_and_console_for_test(
) -> (ServiceWorkerLifecycleCompletion, String) {
handle.dispatch_service_worker_lifecycle_event(ServiceWorkerLifecycleEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(event_id),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
kind,
});
@@ -1276,8 +1306,10 @@ async fn dispatch_service_worker_message_event_and_console_for_test(
) -> (ServiceWorkerMessageCompletion, String) {
handle.dispatch_service_worker_message_event(ServiceWorkerMessageEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(event_id),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
source_client_id: None,
source_client_url: None,
source_client_snapshot: None,
@@ -1702,7 +1734,7 @@ async fn service_worker_fetch_without_respond_with_falls_back() {
ServiceWorkerEventId::from_u64_for_worker(7)
);
assert_eq!(
- completion.version_id,
+ completion.owner.version_id(),
ServiceWorkerVersionId::from_u64_for_test(1)
);
assert!(matches!(
@@ -1761,8 +1793,10 @@ async fn dispatch_service_worker_fetch_event_and_handled_console_for_test(
) -> (ServiceWorkerFetchCompletion, String) {
handle.dispatch_service_worker_fetch_event(ServiceWorkerFetchEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(event_id),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
request,
navigation_preload_sent: false,
});
@@ -1987,8 +2021,10 @@ async fn service_worker_fetch_handler_throw_without_respond_with_still_falls_bac
let event_id = ServiceWorkerEventId::from_u64_for_worker(59);
handle.dispatch_service_worker_fetch_event(ServiceWorkerFetchEvent {
event_id,
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
request: service_worker_fetch_request_for_test(),
navigation_preload_sent: false,
});
@@ -2129,8 +2165,10 @@ async fn service_worker_fetch_respond_with_readable_stream_body_posts_stream_chu
let run = crate::runtime::RendererServiceWorkerRunIdentity::fresh();
handle.dispatch_service_worker_fetch_event(ServiceWorkerFetchEvent {
event_id,
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: run.clone(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ run.clone(),
+ ),
request: service_worker_fetch_request_for_test(),
navigation_preload_sent: false,
});
@@ -2146,10 +2184,10 @@ async fn service_worker_fetch_respond_with_readable_stream_body_posts_stream_chu
WorkerToParentMessage::ServiceWorkerFetchStreamStarted(started) => {
assert_eq!(started.event_id, event_id);
assert_eq!(
- started.version_id,
+ started.owner.version_id(),
ServiceWorkerVersionId::from_u64_for_test(1)
);
- assert_eq!(started.run, run);
+ assert_eq!(started.owner.run_identity(), &run);
assert_eq!(started.response_head.response_type, "default");
assert_eq!(started.response_head.status, 202);
assert!(
@@ -2244,8 +2282,10 @@ async fn service_worker_fetch_respond_with_readable_stream_error_fails_open_stre
let event_id = ServiceWorkerEventId::from_u64_for_worker(21);
handle.dispatch_service_worker_fetch_event(ServiceWorkerFetchEvent {
event_id,
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
request: service_worker_fetch_request_for_test(),
navigation_preload_sent: false,
});
@@ -2316,8 +2356,10 @@ async fn service_worker_fetch_respond_with_invalid_readable_stream_chunk_fails_o
let event_id = ServiceWorkerEventId::from_u64_for_worker(22);
handle.dispatch_service_worker_fetch_event(ServiceWorkerFetchEvent {
event_id,
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
request: service_worker_fetch_request_for_test(),
navigation_preload_sent: false,
});
@@ -2388,8 +2430,10 @@ async fn service_worker_fetch_stream_cancel_from_parent_notifies_source_and_fail
let event_id = ServiceWorkerEventId::from_u64_for_worker(20);
handle.dispatch_service_worker_fetch_event(ServiceWorkerFetchEvent {
event_id,
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
request: service_worker_fetch_request_for_test(),
navigation_preload_sent: false,
});
@@ -2886,8 +2930,10 @@ async fn service_worker_fetch_event_request_signal_aborts_with_parent_reason() {
let event_id = ServiceWorkerEventId::from_u64_for_worker(27);
handle.dispatch_service_worker_fetch_event(ServiceWorkerFetchEvent {
event_id,
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
request: service_worker_fetch_request_for_test(),
navigation_preload_sent: false,
});
@@ -3098,8 +3144,10 @@ async fn service_worker_fetch_respond_with_keeps_response_when_handler_throws_af
let event_id = ServiceWorkerEventId::from_u64_for_worker(25);
handle.dispatch_service_worker_fetch_event(ServiceWorkerFetchEvent {
event_id,
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
request: service_worker_fetch_request_for_test(),
navigation_preload_sent: false,
});
@@ -3286,7 +3334,7 @@ async fn service_worker_message_event_receives_structured_data() {
ServiceWorkerEventId::from_u64_for_worker(20)
);
assert_eq!(
- completion.version_id,
+ completion.owner.version_id(),
ServiceWorkerVersionId::from_u64_for_test(1)
);
assert_eq!(completion.result, Ok(()));
@@ -3505,8 +3553,10 @@ async fn service_worker_message_event_source_uses_client_snapshot() {
&mut handle,
ServiceWorkerMessageEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(21),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
source_client_id: Some(source_client_id),
source_client_url: Some(source_client_url.clone()),
source_client_snapshot: Some(
@@ -3576,8 +3626,10 @@ async fn service_worker_message_event_source_uses_service_worker_snapshot() {
&mut handle,
ServiceWorkerMessageEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(22),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
source_client_id: None,
source_client_url: None,
source_client_snapshot: None,
@@ -3673,8 +3725,10 @@ async fn service_worker_messageerror_dispatches_when_wasm_module_sender_origin_m
&mut handle,
ServiceWorkerMessageEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(24),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
source_client_id: None,
source_client_url: None,
source_client_snapshot: None,
@@ -3919,8 +3973,10 @@ async fn service_worker_global_scope_handler_attributes_dispatch_functional_even
event_id: ServiceWorkerEventId::from_u64_for_worker(45),
kind: ServiceWorkerNotificationEventKind::Click,
registration_id: ServiceWorkerRegistrationId::from_u64_for_test(1),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
notification_id: 1,
title: "click-title".to_owned(),
tag: String::new(),
@@ -3944,8 +4000,10 @@ async fn service_worker_global_scope_handler_attributes_dispatch_functional_even
event_id: ServiceWorkerEventId::from_u64_for_worker(46),
kind: ServiceWorkerNotificationEventKind::Close,
registration_id: ServiceWorkerRegistrationId::from_u64_for_test(1),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
notification_id: 2,
title: "close-title".to_owned(),
tag: String::new(),
@@ -4133,8 +4191,10 @@ async fn service_worker_skip_waiting_posts_runtime_request() {
);
handle.dispatch_service_worker_lifecycle_event(ServiceWorkerLifecycleEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(5),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
kind: ServiceWorkerLifecycleEventKind::Install,
});
@@ -4221,8 +4281,10 @@ async fn service_worker_clients_claim_posts_runtime_request() {
);
handle.dispatch_service_worker_lifecycle_event(ServiceWorkerLifecycleEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(6),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
kind: ServiceWorkerLifecycleEventKind::Activate,
});
@@ -4402,8 +4464,10 @@ async fn service_worker_clients_match_all_and_get_resolve_from_parent_query_resu
);
handle.dispatch_service_worker_lifecycle_event(ServiceWorkerLifecycleEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(30),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
kind: ServiceWorkerLifecycleEventKind::Install,
});
@@ -4614,8 +4678,10 @@ async fn service_worker_worker_client_query_builds_base_client_object() {
);
handle.dispatch_service_worker_lifecycle_event(ServiceWorkerLifecycleEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(31),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
kind: ServiceWorkerLifecycleEventKind::Install,
});
@@ -4752,8 +4818,10 @@ self.addEventListener("message", event => {
handle.dispatch_service_worker_message_event(ServiceWorkerMessageEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(31),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
source_client_id: None,
source_client_url: None,
source_client_snapshot: None,
@@ -4921,8 +4989,10 @@ self.addEventListener("message", event => {
handle.dispatch_service_worker_message_event(ServiceWorkerMessageEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(32),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
source_client_id: None,
source_client_url: None,
source_client_snapshot: None,
@@ -5108,8 +5178,10 @@ self.addEventListener("message", event => {
handle.dispatch_service_worker_message_event(ServiceWorkerMessageEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(33),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
source_client_id: None,
source_client_url: None,
source_client_snapshot: None,
@@ -5269,8 +5341,10 @@ self.addEventListener("message", event => {
handle.dispatch_service_worker_message_event(ServiceWorkerMessageEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(32),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
source_client_id: None,
source_client_url: None,
source_client_snapshot: None,
@@ -5435,8 +5509,10 @@ self.addEventListener("message", event => {
handle.dispatch_service_worker_message_event(ServiceWorkerMessageEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(32),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
source_client_id: None,
source_client_url: None,
source_client_snapshot: None,
@@ -5509,8 +5585,10 @@ self.addEventListener("message", event => {
);
handle.dispatch_service_worker_message_event(ServiceWorkerMessageEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(33),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
source_client_id: None,
source_client_url: None,
source_client_snapshot: None,
@@ -5600,8 +5678,10 @@ self.addEventListener("message", event => {
handle.dispatch_service_worker_message_event(ServiceWorkerMessageEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(33),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
source_client_id: None,
source_client_url: None,
source_client_snapshot: None,
@@ -5685,8 +5765,10 @@ self.addEventListener("message", event => {
handle.dispatch_service_worker_message_event(ServiceWorkerMessageEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(34),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
source_client_id: None,
source_client_url: None,
source_client_snapshot: None,
@@ -5821,8 +5903,10 @@ self.addEventListener("message", event => {
handle.dispatch_service_worker_message_event(ServiceWorkerMessageEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(35),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
source_client_id: None,
source_client_url: None,
source_client_snapshot: None,
@@ -5950,8 +6034,10 @@ self.addEventListener("message", event => {
handle.dispatch_service_worker_message_event(ServiceWorkerMessageEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(36),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
source_client_id: None,
source_client_url: None,
source_client_snapshot: None,
@@ -6068,8 +6154,10 @@ self.addEventListener("message", event => {
handle.dispatch_service_worker_message_event(ServiceWorkerMessageEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(136),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
source_client_id: Some(crate::runtime::ServiceWorkerClientId::from_u64_for_test(1)),
source_client_url: Some(url::Url::parse("https://example.test/app/page.html").unwrap()),
source_client_snapshot: Some(
@@ -6142,8 +6230,10 @@ self.addEventListener("message", event => {
handle.dispatch_service_worker_message_event(ServiceWorkerMessageEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(137),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
source_client_id: Some(crate::runtime::ServiceWorkerClientId::from_u64_for_test(1)),
source_client_url: Some(url::Url::parse("https://example.test/app/page.html").unwrap()),
source_client_snapshot: Some(
@@ -6243,8 +6333,10 @@ self.addEventListener("message", event => {
handle.dispatch_service_worker_message_event(ServiceWorkerMessageEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(39),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
source_client_id: None,
source_client_url: None,
source_client_snapshot: None,
@@ -6399,8 +6491,10 @@ self.addEventListener("message", event => {
handle.dispatch_service_worker_message_event(ServiceWorkerMessageEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(38),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
source_client_id: None,
source_client_url: None,
source_client_snapshot: None,
@@ -6487,8 +6581,10 @@ self.addEventListener("message", event => {
handle.dispatch_service_worker_message_event(ServiceWorkerMessageEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(40),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
source_client_id: None,
source_client_url: None,
source_client_snapshot: None,
@@ -6647,8 +6743,10 @@ self.addEventListener("message", event => {
handle.dispatch_service_worker_message_event(ServiceWorkerMessageEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(37),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
source_client_id: None,
source_client_url: None,
source_client_snapshot: None,
@@ -6870,8 +6968,10 @@ self.addEventListener("notificationclick", event => {
event_id: ServiceWorkerEventId::from_u64_for_worker(32),
kind: ServiceWorkerNotificationEventKind::Click,
registration_id: ServiceWorkerRegistrationId::from_u64_for_test(1),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
notification_id: 1,
title: "hello".to_owned(),
tag: String::new(),
@@ -7071,8 +7171,10 @@ self.addEventListener("notificationclose", event => {
event_id: ServiceWorkerEventId::from_u64_for_worker(33),
kind: ServiceWorkerNotificationEventKind::Close,
registration_id: ServiceWorkerRegistrationId::from_u64_for_test(1),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
notification_id: 2,
title: "bye".to_owned(),
tag: String::new(),
diff --git a/moli-renderer-v8/src/worker/thread/tests/mod.rs b/moli-renderer-v8/src/worker/thread/tests/mod.rs
index 15f64bfa1..513bedaaf 100644
--- a/moli-renderer-v8/src/worker/thread/tests/mod.rs
+++ b/moli-renderer-v8/src/worker/thread/tests/mod.rs
@@ -310,8 +310,10 @@ async fn dispatch_service_worker_lifecycle_event_for_test(
) -> ServiceWorkerLifecycleCompletion {
handle.dispatch_service_worker_lifecycle_event(ServiceWorkerLifecycleEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(event_id),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
kind,
});
loop {
@@ -405,8 +407,10 @@ async fn dispatch_service_worker_fetch_event_with_request_for_test(
) -> ServiceWorkerFetchCompletion {
handle.dispatch_service_worker_fetch_event(ServiceWorkerFetchEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(event_id),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
request,
navigation_preload_sent: false,
});
@@ -475,8 +479,10 @@ async fn dispatch_service_worker_message_event_for_test(
handle,
ServiceWorkerMessageEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(event_id),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
source_client_id: None,
source_client_url: None,
source_client_snapshot: None,
@@ -620,8 +626,10 @@ async fn dispatch_service_worker_push_event_for_test(
) -> ServiceWorkerPushCompletion {
handle.dispatch_service_worker_push_event(ServiceWorkerPushEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(event_id),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
data,
});
loop {
@@ -688,8 +696,10 @@ async fn dispatch_service_worker_sync_event_for_test(
handle.dispatch_service_worker_sync_event(ServiceWorkerSyncEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(event_id),
registration_id: ServiceWorkerRegistrationId::from_u64_for_test(1),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
tag: tag.to_owned(),
last_chance: false,
});
@@ -757,8 +767,10 @@ async fn dispatch_service_worker_periodic_sync_event_for_test(
handle.dispatch_service_worker_periodic_sync_event(ServiceWorkerPeriodicSyncEvent {
event_id: ServiceWorkerEventId::from_u64_for_worker(event_id),
registration_id: ServiceWorkerRegistrationId::from_u64_for_test(1),
- version_id: ServiceWorkerVersionId::from_u64_for_test(1),
- run: crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ owner: crate::service_worker_runtime::ServiceWorkerRunOwner::new(
+ ServiceWorkerVersionId::from_u64_for_test(1),
+ crate::runtime::RendererServiceWorkerRunIdentity::fresh(),
+ ),
tag: tag.to_owned(),
});
loop {