Fix NOTREACHED crash if ReadingListFactory isn't instantiated
The cleanup code for deprecated preferences can crash (NOTREACHED) if
the preference isn't registered. Before this patch, the registration
relied on the factories built-in support for preference registration,
i.e. RegisterBrowserStatePrefs()/RegisterProfilePrefs(), but this turns
out to be unreliable for the purpose of data cleanup, which is exercised
independently of factory creation.
The fix is to register the deprecated preference closer to the cleanup
logic, instead of relying on the factories.
Change-Id: Ia82dbb7dc308d29e878d648d230ab5fd3e7a646d
Fixed: 1431882
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4459277
Reviewed-by: Shakti Sahu <[email protected]>
Reviewed-by: Olivier Robin <[email protected]>
Reviewed-by: Dominic Battre <[email protected]>
Code-Coverage: Findit <[email protected]>
Commit-Queue: Mikel Astiz <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1134315}
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index 7db8872..d11c0f133 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -139,7 +139,6 @@
#include "components/prefs/pref_service.h"
#include "components/privacy_sandbox/privacy_sandbox_prefs.h"
#include "components/proxy_config/pref_proxy_config_tracker_impl.h"
-#include "components/reading_list/core/reading_list_pref_names.h"
#include "components/safe_browsing/content/common/file_type_policies_prefs.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/search_engines/template_url_prepopulate_data.h"
@@ -675,6 +674,8 @@
// Deprecated 12/2022.
const char kAutofillWalletImportStorageCheckboxState[] =
"autofill.wallet_import_storage_checkbox_state";
+const char kDeprecatedReadingListHasUnseenEntries[] =
+ "reading_list.has_unseen_entries";
// Deprecated 01/2023
const char kSendDownloadToCloudPref[] =
@@ -1027,6 +1028,7 @@
// Deprecated 12/2022.
registry->RegisterBooleanPref(kAutofillWalletImportStorageCheckboxState,
true);
+ registry->RegisterBooleanPref(kDeprecatedReadingListHasUnseenEntries, false);
// Deprecated 01/2023.
registry->RegisterBooleanPref(
@@ -2073,8 +2075,7 @@
profile_prefs->ClearPref(kAutofillAssistantTriggerScriptsIsFirstTimeUser);
// Added 12/2022.
- profile_prefs->ClearPref(
- reading_list::prefs::kDeprecatedReadingListHasUnseenEntries);
+ profile_prefs->ClearPref(kDeprecatedReadingListHasUnseenEntries);
// Added 12/2022.
profile_prefs->ClearPref(kAutofillWalletImportStorageCheckboxState);