Commit 68e0bec7 authored by Charlene Yan's avatar Charlene Yan Committed by Commit Bot

[Tab Groups Collapse] Save collapsed group state for session restore.

Feedback from users are that they want their collapsed groups to remain
collapsed when reopening their windows.

Also cleaning up kCommandSetTabGroupMetadata which was replaced in M81
for backwards compatibility for color.

Bug: 1127622
Change-Id: Idce8be561c2d060f4c2613bf358502becc70db1a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2458876Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Charlene Yan <cyan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816702}
parent 0b308a0e
......@@ -1068,7 +1068,7 @@ IN_PROC_BROWSER_TEST_P(SessionRestoreTabGroupsTest, GroupMetadataRestored) {
const tab_groups::TabGroupVisualData group1_data =
*tsm->group_model()->GetTabGroup(group1)->visual_data();
const tab_groups::TabGroupVisualData group2_data(
base::ASCIIToUTF16("Foo"), tab_groups::TabGroupColorId::kBlue);
base::ASCIIToUTF16("Foo"), tab_groups::TabGroupColorId::kBlue, true);
tsm->group_model()->GetTabGroup(group2)->SetVisualData(group2_data);
Browser* const new_browser = QuitBrowserAndRestore(browser(), 5);
......@@ -1080,10 +1080,13 @@ IN_PROC_BROWSER_TEST_P(SessionRestoreTabGroupsTest, GroupMetadataRestored) {
new_tsm->group_model()->GetTabGroup(group1)->visual_data();
const tab_groups::TabGroupVisualData* const group2_restored_data =
new_tsm->group_model()->GetTabGroup(group2)->visual_data();
EXPECT_EQ(group1_data.title(), group1_restored_data->title());
EXPECT_EQ(group1_data.color(), group1_restored_data->color());
EXPECT_EQ(group1_data.is_collapsed(), group1_restored_data->is_collapsed());
EXPECT_EQ(group2_data.title(), group2_restored_data->title());
EXPECT_EQ(group2_data.color(), group2_restored_data->color());
EXPECT_EQ(group2_data.is_collapsed(), group2_restored_data->is_collapsed());
}
INSTANTIATE_TEST_SUITE_P(WithAndWithoutReset,
......
......@@ -65,7 +65,8 @@ static const SessionCommand::id_type kCommandLastActiveTime = 21;
static const SessionCommand::id_type kCommandSetWindowWorkspace2 = 23;
static const SessionCommand::id_type kCommandTabNavigationPathPruned = 24;
static const SessionCommand::id_type kCommandSetTabGroup = 25;
static const SessionCommand::id_type kCommandSetTabGroupMetadata = 26;
// OBSOLETE Superseded by kCommandSetTabGroupMetadata2.
// static const SessionCommand::id_type kCommandSetTabGroupMetadata = 26;
static const SessionCommand::id_type kCommandSetTabGroupMetadata2 = 27;
static const SessionCommand::id_type kCommandSetTabGuid = 28;
static const SessionCommand::id_type kCommandSetTabUserAgentOverride2 = 29;
......@@ -635,7 +636,6 @@ bool CreateTabsAndWindows(
break;
}
case kCommandSetTabGroupMetadata:
case kCommandSetTabGroupMetadata2: {
std::unique_ptr<base::Pickle> pickle = command->PayloadAsPickle();
base::PickleIterator iter(*pickle);
......@@ -652,27 +652,16 @@ bool CreateTabsAndWindows(
if (!iter.ReadString16(&title))
return true;
if (command->id() == kCommandSetTabGroupMetadata) {
SkColor color;
if (!iter.ReadUInt32(&color))
return true;
// crrev.com/c/1968039 changes the color of a tab group from a SkColor
// to a TabGroupColorId. Here we ignore the old SkColor and assign the
// default TabGroupColorId because the fallback is acceptable while
// the tab groups feature isn't yet launched. Once it is,
// kCommandSetTabGroupMetadata will be deprecated in favor of
// kCommandSetTabGroupMetadata2, which properly restores
// TabGroupColorIds.
group->visual_data = tab_groups::TabGroupVisualData(
title, tab_groups::TabGroupColorId::kGrey);
} else {
uint32_t color_int;
if (!iter.ReadUInt32(&color_int))
return true;
uint32_t color_int;
if (!iter.ReadUInt32(&color_int))
return true;
group->visual_data = tab_groups::TabGroupVisualData(title, color_int);
}
// The |is_collapsed| boolean was added in M88 to save the collapsed
// state, so previous versions may not have this stored.
bool is_collapsed = false;
ignore_result(!iter.ReadBool(&is_collapsed));
group->visual_data =
tab_groups::TabGroupVisualData(title, color_int, is_collapsed);
break;
}
......@@ -963,6 +952,9 @@ std::unique_ptr<SessionCommand> CreateTabGroupMetadataUpdateCommand(
WriteTokenToPickle(&pickle, group.token());
pickle.WriteString16(visual_data->title());
pickle.WriteUInt32(static_cast<int>(visual_data->color()));
// This boolean was added in M88 to save the collapsed state.
pickle.WriteBool(visual_data->is_collapsed());
return std::make_unique<SessionCommand>(kCommandSetTabGroupMetadata2, pickle);
}
......
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