tree: d817852c31102515d3cba5677ba4a4213e482f8f [path history] [tgz]
  1. BUILD.gn
  2. DEPS
  3. embedded_worker_instance.cc
  4. embedded_worker_instance.h
  5. embedded_worker_instance_unittest.cc
  6. embedded_worker_registry.cc
  7. embedded_worker_registry.h
  8. embedded_worker_status.h
  9. embedded_worker_test_helper.cc
  10. embedded_worker_test_helper.h
  11. OWNERS
  12. payment_handler_support.cc
  13. payment_handler_support.h
  14. README.md
  15. service_worker_blob_reader.cc
  16. service_worker_blob_reader.h
  17. service_worker_browsertest.cc
  18. service_worker_cache_writer.cc
  19. service_worker_cache_writer.h
  20. service_worker_cache_writer_unittest.cc
  21. service_worker_client_info.cc
  22. service_worker_client_info.h
  23. service_worker_client_utils.cc
  24. service_worker_client_utils.h
  25. service_worker_clients_api_browsertest.cc
  26. service_worker_consts.cc
  27. service_worker_consts.h
  28. service_worker_content_settings_proxy_impl.cc
  29. service_worker_content_settings_proxy_impl.h
  30. service_worker_context_core.cc
  31. service_worker_context_core.h
  32. service_worker_context_core_observer.h
  33. service_worker_context_core_unittest.cc
  34. service_worker_context_request_handler.cc
  35. service_worker_context_request_handler.h
  36. service_worker_context_request_handler_unittest.cc
  37. service_worker_context_unittest.cc
  38. service_worker_context_watcher.cc
  39. service_worker_context_watcher.h
  40. service_worker_context_watcher_unittest.cc
  41. service_worker_context_wrapper.cc
  42. service_worker_context_wrapper.h
  43. service_worker_controllee_request_handler.cc
  44. service_worker_controllee_request_handler.h
  45. service_worker_controllee_request_handler_unittest.cc
  46. service_worker_data_pipe_reader.cc
  47. service_worker_data_pipe_reader.h
  48. service_worker_data_pipe_reader_unittest.cc
  49. service_worker_database.cc
  50. service_worker_database.h
  51. service_worker_database.proto
  52. service_worker_database_unittest.cc
  53. service_worker_disk_cache.cc
  54. service_worker_disk_cache.h
  55. service_worker_dispatcher_host.cc
  56. service_worker_dispatcher_host.h
  57. service_worker_dispatcher_host_unittest.cc
  58. service_worker_fetch_dispatcher.cc
  59. service_worker_fetch_dispatcher.h
  60. service_worker_info.cc
  61. service_worker_info.h
  62. service_worker_installed_script_loader.cc
  63. service_worker_installed_script_loader.h
  64. service_worker_installed_script_reader.cc
  65. service_worker_installed_script_reader.h
  66. service_worker_installed_scripts_sender.cc
  67. service_worker_installed_scripts_sender.h
  68. service_worker_installed_scripts_sender_unittest.cc
  69. service_worker_internals_ui.cc
  70. service_worker_internals_ui.h
  71. service_worker_job_coordinator.cc
  72. service_worker_job_coordinator.h
  73. service_worker_job_unittest.cc
  74. service_worker_lifetime_tracker.cc
  75. service_worker_lifetime_tracker.h
  76. service_worker_lifetime_tracker_unittest.cc
  77. service_worker_metrics.cc
  78. service_worker_metrics.h
  79. service_worker_metrics_unittest.cc
  80. service_worker_navigation_handle.cc
  81. service_worker_navigation_handle.h
  82. service_worker_navigation_handle_core.cc
  83. service_worker_navigation_handle_core.h
  84. service_worker_navigation_loader.cc
  85. service_worker_navigation_loader.h
  86. service_worker_navigation_loader_unittest.cc
  87. service_worker_new_script_loader.cc
  88. service_worker_new_script_loader.h
  89. service_worker_new_script_loader_unittest.cc
  90. service_worker_object_host.cc
  91. service_worker_object_host.h
  92. service_worker_object_host_unittest.cc
  93. service_worker_ping_controller.cc
  94. service_worker_ping_controller.h
  95. service_worker_process_manager.cc
  96. service_worker_process_manager.h
  97. service_worker_process_manager_unittest.cc
  98. service_worker_provider_host.cc
  99. service_worker_provider_host.h
  100. service_worker_provider_host_unittest.cc
  101. service_worker_quota_client.cc
  102. service_worker_quota_client.h
  103. service_worker_read_from_cache_job.cc
  104. service_worker_read_from_cache_job.h
  105. service_worker_read_from_cache_job_unittest.cc
  106. service_worker_register_job.cc
  107. service_worker_register_job.h
  108. service_worker_register_job_base.h
  109. service_worker_registration.cc
  110. service_worker_registration.h
  111. service_worker_registration_object_host.cc
  112. service_worker_registration_object_host.h
  113. service_worker_registration_status.cc
  114. service_worker_registration_status.h
  115. service_worker_registration_unittest.cc
  116. service_worker_request_handler.cc
  117. service_worker_request_handler.h
  118. service_worker_request_handler_unittest.cc
  119. service_worker_response_info.cc
  120. service_worker_response_info.h
  121. service_worker_response_type.h
  122. service_worker_script_cache_map.cc
  123. service_worker_script_cache_map.h
  124. service_worker_script_loader_factory.cc
  125. service_worker_script_loader_factory.h
  126. service_worker_script_loader_factory_unittest.cc
  127. service_worker_single_script_update_checker.cc
  128. service_worker_single_script_update_checker.h
  129. service_worker_single_script_update_checker_unittest.cc
  130. service_worker_storage.cc
  131. service_worker_storage.h
  132. service_worker_storage_unittest.cc
  133. service_worker_test_utils.cc
  134. service_worker_test_utils.h
  135. service_worker_tls_browsertest.cc
  136. service_worker_type_converters.cc
  137. service_worker_type_converters.h
  138. service_worker_unregister_job.cc
  139. service_worker_unregister_job.h
  140. service_worker_update_checker.cc
  141. service_worker_update_checker.h
  142. service_worker_url_job_wrapper.cc
  143. service_worker_url_job_wrapper.h
  144. service_worker_url_request_job.cc
  145. service_worker_url_request_job.h
  146. service_worker_url_request_job_unittest.cc
  147. service_worker_version.cc
  148. service_worker_version.h
  149. service_worker_version_unittest.cc
  150. service_worker_write_to_cache_job.cc
  151. service_worker_write_to_cache_job.h
  152. service_worker_write_to_cache_job_unittest.cc
content/browser/service_worker/README.md

Service workers

This is Chromium's implementation of service workers. See the Service Worker specification.

Directory structure

Storage

Service worker storage consists of the following.

  • Service worker registration metadata is stored in a LevelDB instance located at ${DIR_USER_DATA}/Service Worker/Database.
  • Service worker scripts are stored in a disk_cache instance using the “simple” implementation, located at ${DIR_USER_DATA}/Service Worker/ScriptCache. Registration metadata points to these scripts.

Code pointers include ServiceWorkerDatabase and ServiceWorkerStorage.

The related Cache Storage API uses a disk_cache instance using the “simple” implementation, located at ${DIR_USER_DATA}/Service Worker/CacheStorage. This location was chosen because the Cache Storage API is currently defined in the Service Worker specification, but it can be used independently of service workers.

For incognito windows, everything is in-memory.

Eviction

Service workers storage lasts indefinitely, i.e, there is no periodic deletion of old but still installed service workers. Installed service workers are only evicted by the Quota Manager (or user action). The Quota Manager controls several web platform APIs, including sandboxed filesystem, WebSQL, appcache, IndexedDB, cache storage, service worker (registration and scripts), and background fetch.

The Quota Manager starts eviction when one of the following conditions is true (as of August 2018):

  • The global pool is full: Chrome is using > 1/3 of the disk (>2/3 on CrOS).
  • The system is critically low on space: the disk has < min(1GB,1%) free (regardless of how much Chrome is contributing!)

When eviction starts, origins are purged on an LRU basis until the triggering condition no longer applies. Purging an origin deletes its storage completely.

Note that Quota Manager eviction is independent of HTTP cache eviction. The HTTP cache is typically much smaller than the storage under the control of the Quota Manager, and it likely uses a simple non-origin-based LRU algorithm.

UseCounter integration

Blink has a UseCounter mechanism intended to measure the percentage of page loads on the web that used a given feature. Service workers complicate this measurement because a feature use in a service worker potentially affects many page loads, including ones in the future.

Therefore, service workers integrate with the UseCounter mechanism as follows:

  • If a feature use occurs before the service worker finished installing, it is recorded in storage along with the service worker. Any page thereafter that the service worker controls is counted as using the feature.
  • If a feature use occurs after the service worker finished installing, all currently controlled pages are counted as using the feature.

For more details and rationale, see Design of UseCounter for workers and crbug 376039.

Code pointers include:

Other documentation