Commit 6f6acf6a authored by Nicolas Ouellet-Payeur's avatar Nicolas Ouellet-Payeur Committed by Chromium LUCI CQ

Make ScopedProfileKeepAlive play nice in unit tests

In unit-tests, g_browser_process->profile_manager() can return null.
When the DestroyProfileOnBrowserClose flag is enabled (via
ScopedFeatureList, or fieldtrial_testing_config.json),
ScopedProfileKeepAlive causes a crash.

Add a guard in ScopedProfileKeepAlive(), so it's a no-op if there is no
ProfileManager.

Bug: 88586
Change-Id: Ife9f198da3d7dc69f8cf59bed80aca9c57517a6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2614859
Auto-Submit: Nicolas Ouellet-Payeur <nicolaso@chromium.org>
Commit-Queue: Mihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841088}
parent 9e46ab65
......@@ -12,7 +12,10 @@ ScopedProfileKeepAlive::ScopedProfileKeepAlive(const Profile* profile,
ProfileKeepAliveOrigin origin)
: profile_(profile), origin_(origin) {
DCHECK(profile_);
g_browser_process->profile_manager()->AddKeepAlive(profile_, origin_);
// |profile_manager| can be nullptr in tests.
auto* profile_manager = g_browser_process->profile_manager();
if (profile_manager)
profile_manager->AddKeepAlive(profile_, origin_);
}
ScopedProfileKeepAlive::~ScopedProfileKeepAlive() {
......
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