Modifying Session History Serialization
Note: Please expand these steps as needed. See also NavigationEntryImpl comments for how to save and restore values outside of PageState, which is less common.
Overview
The following (non-exhaustive) steps are required to add new values to the PageState data serialization process, which is used for saving and restoring values in session restore across different versions of Chromium, as well as tab restore and tab duplication within a running instance of Chromium.
Note that changing the serialization format is high risk and should be approached carefully. Mistakes or missed steps can cause backwards compatibility problems, because the effects can continue to live on disk between different versions of Chromium. For this reason, it is important to make these changes carefully, minimizing the risk of reverts (e.g., not as part of much larger CLs) or other back-and-forth between formats (e.g., not as part of an A/B experiment).
Please ask the CL reviewer to also consult this checklist to ensure no steps have been missed.
PageState Modification Checklist
- Update NavigationEntryImpl's
RecursivelyGenerateFrameEntriesandRecursivelyGenerateFrameStateincontent/browser/renderer_host/navigation_entry_impl.ccto save and restore the new value from appropriate locations in Chromium. - Update any member declaration comments for the new value in
content/browser/renderer_host/frame_navigation_entry.h, indicating if the new value is persisted if necessary (e.g. here). - Update
third_party/blink/public/mojom/page_state/page_state.mojom, following the current instructions and warnings in the comments. These include (but are not limited to):- Search for
Next MinVersionin the comments and increment it. - Add the new value under the appropriate section, remembering to
increment the
Next Ordinalvalue for that section. Include[MinVersion=<N>]in front of the mojom declaration for the newly added value. E.g. if adding a value toExplodedFrameState, update theNext Ordinalvalue for thestruct FrameStatesection.
- Search for
- Add the new element to
ExplodedFrameStateinthird_party/blink/public/common/page_state/page_state_serialization.h. - Update the value of
kCurrentVersioninthird_party/blink/common/page_state/page_state_serialization.cc, and modify the comment above to explain what’s new in this version. - Update the
WriteFrameStateandReadFrameStatefunctions inthird_party/blink/common/page_state/page_state_serialization.ccto save and restore the new value in the persistence format. - Update
ExplodedFrameState::assign()to copy the new element so that its copy constructor and assignment operator works as expected. - Update the
ExplodedFrameState-specialization ofExpectEquality()inthird_party/blink/common/page_state/page_state_serialization_unittest.cc. - Update
PopulateFrameStateForBackwardsCompatTest, for cases where theversionvalue equals/exceeds the newkCurrentVersionset earlier. - Update
PopulateFrameStateto include the newly-added value. - Add a backwards compatibility test,
TEST_F(PageStateSerializationTest, BackwardsCompat_v<NN>), where<NN>is replaced by the new kCurrentVersion value. - Add a new baseline data file
third_party/blink/common/page_state/test_data/serialized_v<NN>.dat, using the following steps:- In
third_party/blink/common/page_state/page_state_serialization_unittest.cc, find the#if 0directive beforeTEST_F(PageStateSerializationTest, DumpExpectedPageStateForBackwardsCompat), and temporarily change it to#if 1. - Compile
blink_common_unitteststhen run with--gtest_filter=PageStateSerializationTest.DumpExpectedPageStateForBackwardsCompat - This will create a file
expected.datin the temp directory (e.g./tmpon Linux). Copy this file tothird_party/blink/common/page_state/test_data/serialized_v<NN>.datand rungit add. - Remember to undo the
#if 1change made topage_state_serialization_unittest.ccabove once the new baseline data has been created.
- In
Example CLs modifying the format:
- https://chromium-review.googlesource.com/c/chromium/src/+/1679162
- https://chromium-review.googlesource.com/c/chromium/src/+/4092432