tree: dc5731f9c03d215245e6b65c000ac4e2612e6fdd [path history] [tgz]
  1. docs/
  2. testing/
  3. BUILD.gn
  4. cached_storage_area.cc
  5. cached_storage_area.h
  6. cached_storage_area_test.cc
  7. dom_window_storage.cc
  8. dom_window_storage.h
  9. dom_window_storage_controller.cc
  10. dom_window_storage_controller.h
  11. inspector_dom_storage_agent.cc
  12. inspector_dom_storage_agent.h
  13. OWNERS
  14. README.md
  15. storage.idl
  16. storage_area.cc
  17. storage_area.h
  18. storage_area_map.cc
  19. storage_area_map.h
  20. storage_area_map_test.cc
  21. storage_controller.cc
  22. storage_controller.h
  23. storage_controller_test.cc
  24. storage_event.cc
  25. storage_event.h
  26. storage_event.idl
  27. storage_event_init.idl
  28. storage_namespace.cc
  29. storage_namespace.h
  30. storage_namespace_test.cc
  31. window_storage.idl
third_party/blink/renderer/modules/storage/README.md

blink/renderer/modules/storage

This directory contains the renderer side implementation of the DOM Storage API. This API is defined in the HTML Spec's section on Web Storage.

The browser side code for this lives in content/browser/dom_storage/.

TODO(dmurph): Delete this paragraph after onion-souping is complete. https://crbug.com/781870 This file describes only the post-onion-souped version of the code, where features::kOnionSoupDOMStorage is turned on. This is not yet the default.

Class Responsibilities

DOMWindowStorage

This implements the partial Window interface in window_storage.idl, and provides bindings for window.localStorage and window.sessionStorage to the web platform. This creates & owns the StorageArea objects.

StorageArea

This implements the WebIDL Storage interface in storage.idl, and provides access to localStorage and sessionStorage. This class holds a shared reference to a CachedStorageArea (which can be shared between multiple StorageAreas), and basically delegates most calls here.

This is also temporarily created & used by InspectorDOMStorageAgent to make modifications to local & session storage.

CachedStorageArea

This is responsible for

  • keeping a local cache of the localStorage or sessionStorage data (which it does using a StorageAreaMap),
  • keeping track of Sources that are using this cached storage area (which are StorageAreas),
  • loading and saving data with a StorageArea mojo interface, and
  • observing changes from that StorageArea interface and communicating these to all Sources, and InspectorEventListeners.

StorageAreaMap

This represents an in-memory cache of a storage area. It holds key-value storage and keeps track of the total size of the bytes stored.

StorageNamespace

This class is responsible for

  • creating & caching CachedStorageAreas on a per-origin basis,
  • holding weak references to DOMStorageInspectorAgents & telling them when a storage event was dispatched,
  • interacting with the StoragePartitionService and SessionStorageNamespace mojo interfaces to create StorageArea mojo ptrs for the CachedStorageAreas and clone namespaces for SessionStorage.
  • accounting for all storage used in it's cached areas, and
  • cleaning up unused caches areas on demand.

There are two versions of this class - one version is the SessionStorage version, which holds a SessionStorageNamespace mojo ptr and lives on a Page as a Page Supplement. The other version is for LocalStorage, which just uses the StoragePartitionService to open the StorageAreas, and is owned by the StorageController.

StorageController

This is a singleton that is responsible for keeping track of all StorageNamespaces and provide access to the functionality of it's single LocalStorage StorageNamespace that it owns. It holds weak references to all of the SessionStorage StorageNamespaces so it can account for the total amount of memory used by all of DOMStorage. If this gets too high, it can ask all namespaces to prune all unused CacheStorageAreas.

InspectorDOMStorageAgent

This is used by the Inspector (DevTools) code to listen to and modify local & session storage. The StorageNamespace class allows these agents to be added & removed by the Inspector system, and all events that are dispatched on that namespace are sent to its InspectorDOMStorageAgents.

This class also creates a temporary StorageArea to query & modify local & session storage.

Class Ownership Structure

StorageArea lives on the window. Instances of this class hold a reference to a CachedStorageArea instance. All StorageArea instances representing the same area use the same CachedStorageArea instance (which is reference counted). Two classes are used to create and manage CachedStorageAreas - the StorageController, and StorageNamespaces.

The StorageNamespace represents a SessionStorage namespace, but can also be used for LocalStorage. It creates & manages CachedStorageAreas per-origin. It keeps a reference to all CachedStorageAreas it creates for memory accounting and object re-use. It also contains weak references to InspectorDOMStorageAgents that it notifies when StorageEvents are dispatched.

SessionStorage StorageNamespace objects live as supplements on the Page, so each Page owns one. The LocalStorage StorageNamespace object lives in the StorageController.

The StorageController is a singleton. It owns the LocalStorage StorageNamespace, and hold weak references to each SessionStorage StorageNamespace.

Finally - InspectorDomStorageAgent will create temporary StorageArea objects when it wants to query or modify DOMStorage.

Object ownership graph Image Source