Files
brave-core/components/speedreader/speedreader_pref_migration.cc
T
Brian R. BondyandSerg 7240ef2e2e Add top level toggle to enable/disable Speedreader (#30600)
* Add top level toggle to enable/disable Speedreader

This migrates away an old bad named feature for automatically using
speedreader for all sites.  The pref was wrongly named `enabled`.

This also adds a new preference for actually enabling/disabling the
feature.

* Fixes Android presubmit

---------

Co-authored-by: Serg <serg.zhukovsky@gmail.com>
2025-08-13 11:14:10 -04:00

35 lines
1.4 KiB
C++

/* Copyright (c) 2025 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */
#include "brave/components/speedreader/speedreader_pref_migration.h"
#include "brave/components/speedreader/speedreader_pref_names.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
namespace speedreader {
void RegisterProfilePrefsForMigration(PrefRegistrySimple* registry) {
// Legacy preference - keep for migration purposes only
registry->RegisterBooleanPref(kSpeedreaderPrefEnabledDeprecated, false);
}
void MigrateObsoleteProfilePrefs(PrefService* prefs) {
// Check if the deprecated pref has been explicitly set by a user
if (prefs->HasPrefPath(kSpeedreaderPrefEnabledDeprecated)) {
bool old_value = prefs->GetBoolean(kSpeedreaderPrefEnabledDeprecated);
// The old "enabled" pref controlled whether speedreader was enabled for
// all sites. Migrate only the all-sites preference - let the feature
// toggle use its default value (enabled).
prefs->SetBoolean(kSpeedreaderPrefEnabledForAllSites, old_value);
// Clear the deprecated preference
prefs->ClearPref(kSpeedreaderPrefEnabledDeprecated);
}
}
} // namespace speedreader