Commit 7192987e authored by Nicolas Zea's avatar Nicolas Zea Committed by Commit Bot

Add ability to exclude page state in ContentSerializedNavigationBuilder

Serialization of page state can be a cpu intensive process as the serializer
must recursively traverse a tree of iframes. One of the common cases for
serializing navigation entries is Sync, which does not actually use the
encoded page state information.

This CL adds a new SerializationOptions param and support for using it to
exclude the page state when serializing a NavigationEntry, allowing Sync's
tab delegate to bypass encoding the page state.

Bug: 738187
Change-Id: Ib758db83e3f688c7016044e16a9f2818062e1da0
Reviewed-on: https://chromium-review.googlesource.com/560696
Commit-Queue: Nicolas Zea <zea@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#486125}
parent 83299caa
......@@ -114,9 +114,13 @@ void TabContentsSyncedTabDelegate::GetSerializedNavigationAtIndex(
sessions::SerializedNavigationEntry* serialized_entry) const {
NavigationEntry* entry = GetPossiblyPendingEntryAtIndex(web_contents_, i);
if (entry) {
// Explicitly exclude page state when serializing the navigation entry.
// Sync ignores the page state anyway (e.g. form data is not synced), and
// the page state can be expensive to serialize.
*serialized_entry =
sessions::ContentSerializedNavigationBuilder::FromNavigationEntry(
i, *entry);
i, *entry,
sessions::ContentSerializedNavigationBuilder::EXCLUDE_PAGE_STATE);
}
}
......
......@@ -22,7 +22,8 @@ namespace sessions {
SerializedNavigationEntry
ContentSerializedNavigationBuilder::FromNavigationEntry(
int index,
const content::NavigationEntry& entry) {
const content::NavigationEntry& entry,
SerializationOptions serialization_options) {
SerializedNavigationEntry navigation;
navigation.index_ = index;
navigation.unique_id_ = entry.GetUniqueID();
......@@ -30,7 +31,8 @@ ContentSerializedNavigationBuilder::FromNavigationEntry(
navigation.referrer_policy_ = entry.GetReferrer().policy;
navigation.virtual_url_ = entry.GetVirtualURL();
navigation.title_ = entry.GetTitle();
navigation.encoded_page_state_ = entry.GetPageState().ToEncodedData();
if (!(serialization_options & SerializationOptions::EXCLUDE_PAGE_STATE))
navigation.encoded_page_state_ = entry.GetPageState().ToEncodedData();
navigation.transition_type_ = entry.GetTransitionType();
navigation.has_post_data_ = entry.GetHasPostData();
navigation.post_id_ = entry.GetPostID();
......
......@@ -22,11 +22,25 @@ class SerializedNavigationEntry;
// classes.
class SESSIONS_EXPORT ContentSerializedNavigationBuilder {
public:
// Set of options for serializing a navigation. Multiple options can be
// combined by bit masking.
enum SerializationOptions {
// Serialized all available navigation data.
DEFAULT = 0x0,
// Exclude page state data. Serializing page state data can involve heavy
// processing on pages with deep iframe trees, so should be avoided if not
// necessary.
EXCLUDE_PAGE_STATE = 0x1,
};
// Construct a SerializedNavigationEntry for a particular index from the given
// NavigationEntry.
static SerializedNavigationEntry FromNavigationEntry(
int index,
const content::NavigationEntry& entry);
const content::NavigationEntry& entry,
SerializationOptions serialization_options =
SerializationOptions::DEFAULT);
// Convert the given SerializedNavigationEntry into a NavigationEntry with the
// given context. The NavigationEntry will have a transition type of
......
......@@ -161,6 +161,26 @@ TEST_F(ContentSerializedNavigationBuilderTest, FromNavigationEntry) {
navigation.extended_info_map().at(kExtendedInfoKey2));
}
// Test effect of the navigation serialization options.
TEST_F(ContentSerializedNavigationBuilderTest,
FromNavigationEntrySerializationOptions) {
const std::unique_ptr<content::NavigationEntry> navigation_entry(
MakeNavigationEntryForTest());
const SerializedNavigationEntry& default_navigation =
ContentSerializedNavigationBuilder::FromNavigationEntry(
test_data::kIndex, *navigation_entry,
ContentSerializedNavigationBuilder::DEFAULT);
EXPECT_EQ(test_data::kEncodedPageState,
default_navigation.encoded_page_state());
const SerializedNavigationEntry& excluded_page_state_navigation =
ContentSerializedNavigationBuilder::FromNavigationEntry(
test_data::kIndex, *navigation_entry,
ContentSerializedNavigationBuilder::EXCLUDE_PAGE_STATE);
EXPECT_TRUE(excluded_page_state_navigation.encoded_page_state().empty());
}
// Create a NavigationEntry, then create another one by converting to
// a SerializedNavigationEntry and back. The new one should match the old one
// except for fields that aren't preserved, which should be set to
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment