tree: 072f1b5c86ec721ef80de59a1bf8daf24021e8fc [path history] [tgz]
  1. README.md
  2. cache_entry_handler_impl.cc
  3. cache_entry_handler_impl.h
  4. cleanup_task.cc
  5. cleanup_task.h
  6. create_metadata_task.cc
  7. create_metadata_task.h
  8. database_helpers.cc
  9. database_helpers.h
  10. database_helpers_unittest.cc
  11. database_task.cc
  12. database_task.h
  13. delete_registration_task.cc
  14. delete_registration_task.h
  15. get_developer_ids_task.cc
  16. get_developer_ids_task.h
  17. get_initialization_data_task.cc
  18. get_initialization_data_task.h
  19. get_metadata_task.cc
  20. get_metadata_task.h
  21. get_registration_task.cc
  22. get_registration_task.h
  23. get_request_blob_task.cc
  24. get_request_blob_task.h
  25. image_helpers.cc
  26. image_helpers.h
  27. image_helpers_unittest.cc
  28. mark_registration_for_deletion_task.cc
  29. mark_registration_for_deletion_task.h
  30. mark_request_complete_task.cc
  31. mark_request_complete_task.h
  32. match_requests_task.cc
  33. match_requests_task.h
  34. start_next_pending_request_task.cc
  35. start_next_pending_request_task.h
content/browser/background_fetch/storage/README.md

Background fetch state storage

content/browser/background_fetch/storage contains a set of tasks that read to and write from the service worker database, to store the state of the currently running background fetches.

DatabaseTask is the abstract base class that all other tasks extend.

Service Worker DB UserData schema

Design doc

  • Each key will be stored twice by the Service Worker DB, once as a “REG_HAS_USER_DATA:”, and once as a “REG_USER_DATA:” - see content/browser/service_worker/service_worker_database.cc for details.
  • Non-padded integer values are serialized as a string by base::Int*ToString().

Keys and values

key: "bgfetch_active_registration_unique_id_<developer_id>"
value: "<unique_id>"
key: "bgfetch_registration_<unique_id>"
value: "<serialized content::proto::BackgroundFetchMetadata>"
key: "bgfetch_ui_options_<unique_id>"
value: "<serialized content::proto::BackgroundFetchUIOptions>"
key: "bgfetch_pending_request_<unique_id>_<request_index>"
value: "<serialized content::proto::BackgroundFetchPendingRequest>"
key: "bgfetch_active_request_<unique_id>_<request_index>"
value: "<serialized content::proto::BackgroundFetchActiveRequest>"
key: "bgfetch_completed_request_<unique_id>_<request_index>"
value: "<serialized content::proto::BackgroundFetchCompletedRequest>"
key: "bgfetch_storage_version_<unique_id>"
value: "<content::proto::BackgroundFetchStorageVersion>"

Cache Storage UserData schema

The downloaded responses of every fetch will be stored in their own private cache.

Cache identifiers

  • origin: <origin>
  • owner: CacheStorageOwner::kBackgroundFetch
  • cache_name: <unique_id>

The cache will contain all the Request/Response key/value pairs of the fetch. Note that the Request value stored isn't comprehensive, and only the url value is used to as a key to find the matching Response.

Expansions

  • <unique_id> is a GUID (v4) that identifies a background fetch registration. E.g. 17467386-60b4-4c5b-b66c-aabf793fd39b
  • <developer_id> is a string provided by the developer to differentiate background fetches within a service worker. As such it may contain any characters and so it should be used very carefully within keys as it may introduce ambiguity.
  • <request_index> is an int containing the index of a request within a multi-part fetch. These must be padded with zeros to ensure that the ordering is maintain when reading back from the database, e.g. 0000000000.
  • <ui_title> is the notification title provided by the developer. It can also be updated by calling BackgroundFetchUpdateEvent.updateUI.