Name Description Size
moz.build 1537
PRemoteWorker.ipdl 1209
PRemoteWorkerController.ipdl Proxy protocol used by ServiceWorkerManager whose canonical state exists on the main thread to control/receive feedback from RemoteWorkers which are canonically controlled from the PBackground thread. Exclusively for use from the parent process main thread to the parent process PBackground thread. 1259
PRemoteWorkerNonLifeCycleOpController.ipdl 683
PRemoteWorkerService.ipdl 850
RemoteWorkerChild.cpp 30822
RemoteWorkerChild.h Background-managed "Worker Launcher"-thread-resident created via the RemoteWorkerManager to actually spawn the worker. Currently, the worker will be spawned from the main thread due to nsIPrincipal not being able to be created on background threads and other ownership invariants, most of which can be relaxed in the future. 6196
RemoteWorkerController.cpp static 18089
RemoteWorkerController.h Here's a graph about this remote workers are spawned. _________________________________ | ________________________________ | | | | | | Parent process | IPC | Creation of Process X | | PBackground thread | | | | | | | | [RemoteWorkerService::Init()] | | | | | | | | | | | | (1) | | [RemoteWorkerManager:: (2) | | | V | | RegisterActor()]<-------- [new RemoteWorkerServiceChild] | | | | | | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | |________________________________| | | | | new SharedWorker/ServiceWorker | | | | ^ | IPC | (3) | (4)| | | V | | | | [RemoteWorkerController:: | | | | Create(data)] | | | | (5) | | | V | | | [RemoteWorkerManager::Launch()] | | | | | IPC _____________________________ | | (6) | | | | | | | | Selected content process | | V | (7) | | | [SendPRemoteWorkerConstructor()]--------->[new RemoteWorkerChild()] | | | | | | | | | | (8) | | | | | | V | | | V | | [RemoteWorkerController-> | | | RemoteWorkerChild->Exec() | | | SetControllerActor()] | | |_____________________________| | (9) | | IPC | V | | | [RemoteWorkerObserver-> | | | CreationCompleted()] | | |_________________________________| | | 1. When a new process starts, it creates a RemoteWorkerService singleton. This service creates a new thread (Worker Launcher) and from there, it starts a PBackground RemoteWorkerServiceChild actor. 2. On the parent process, PBackground thread, RemoteWorkerServiceParent actors are registered into the RemoteWorkerManager service. 3. At some point, a SharedWorker or a ServiceWorker must be executed. RemoteWorkerController::Create() is used to start the launching. This method must be called on the parent process, on the PBackground thread. 4. RemoteWorkerController object is immediately returned to the caller. Any operation done with this controller object will be stored in a queue, until the launching is correctly executed. 5. RemoteWorkerManager has the list of active RemoteWorkerServiceParent actors. From them, it picks one. In case we don't have any content process to select, a new one is spawned. If this happens, the operation is suspended until a new RemoteWorkerServiceParent is registered. 6. RemoteWorkerServiceParent is used to create a RemoteWorkerParent. 7. RemoteWorkerChild is created on a selected process and it executes the WorkerPrivate. 8. The RemoteWorkerParent actor is passed to the RemoteWorkerController. 9. RemoteWorkerController now is ready to continue and it called RemoteWorkerObserver to inform that the operation is completed. In case there were pending operations, they are now executed. 11565
RemoteWorkerControllerChild.cpp 3936
RemoteWorkerControllerChild.h Parent-process main-thread proxy used by ServiceWorkerManager to control RemoteWorkerController instances on the parent-process PBackground thread. 2107
RemoteWorkerControllerParent.cpp random process ID 5847
RemoteWorkerControllerParent.h PBackground-resident proxy used by ServiceWorkerManager because canonical ServiceWorkerManager state exists on the parent process main thread but the RemoteWorkerController API is used from the parent process PBackground thread. 2681
RemoteWorkerManager.cpp 20712
RemoteWorkerManager.h PBackground instance that keeps tracks of RemoteWorkerServiceParent actors (1 per process, including the main process). Decides which RemoteWorkerServerParent to use internally via SelectTargetActor in order to select a BackgroundParent manager on which to create a RemoteWorkerParent. 4695
RemoteWorkerNonLifeCycleOpControllerChild.cpp static 3276
RemoteWorkerNonLifeCycleOpControllerChild.h 1734
RemoteWorkerNonLifeCycleOpControllerParent.cpp 1495
RemoteWorkerNonLifeCycleOpControllerParent.h 1216
RemoteWorkerOp.cpp 900
RemoteWorkerOp.h 3837
RemoteWorkerParent.cpp unused 3892
RemoteWorkerParent.h PBackground-managed parent actor that is mutually associated with a single RemoteWorkerController. Relays error/close events to the controller and in turns is told life-cycle events. 2091
RemoteWorkerService.cpp Block shutdown until the RemoteWorkers have shutdown so that we do not try and shutdown the RemoteWorkerService "Worker Launcher" thread until they have cleanly shutdown. Note that this shutdown blocker is not used to initiate shutdown of any of the workers directly; their shutdown is initiated from PBackground in the parent process. The shutdown blocker just exists to avoid races around shutting down the worker launcher thread after all of the workers have shutdown and torn down their actors. Currently, it should be the case that the ContentParent should want to keep the content processes alive until the RemoteWorkers have all reported their shutdown over IPC (on the "Worker Launcher" thread). So for an orderly content process shutdown that is waiting for there to no longer be a reason to keep the content process alive, this blocker should only hang around for a brief period of time, helping smooth out lifecycle edge cases. In the event the content process is trying to shutdown while the RemoteWorkers think they should still be alive, it's possible that this blocker could expose the relevant logic error in the parent process if no attempt is made to shutdown the RemoteWorker. ## Major Implementation Note: This is not actually an nsIAsyncShutdownClient Until https://bugzilla.mozilla.org/show_bug.cgi?id=1760855 provides us with a non-JS implementation of nsIAsyncShutdownService, this implementation actually uses event loop spinning. The patch on https://bugzilla.mozilla.org/show_bug.cgi?id=1775784 that changed us to use this hack can be reverted when the time is right. Event loop spinning is handled by `RemoteWorkerService::Observe` and it calls our exposed `ShouldBlockShutdown()` to know when to stop spinning. 12334
RemoteWorkerService.h Refcounted lifecycle helper; when its refcount goes to zero its destructor will call RemoteWorkerService::Shutdown() which will remove the shutdown blocker and shutdown the "Worker Launcher" thread. The RemoteWorkerService itself will hold a reference to this singleton which it will use to hand out additional refcounts to RemoteWorkerChild instances. When the shutdown blocker is notified that it's time to shutdown, the RemoteWorkerService's reference will be dropped. 5263
RemoteWorkerServiceChild.cpp 1264
RemoteWorkerServiceChild.h "Worker Launcher"-thread child actor created by the RemoteWorkerService to receive messages from the PBackground RemoteWorkerManager in the parent. 1542
RemoteWorkerServiceParent.cpp 2657
RemoteWorkerServiceParent.h PBackground-thread parent actor that registers with the PBackground RemoteWorkerManager and used to relay spawn requests. 1717
RemoteWorkerTypes.ipdlh 3920