tree: c4d84fced9f5e090c6a66183f09a36e3e53c4e45 [path history] [tgz]
  1. proto/
  2. BUILD.gn
  3. DEPS
  4. fake_tab_restore_service.h
  5. fake_tab_restore_service.mm
  6. features.cc
  7. features.h
  8. ios_chrome_tab_restore_browser_agent.h
  9. ios_chrome_tab_restore_browser_agent.mm
  10. ios_chrome_tab_restore_service_client.h
  11. ios_chrome_tab_restore_service_client.mm
  12. ios_chrome_tab_restore_service_factory.cc
  13. ios_chrome_tab_restore_service_factory.h
  14. legacy_session_restoration_service.h
  15. legacy_session_restoration_service.mm
  16. legacy_session_restoration_service_unittest.mm
  17. live_tab_context_browser_agent.h
  18. live_tab_context_browser_agent.mm
  19. NSCoder+Compatibility.h
  20. NSCoder+Compatibility.mm
  21. OWNERS
  22. proto_util.cc
  23. proto_util.h
  24. proto_util_unittest.cc
  25. README.md
  26. session_constants.h
  27. session_constants.mm
  28. session_internal_util.h
  29. session_internal_util.mm
  30. session_internal_util_unittest.mm
  31. session_io_request.h
  32. session_io_request.mm
  33. session_io_request_unittest.mm
  34. session_ios.h
  35. session_ios.mm
  36. session_loading.h
  37. session_loading.mm
  38. session_loading_unittest.mm
  39. session_migration.h
  40. session_migration.mm
  41. session_migration_unittest.mm
  42. session_restoration_browser_agent.h
  43. session_restoration_browser_agent.mm
  44. session_restoration_browser_agent_unittest.mm
  45. session_restoration_observer.h
  46. session_restoration_scroll_observer.h
  47. session_restoration_scroll_observer.mm
  48. session_restoration_scroll_observer_unittest.mm
  49. session_restoration_service.h
  50. session_restoration_service_factory.h
  51. session_restoration_service_factory.mm
  52. session_restoration_service_factory_unittest.mm
  53. session_restoration_service_impl.h
  54. session_restoration_service_impl.mm
  55. session_restoration_service_impl_unittest.mm
  56. session_restoration_service_tmpl.h
  57. session_restoration_web_state_list_observer.h
  58. session_restoration_web_state_list_observer.mm
  59. session_restoration_web_state_list_observer_unittest.mm
  60. session_restoration_web_state_observer.h
  61. session_restoration_web_state_observer.mm
  62. session_restoration_web_state_observer_unittest.mm
  63. session_saving_scene_agent.h
  64. session_saving_scene_agent.mm
  65. session_service_ios.h
  66. session_service_ios.mm
  67. session_service_ios_unittest.mm
  68. session_tab_group.h
  69. session_tab_group.mm
  70. session_util.h
  71. session_util.mm
  72. session_window_ios.h
  73. session_window_ios.mm
  74. session_window_ios_factory.h
  75. session_window_ios_factory.mm
  76. session_window_ios_unittest.mm
  77. tab_group_util.h
  78. tab_group_util.mm
  79. tab_group_util_unittest.mm
  80. test_session_restoration_observer.h
  81. test_session_restoration_observer.mm
  82. test_session_restoration_service.h
  83. test_session_restoration_service.mm
  84. test_session_service.h
  85. test_session_service.mm
  86. web_session_state_cache.h
  87. web_session_state_cache.mm
  88. web_session_state_cache_factory.h
  89. web_session_state_cache_factory.mm
  90. web_session_state_cache_unittest.mm
  91. web_session_state_cache_web_state_list_observer.h
  92. web_session_state_cache_web_state_list_observer.mm
  93. web_session_state_tab_helper.h
  94. web_session_state_tab_helper.mm
  95. web_session_state_tab_helper_unittest.mm
  96. web_state_list_serialization.h
  97. web_state_list_serialization.mm
  98. web_state_list_serialization_unittest.mm
ios/chrome/browser/sessions/model/README.md

Session saving and restoration.

A Session is the data Chrome saves to an iOS device's storage that preserves the state of open tabs in a given Browser. On a device that only supports a single Chrome window, there will be one saved session for the regular tabs, and one saved session for the Incognito tabs. On devices that support multiple windows, there will be one or two (two if there are Incognito tabs) saved sessions for each window.

Sessions are the mechanism by which a user‘s open tabs are restored when they laucnh Chrome. Given that iOS can terminate Chrome in the background at any time -- and can disconnect individual scenes when there are multiple windows -- it’s critical that sessions are saved and restored in a way that is quick and lossless for the user.

(Don‘t confuse this Chrome-specific sense of session with the UIKit concept of a scene session, implemented in the UISceneSession class. While both are concerned with persisting application state data, they are not interchangeable, and Chrome’s sessions are not implemented using UISceneSessions for storage.)

Session saving

The design intent is that sessions are saved before Chrome enters a state where it might be suddenly terminated.

Saving a session is done by means of the SessionRestorationBrowserAgent for the browser being saved, using the SaveSession() method. Calling this saves the session for the browser the agent is attached to.

SaveSession() is called in the following circumstances:

  1. Whenever a sene moves to the background, SaveSession() is called on its browsers.
  2. When the UI for a scene is destroyed (when the scene‘s SceneController is shutting down), SaveSession() is called if it hasn’t been called aready.
  3. When a tab is inserted, removed, activated, replaced, re-ordered, or completes a navigation, SaveSession() on the Browser that owns its WebStateList.
  4. When a prerendered tab is loaded, replacing an existing webState, SaveSession() on the browser whose WebStateList contains the new tab.

Case (1) is handled by SessionSavingSceneAgent, which watches for scene state changes and tracks if the current scene has been foregrounded since the last time it was saved. Such scenes are marked as needing to have their sessions saved the next time they background.

Case (2) is handled by SceneController itself when it shuts down; it in turn asks its SessionSavingSceneAgent to save its sessions if needed.

Case (3) is handled by SessionRestorationBrowserAgent via WebState and WebStateList observation.

Case (4) is handled by the PrerenderService; it directly calls SaveSession(), regardless of whether the session is in the background.

Cases (3) and (4) save after a short delay, and repeated session saves within that delay are ignored. Cases (1) and (2) save immediately (canceling any pending delayed saves). SessionServiceIOS handles this.

Session Restoration

TODO: Describe when sessions are restored.

Session Recovery

TODO: Describe the logic for post-crash session recovery and how sessions are set aside and (possibly) discarded.

Incognito Sessions

TODO: Describe how Incognito sessions are stored, and how it differs from how regular session are.