tree: ccf41b2980aa08389f9855f988d9e108551cf0d6 [path history] [tgz]
  1. abstract_worker.cc
  2. abstract_worker.h
  3. abstract_worker.idl
  4. BUILD.gn
  5. dedicated_worker.cc
  6. dedicated_worker.h
  7. dedicated_worker_global_scope.cc
  8. dedicated_worker_global_scope.h
  9. dedicated_worker_global_scope.idl
  10. dedicated_worker_messaging_proxy.cc
  11. dedicated_worker_messaging_proxy.h
  12. dedicated_worker_object_proxy.cc
  13. dedicated_worker_object_proxy.h
  14. dedicated_worker_test.cc
  15. dedicated_worker_thread.cc
  16. dedicated_worker_thread.h
  17. global_scope_creation_params.cc
  18. global_scope_creation_params.h
  19. installed_scripts_manager.cc
  20. installed_scripts_manager.h
  21. main_thread_worklet_reporting_proxy.cc
  22. main_thread_worklet_reporting_proxy.h
  23. main_thread_worklet_test.cc
  24. OWNERS
  25. parent_execution_context_task_runners.cc
  26. parent_execution_context_task_runners.h
  27. README.md
  28. shared_worker.cc
  29. shared_worker.h
  30. shared_worker.idl
  31. shared_worker_client.cc
  32. shared_worker_client.h
  33. shared_worker_client_holder.cc
  34. shared_worker_client_holder.h
  35. shared_worker_content_settings_proxy.cc
  36. shared_worker_content_settings_proxy.h
  37. shared_worker_global_scope.cc
  38. shared_worker_global_scope.h
  39. shared_worker_global_scope.idl
  40. shared_worker_reporting_proxy.cc
  41. shared_worker_reporting_proxy.h
  42. shared_worker_thread.cc
  43. shared_worker_thread.h
  44. threaded_messaging_proxy_base.cc
  45. threaded_messaging_proxy_base.h
  46. threaded_object_proxy_base.cc
  47. threaded_object_proxy_base.h
  48. threaded_worklet_messaging_proxy.cc
  49. threaded_worklet_messaging_proxy.h
  50. threaded_worklet_object_proxy.cc
  51. threaded_worklet_object_proxy.h
  52. threaded_worklet_test.cc
  53. worker.idl
  54. worker_backing_thread.cc
  55. worker_backing_thread.h
  56. worker_backing_thread_startup_data.h
  57. worker_classic_script_loader.cc
  58. worker_classic_script_loader.h
  59. worker_clients.cc
  60. worker_clients.h
  61. worker_fetch_test_helper.h
  62. worker_global_scope.cc
  63. worker_global_scope.h
  64. worker_global_scope.idl
  65. worker_location.h
  66. worker_location.idl
  67. worker_module_tree_client.cc
  68. worker_module_tree_client.h
  69. worker_navigator.cc
  70. worker_navigator.h
  71. worker_navigator.idl
  72. worker_options.idl
  73. worker_or_worklet_global_scope.cc
  74. worker_or_worklet_global_scope.h
  75. worker_reporting_proxy.h
  76. worker_settings.cc
  77. worker_settings.h
  78. worker_thread.cc
  79. worker_thread.h
  80. worker_thread_test.cc
  81. worker_thread_test_helper.h
  82. worklet.cc
  83. worklet.h
  84. worklet.idl
  85. worklet_global_scope.cc
  86. worklet_global_scope.h
  87. worklet_global_scope.idl
  88. worklet_global_scope_proxy.h
  89. worklet_module_responses_map.cc
  90. worklet_module_responses_map.h
  91. worklet_module_responses_map_test.cc
  92. worklet_module_tree_client.cc
  93. worklet_module_tree_client.h
  94. worklet_options.idl
  95. worklet_pending_tasks.cc
  96. worklet_pending_tasks.h
  97. worklet_thread_holder.h
third_party/blink/renderer/core/workers/README.md

This directory contains the base implementation of all worker and worklet types. Also, this contains the implementation of the Web Workers API (Dedicated Worker and Shared Worker) and Worklets API.

Worker / Worklet types

  • Workers are divided into 2 types:
    • In-process workers (Dedicated Workers): A worker of this type always runs in the same renderer process with a parent document that starts the worker.
    • Out-of-process workers (Shared Workers and Service Workers): A worker of this type may run in a different renderer process with a parent document that starts the worker.
  • Worklets are divided into 2 types:
    • Main thread worklets (Paint Worklets and Layout Worklets): A worklet of this type runs on the main thread.
    • Threaded worklets (Audio Worklets and Animation Worklets): A worklet of this type runs on a worker thread.

Worklets always run in the same renderer process with a parent document that starts the worklet like the in-process-workers.

Naming conventions

Classes in this directory are named with the following conventions, there're still some exceptions though.

  • WorkerOrWorklet prefix: Classes commonly used for workers and worklets (e.g., WorkerOrWorkletGlobalScope).
  • Worker / Worklet prefix: Classes used for workers or worklets (e.g., WorkerGlobalScope).
  • Threaded prefix: Classes used for workers and threaded worklets (e.g., ThreadedMessagingProxyBase).
  • MainThreadWorklet prefix: Classes used for main thread worklets (e.g., MainThreadWorkletReportingProxy).

Thread hopping between the main (parent) thread and a worker thread is handled by proxy classes.

  • MessagingProxy is the main (parent) thread side proxy that communicates to the worker thread.
  • ObjectProxy is the worker thread side proxy that communicates to the main (parent) thread. Object indicates a worker/worklet JavaScript object on the parent execution context.

Off-the-main-thread fetch

All worker subresources, and some of worker/worklet top-level scripts, are fetched off-the-main-thread (i.e. on the worker/worklet thread). See following docs for more details.

There are two types of network fetch on the worker/worklet thread: insideSettings and outsideSettings fetch. The terms insideSettings and outsideSettings are originated from HTML spec and Worklet spec.

insideSettings fetch

insideSettings fetch is subresource fetch.

In the spec, insideSettings corresponds to the worker environment settings object of WorkerOrWorkletGlobalScope.

In the implementation, insideSettings roughly corresponds to WorkerOrWorkletGlobalScope. WorkerOrWorkletGlobalScope::Fetcher(), its corresponding WorkerFetchContext, and WorkerOrWorkletGlobalScope::GetContentSecurityPolicy() are used.

Currently, all subresource fetches are already off-the-main-thread.

outsideSettings fetch

outsideSettings fetch is off-the-main-thread top-level worker/worklet script fetch.

In the spec, an outsideSettings is the environment settings object of worker's parent context.

In the implementation, outsideSettings should correspond to Document (or WorkerOrWorkletGlobalScope for nested workers), but the worker thread can't access these objects due to threading restriction. Therefore, we pass FetchClientSettingsObjectSnapshot that contains information of these objects across threads, and create ResourceFetcher, WorkerFetchContext and ContentSecurityPolicy (separate objects from those used for insideSettings fetch) on the worker thread. They work as if the parent context, and are used via WorkerOrWorkletGlobalScope::CreateOutsideSettingsFetcher().

Note that, where off-the-main-thread top-level fetch is NOT enabled (e.g. classic workers), the worker scripts are fetched on the main thread and thus WorkerOrWorkletGlobalScope and the worker thread are not involved.

Metrics

UseCounter

UseCounter is available in all workers and worklets. The count mechanism varies based on worker and worklet types as follows.

  • Dedicated Workers and Worklets: A feature use in a dedicated worker or worklet is propagated to the parent document, and then recorded in the document's UseCounter. For nested dedicated workers, a feature use is propagated up to the ancestor document via parent workers.
  • Shared Workers: A feature use in a shared worker is propagated to all documents connected to the shared worker via mojo calls, and then recorded in their UseCounter.
  • Service Workers: A feature use in a service worker is propagated to all documents and workers being controlled by the service worker via mojo calls, and then recorded in their UseCounter. When a feature use occurs before the service worker finishes installing, the feature use is stored in service worker storage. It is read whenever the installed service worker is started. See content/browser/service_worker/README.md for details.

WorkerOrWorkletGlobalScope::CountUse() is the common entry point. For more details, see Design of UseCounter for workers and crbug 376039.

There are some fundamental metrics.

  • WorkerStart : Counts of new DedicatedWorker() calls in Document and DedicatedWorkerGlobalScope.
  • NestedDedicatedWorker : Counts of new DedicatedWorker() calls in DedicatedWorkerGlobalScope.
  • SharedWorkerStart : Counts of new SharedWorker() calls in Document.
  • WorkletAddModule : Counts of Worklet#addModule() calls in Document. This includes all worklet types. Each worklet type has its own counter, too.

UMA

The UMA data is internal-only.

  • WorkerThread.ExitCode : Records the exit code of WorkerThread.

Tests

When you add a new worker or worklet type, please consider adding tests in following files and directories to check integration with the underlying worker and worklet infrastructure.

Workers and worklets interact with various features. You should also add tests in the following files and directories to avoid breakage.

References