Extension SW: Run all PendingTasks once a lazy context's worker is ready.
For running PendingTasks for a particular ContextId through
SWTQ::AddPendingTask(), call StartWorker* exactly once instead of calling it
each time for each AddPendingTask call. This has two advantages:
- We don't call StartWorker* more than once when we don't need to.
- Extension messaging subtly depends on running these tasks once. This is
because how LazyBackgroundTaskQueue behaves in terms of multiple pending
tasks and we need some sort of parity in SWTQ for future worker messaging
implementation.
Detailed changes:
- ServiceWorkerTaskQueue: Remove the queue for registration
(old |pending_tasks_|) and worker start (|waiting_did_start_worker_tasks_|)
and merge them to a single queue (|pending_tasks_). Run these tasks
once registration, service worker start (DidStartWorkerForScope) and
service worker loadstop (DidStartServiceWorkerContext) completes.
- IPC: Add thread_id and SW scope to DidStartServiceWorkerContext IPC
(loadstop), as PendingTasks that were pending after DidStartWorkerForScope
but before the SW context has seen loadstop can use these thread_id and
scope to build LazyContextTaskQueue::ContextInfo to run those tasks.
Previously we used to remember these two pieces of information in
WaitingDidStartWorkerTask. This also simplifies the queue in SWTQ.
- IPC: Add thread_id and SW scope to DidStopServiceWorkerContext IPC
to clean up the task containers on worker shutdown. This will also
be necessary for multiple worker support within extension in future.
Bug: 925927
Test: Service worker within extension internal change, no visible effect.
Change-Id: I06581f821550154ebca3ee6d9aa803953abf7d86
Reviewed-on: https://chromium-review.googlesource.com/c/1481580
Reviewed-by: Dominick Ng <[email protected]>
Reviewed-by: Devlin <[email protected]>
Commit-Queue: Istiaque Ahmed <[email protected]>
Cr-Commit-Position: refs/heads/master@{#636239}
diff --git a/extensions/renderer/worker_thread_dispatcher.cc b/extensions/renderer/worker_thread_dispatcher.cc
index 98605e0..de817f0 100644
--- a/extensions/renderer/worker_thread_dispatcher.cc
+++ b/extensions/renderer/worker_thread_dispatcher.cc
@@ -169,18 +169,26 @@
}
void WorkerThreadDispatcher::DidStartContext(
+ const GURL& service_worker_scope,
int64_t service_worker_version_id) {
ServiceWorkerData* data = g_data_tls.Pointer()->Get();
DCHECK_EQ(service_worker_version_id, data->service_worker_version_id());
+ const int thread_id = content::WorkerThread::GetCurrentId();
+ DCHECK_NE(thread_id, kMainThreadId);
Send(new ExtensionHostMsg_DidStartServiceWorkerContext(
- data->context()->GetExtensionID(), service_worker_version_id));
+ data->context()->GetExtensionID(), service_worker_scope,
+ service_worker_version_id, thread_id));
}
-void WorkerThreadDispatcher::DidStopContext(int64_t service_worker_version_id) {
+void WorkerThreadDispatcher::DidStopContext(const GURL& service_worker_scope,
+ int64_t service_worker_version_id) {
ServiceWorkerData* data = g_data_tls.Pointer()->Get();
+ const int thread_id = content::WorkerThread::GetCurrentId();
+ DCHECK_NE(thread_id, kMainThreadId);
DCHECK_EQ(service_worker_version_id, data->service_worker_version_id());
Send(new ExtensionHostMsg_DidStopServiceWorkerContext(
- data->context()->GetExtensionID(), service_worker_version_id));
+ data->context()->GetExtensionID(), service_worker_scope,
+ service_worker_version_id, thread_id));
}
void WorkerThreadDispatcher::RemoveWorkerData(