Commit 3c2815cf authored by Michael Giuffrida's avatar Michael Giuffrida Committed by Commit Bot

WindowActivityWatcher: Verify browser window exists

It's apparently possible for
BrowserList::SetLastActive(Browser* browser) to be called before
|browser| is added to the BrowserList. This might happen, e.g., if a
BrowserView's widget receives an activation event before
CreateBrowserWindow() returns.

This will cause WindowActivityWatcher's UpdateMetrics() helper function
to dereference the null pointer at browser->window().

Bug: 811243,811191
Change-Id: Ia377a810b73494f88d1cd2b4532367950f35b1f7
Reviewed-on: https://chromium-review.googlesource.com/924353
Commit-Queue: Michael Giuffrida <michaelpg@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537825}
parent fcedfca0
......@@ -44,6 +44,8 @@ struct WindowMetrics {
// Sets metric values that are dependent on the current window state.
void UpdateMetrics(const Browser* browser, WindowMetrics* window_metrics) {
DCHECK(browser->window());
if (browser->window()->IsFullscreen())
window_metrics->show_state = WindowMetricsEvent::SHOW_STATE_FULLSCREEN;
else if (browser->window()->IsMinimized())
......@@ -195,11 +197,19 @@ void WindowActivityWatcher::OnBrowserRemoved(Browser* browser) {
}
void WindowActivityWatcher::OnBrowserSetLastActive(Browser* browser) {
if (ShouldTrackBrowser(browser))
// The browser may not have a window yet if activation calls happen during
// initialization.
// TODO(michaelpg): The browser window check should be unnecessary
// (https://crbug.com/811191, https://crbug.com/811243).
if (ShouldTrackBrowser(browser) && browser->window())
browser_watchers_[browser]->MaybeLogWindowMetricsUkmEntry();
}
void WindowActivityWatcher::OnBrowserNoLongerActive(Browser* browser) {
if (ShouldTrackBrowser(browser))
// The browser may not have a window yet if activation calls happen during
// initialization.
// TODO(michaelpg): The browser window check should be unnecessary
// (https://crbug.com/811191, https://crbug.com/811243).
if (ShouldTrackBrowser(browser) && browser->window())
browser_watchers_[browser]->MaybeLogWindowMetricsUkmEntry();
}
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