Commit a0bdaa4a authored by Charles Zhao's avatar Charles Zhao Committed by Commit Bot

tab_discarder: check nullptr for web_contents_data

Based on the bug report, the GetTabFeatures() crashes on a line when
accessing it's own member variables which indicates the pointer maybe
empty.

Based on recent change in
https://chromium-review.googlesource.com/c/chromium/src/+/1816004

It's very likely that web_contents_data becomes nullptr in some cases.

Bug: 1017222
Change-Id: Iec58d533af478cc37f96cbedc263884e7e34bf1e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1884407Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Reviewed-by: default avatarCharles . <charleszhao@chromium.org>
Commit-Queue: Charles . <charleszhao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711467}
parent a0171059
......@@ -568,15 +568,22 @@ void TabActivityWatcher::LogAndMaybeSortLifecycleUnitWithTabRanker(
// TabManagerDelegateTest::KillMultipleProcesses.
if (!lifecycle_unit_external) {
tab_features[lifecycle_unit->GetID()] = base::nullopt;
} else {
WebContentsData* web_contents_data = WebContentsData::FromWebContents(
lifecycle_unit_external->GetWebContents());
DCHECK(web_contents_data);
const base::Optional<TabFeatures> tab =
web_contents_data->GetTabFeatures();
tab_features[lifecycle_unit->GetID()] = tab;
web_contents_data->LogCurrentTabFeatures(tab);
continue;
}
WebContentsData* web_contents_data = WebContentsData::FromWebContents(
lifecycle_unit_external->GetWebContents());
// The web_contents_data can be nullptr in some cases.
// TODO(crbug.com/1019482): move the creation of WebContentsData to
// TabHelpers::AttachTabHelpers.
if (!web_contents_data) {
tab_features[lifecycle_unit->GetID()] = base::nullopt;
continue;
}
const base::Optional<TabFeatures> tab = web_contents_data->GetTabFeatures();
tab_features[lifecycle_unit->GetID()] = tab;
web_contents_data->LogCurrentTabFeatures(tab);
}
// Directly return if TabRanker is not enabled.
......
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