0

[ServiceWorker] ServiceWorkerContextObserverSynchronous::OnStartWorkerMessageSent

This method allows the extensions layer to get a notice that the
message to start a worker (`OnStartWorkerMessageSent`) has been sent.

This is needed to deterministically trigger a race condition with
`ResetURLLoaderFactories` in browsertests.

Design doc: http://go/defer-reset-url-loader-factories

Bug: 394523691
Change-Id: Ie43471f86d26c5c5478211bc0d82176b678b839a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6433846
Reviewed-by: Yoshisato Yanagisawa <yyanagisawa@chromium.org>
Commit-Queue: Andrea Orru <andreaorru@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1443867}
This commit is contained in:
Andrea Orru
2025-04-07 17:57:24 -07:00
committed by Chromium LUCI CQ
parent 5a04f93aa6
commit 202b13fdc2
5 changed files with 22 additions and 0 deletions

@ -1229,6 +1229,16 @@ void ServiceWorkerContextCore::OnControlleeNavigationCommitted(
version->version_id(), client_uuid, render_frame_host_id);
}
void ServiceWorkerContextCore::OnStartWorkerMessageSent(
ServiceWorkerVersion* version) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK_EQ(this, version->context().get());
for (auto& observer : sync_observer_list_->observers) {
observer.OnStartWorkerMessageSent(version->version_id(), version->scope());
}
}
void ServiceWorkerContextCore::OnRunningStateChanged(
ServiceWorkerVersion* version) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);

@ -367,6 +367,7 @@ class CONTENT_EXPORT ServiceWorkerContextCore
void OnNoControllees(ServiceWorkerVersion* version);
// ServiceWorkerVersion::Observer overrides.
void OnStartWorkerMessageSent(ServiceWorkerVersion* version) override;
void OnRunningStateChanged(ServiceWorkerVersion* version) override;
void OnVersionStateChanged(ServiceWorkerVersion* version) override;
void OnDevToolsRoutingIdChanged(ServiceWorkerVersion* version) override;

@ -1463,6 +1463,12 @@ void ServiceWorkerVersion::OnStarting() {
}
}
void ServiceWorkerVersion::OnStartWorkerMessageSent() {
for (auto& observer : observers_) {
observer.OnStartWorkerMessageSent(this);
}
}
void ServiceWorkerVersion::OnStarted(
blink::mojom::ServiceWorkerStartStatus start_status,
FetchHandlerType new_fetch_handler_type,

@ -180,6 +180,7 @@ class CONTENT_EXPORT ServiceWorkerVersion
class Observer {
public:
virtual void OnStartWorkerMessageSent(ServiceWorkerVersion* version) {}
virtual void OnRunningStateChanged(ServiceWorkerVersion* version) {}
virtual void OnVersionStateChanged(ServiceWorkerVersion* version) {}
virtual void OnDevToolsRoutingIdChanged(ServiceWorkerVersion* version) {}
@ -892,6 +893,7 @@ class CONTENT_EXPORT ServiceWorkerVersion
void OnScriptLoaded() override;
void OnProcessAllocated() override;
void OnStarting() override;
void OnStartWorkerMessageSent() override;
void OnStarted(blink::mojom::ServiceWorkerStartStatus status,
FetchHandlerType new_fetch_handler_type,
bool new_has_hid_event_handlers,

@ -93,6 +93,9 @@ using ServiceWorkerScriptExecutionCallback =
// synchronously with changes in //content.
class ServiceWorkerContextObserverSynchronous : public base::CheckedObserver {
public:
// Called after the message to start the service worker has been sent.
virtual void OnStartWorkerMessageSent(int64_t version_id, const GURL& scope) {
}
// Called when the service worker with id `version_id` will be stopped.
virtual void OnStopping(int64_t version_id,
const ServiceWorkerRunningInfo& worker_info) {}