tree: d245800fad7ba909eb52ded899f5671a76422479 [path history] [tgz]
  1. BUILD.gn
  2. DEPS
  3. OWNERS
  4. README.md
  5. embedded_worker_instance.cc
  6. embedded_worker_instance.h
  7. embedded_worker_instance_unittest.cc
  8. embedded_worker_status.h
  9. embedded_worker_test_helper.cc
  10. embedded_worker_test_helper.h
  11. fake_embedded_worker_instance_client.cc
  12. fake_embedded_worker_instance_client.h
  13. fake_service_worker.cc
  14. fake_service_worker.h
  15. payment_handler_support.cc
  16. payment_handler_support.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_unittest.cc
  35. service_worker_context_watcher.cc
  36. service_worker_context_watcher.h
  37. service_worker_context_watcher_unittest.cc
  38. service_worker_context_wrapper.cc
  39. service_worker_context_wrapper.h
  40. service_worker_controllee_request_handler.cc
  41. service_worker_controllee_request_handler.h
  42. service_worker_controllee_request_handler_unittest.cc
  43. service_worker_database.cc
  44. service_worker_database.h
  45. service_worker_database.proto
  46. service_worker_database_unittest.cc
  47. service_worker_disk_cache.cc
  48. service_worker_disk_cache.h
  49. service_worker_fetch_dispatcher.cc
  50. service_worker_fetch_dispatcher.h
  51. service_worker_file_upload_browsertest.cc
  52. service_worker_info.cc
  53. service_worker_info.h
  54. service_worker_installed_script_loader.cc
  55. service_worker_installed_script_loader.h
  56. service_worker_installed_script_reader.cc
  57. service_worker_installed_script_reader.h
  58. service_worker_installed_scripts_sender.cc
  59. service_worker_installed_scripts_sender.h
  60. service_worker_installed_scripts_sender_unittest.cc
  61. service_worker_internals_ui.cc
  62. service_worker_internals_ui.h
  63. service_worker_job_coordinator.cc
  64. service_worker_job_coordinator.h
  65. service_worker_job_unittest.cc
  66. service_worker_metrics.cc
  67. service_worker_metrics.h
  68. service_worker_metrics_unittest.cc
  69. service_worker_navigation_handle.cc
  70. service_worker_navigation_handle.h
  71. service_worker_navigation_handle_core.cc
  72. service_worker_navigation_handle_core.h
  73. service_worker_navigation_loader.cc
  74. service_worker_navigation_loader.h
  75. service_worker_navigation_loader_unittest.cc
  76. service_worker_new_script_loader.cc
  77. service_worker_new_script_loader.h
  78. service_worker_new_script_loader_unittest.cc
  79. service_worker_no_best_effort_tasks_browsertest.cc
  80. service_worker_object_host.cc
  81. service_worker_object_host.h
  82. service_worker_object_host_unittest.cc
  83. service_worker_ping_controller.cc
  84. service_worker_ping_controller.h
  85. service_worker_process_manager.cc
  86. service_worker_process_manager.h
  87. service_worker_process_manager_unittest.cc
  88. service_worker_provider_host.cc
  89. service_worker_provider_host.h
  90. service_worker_provider_host_unittest.cc
  91. service_worker_quota_client.cc
  92. service_worker_quota_client.h
  93. service_worker_register_job.cc
  94. service_worker_register_job.h
  95. service_worker_register_job_base.h
  96. service_worker_registration.cc
  97. service_worker_registration.h
  98. service_worker_registration_object_host.cc
  99. service_worker_registration_object_host.h
  100. service_worker_registration_status.cc
  101. service_worker_registration_status.h
  102. service_worker_registration_unittest.cc
  103. service_worker_request_handler.cc
  104. service_worker_request_handler.h
  105. service_worker_request_handler_unittest.cc
  106. service_worker_response_type.h
  107. service_worker_script_cache_map.cc
  108. service_worker_script_cache_map.h
  109. service_worker_script_loader_factory.cc
  110. service_worker_script_loader_factory.h
  111. service_worker_script_loader_factory_unittest.cc
  112. service_worker_single_script_update_checker.cc
  113. service_worker_single_script_update_checker.h
  114. service_worker_single_script_update_checker_unittest.cc
  115. service_worker_storage.cc
  116. service_worker_storage.h
  117. service_worker_storage_unittest.cc
  118. service_worker_test_utils.cc
  119. service_worker_test_utils.h
  120. service_worker_tls_browsertest.cc
  121. service_worker_type_converters.cc
  122. service_worker_type_converters.h
  123. service_worker_unregister_job.cc
  124. service_worker_unregister_job.h
  125. service_worker_update_checker.cc
  126. service_worker_update_checker.h
  127. service_worker_version.cc
  128. service_worker_version.h
  129. service_worker_version_unittest.cc
  130. test_service_worker_observer.cc
  131. test_service_worker_observer.h
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:

Performance

We monitor service worker performance with real-world metrics (UMA) and performance benchmarks.

UMA

The UMA data is internal-only. Key metrics include:

Page load metrics for service worker controlled loads:

  • PageLoad.Clients.ServiceWorker2.PaintTiming.NavigationToFirstContentfulPaint
  • PageLoad.Clients.ServiceWorker2.Input.NavigationToFirstContentfulPaint
  • PageLoad.Clients.ServiceWorker2.InteractiveTiming.FirstInputDelay3

Service worker startup time and breakdown:

  • ServiceWorker.StartWorker.Time
  • ServiceWorker.StartTiming.Duration
  • ServiceWorker.StartTiming.*To* (e.g., ServiceWorker.StartTiming.StartToReceivedStartWorker)

Fetch event handling:

  • ServiceWorker.LoadTiming.MainFrame.MainResource.*
  • ServiceWorker.LoadTiming.Subresource.*

TODO(falken, bashi): Add a list of the milestones of startup and fetch event handling.

Tests

We run a limited number of Telemetry benchmark tests for service worker. These tests are part of the Loading benchmarks, as the “pwa” tests inside the “loading.mobile” suite. The tests do not run on desktop machines (loading.desktop) due to resource constraints.

See a quick dashboard of these test results. You can also run the benchmarks locally:

# Run benchmark on `FlipKart`
$ tools/perf/run_benchmark --browser=android-chromium loading.mobile --story-filter='FlipKart'

# Run benchmark on `FlipKart` with cache_temperature = cold
$ tools/perf/run_benchmark --browser=android-chromium loading.mobile --story-filter='FlipKart_cold'

TODO(falken): Merge this with loading.md and cache_temperature.py documentation.

The PWA tests load a page multiple times. Each time has a different “cache temperature”. These temperatures have special significance for service worker controlled page loads:

  • cold: tests the very first load to a page (no active service worker). Browser cache and storage data including service worker registrations are cleared first.
  • warm: tests the second load to a page (with an active service worker). It first does a cold load which installs a service worker, waits for the service worker to reach activated state, and then tests the load.
  • hot: tests the third load to the page (with an active service worker and V8 code caching). It first does a warm load, then waits(?) for V8 Code Caching to complete, then tests another load.

Service workers are terminated between loads in order to include service worker startup as part of the performance test.

Code links and resources:

Other documentation