DayZeroBrowserUIExptManager crashes when P3A is toggled off-on-off (#34370)
fix: DayZeroBrowserUIExptManager crashes when P3A is toggled off-on-off ResetBrowserUIStateForAllProfiles() was resetting observation_ when P3A was disabled, but SetDayZeroBrowserUIForAllProfiles() never re-established it when P3A was re-enabled. Toggling P3A off a second time hit the CHECK(observation_.IsObserving()) because the observation was already reset. Remove the observation_.Reset() from ResetBrowserUIStateForAllProfiles(). It's unnecessary because OnProfileAdded() already guards on IsP3AEnabled(), making it a no-op when P3A is off. Also destroy the p3a_enabled_ pref subscription in OnProfileManagerDestroying() to prevent the callback from firing after the ProfileManager is gone. Resolves: https://github.com/brave/brave-browser/issues/53294
This commit is contained in:
@@ -113,6 +113,9 @@ void DayZeroBrowserUIExptManager::OnProfileAdded(Profile* profile) {
|
||||
}
|
||||
|
||||
void DayZeroBrowserUIExptManager::OnProfileManagerDestroying() {
|
||||
// Unsubscribe the pref callback before resetting the observation to ensure
|
||||
// OnP3AEnabledChanged() can't fire after the ProfileManager is gone.
|
||||
p3a_enabled_.Destroy();
|
||||
if (observation_.IsObserving()) {
|
||||
observation_.Reset();
|
||||
}
|
||||
@@ -134,8 +137,11 @@ void DayZeroBrowserUIExptManager::ResetForDayZeroBrowserUI(Profile* profile) {
|
||||
|
||||
void DayZeroBrowserUIExptManager::ResetBrowserUIStateForAllProfiles() {
|
||||
CHECK(observation_.IsObserving());
|
||||
observation_.Reset();
|
||||
|
||||
// Don't reset observation_ here. Previously it was reset when P3A was
|
||||
// disabled, but that caused a CHECK crash if P3A was toggled off->on->off
|
||||
// because the observation was never re-established. It's safe to keep
|
||||
// observing because OnProfileAdded() already guards on IsP3AEnabled(),
|
||||
// making it a no-op when P3A is off.
|
||||
// Reset all currently active normal profiles.
|
||||
for (auto* profile : profile_manager_->GetLoadedProfiles()) {
|
||||
if (!profile->IsRegularProfile()) {
|
||||
|
||||
Reference in New Issue
Block a user