Migrate browser/ash to new list pref update class.
ListPrefUpdate is now deprecated, in favor of ScopedListPrefUpdate,
which only expose Value::List to discourage use of other APIs to
manipulate lists, which are all deprecated.
Bug: 1362719
Change-Id: I18a46f35ad7b102f78ec41bd93254f0b158b083a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3904665
Commit-Queue: Matt Menke <mmenke@chromium.org>
Reviewed-by: Hidehiko Abe <hidehiko@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1049206}
diff --git a/chrome/browser/ash/child_accounts/time_limits/app_activity_registry.cc b/chrome/browser/ash/child_accounts/time_limits/app_activity_registry.cc
index 4545a3d..9244ab17 100644
--- a/chrome/browser/ash/child_accounts/time_limits/app_activity_registry.cc
+++ b/chrome/browser/ash/child_accounts/time_limits/app_activity_registry.cc
@@ -626,13 +626,13 @@
void AppActivityRegistry::SaveAppActivity() {
{
- ListPrefUpdate update(pref_service_, prefs::kPerAppTimeLimitsAppActivities);
- base::Value* list_value = update.Get();
+ ScopedListPrefUpdate update(pref_service_,
+ prefs::kPerAppTimeLimitsAppActivities);
+ base::Value::List& list = update.Get();
const base::Time now = base::Time::Now();
- base::Value::ListView list_view = list_value->GetListDeprecated();
- for (base::Value& entry : list_view) {
+ for (base::Value& entry : list) {
absl::optional<AppId> app_id = policy::AppIdFromAppInfoDict(entry);
DCHECK(app_id.has_value());
@@ -652,7 +652,7 @@
const PersistedAppInfo info = GetPersistedAppInfoForApp(app_id, now);
base::Value value(base::Value::Type::DICTIONARY);
info.UpdateAppActivityPreference(&value, /* replace */ false);
- list_value->Append(std::move(value));
+ list.Append(std::move(value));
}
newly_installed_apps_.clear();
}
@@ -697,11 +697,10 @@
}
void AppActivityRegistry::CleanRegistry(base::Time timestamp) {
- ListPrefUpdate update(pref_service_, prefs::kPerAppTimeLimitsAppActivities);
+ ScopedListPrefUpdate update(pref_service_,
+ prefs::kPerAppTimeLimitsAppActivities);
- base::Value* list_value = update.Get();
-
- base::Value::List& list = list_value->GetList();
+ base::Value::List& list = update.Get();
for (size_t index = 0; index < list.size();) {
base::Value& entry = list[index];
diff --git a/chrome/browser/ash/crosapi/browser_util.cc b/chrome/browser/ash/crosapi/browser_util.cc
index 6300251c..b9929e5 100644
--- a/chrome/browser/ash/crosapi/browser_util.cc
+++ b/chrome/browser/ash/crosapi/browser_util.cc
@@ -1048,18 +1048,17 @@
void SetGotoFilesClicked(PrefService* local_state,
const std::string& user_id_hash) {
- ListPrefUpdate update(local_state, kGotoFilesPref);
- base::Value* list = update.Get();
+ ScopedListPrefUpdate update(local_state, kGotoFilesPref);
+ base::Value::List& list = update.Get();
base::Value user_id_hash_value(user_id_hash);
- if (!base::Contains(list->GetList(), user_id_hash_value))
- list->GetList().Append(std::move(user_id_hash_value));
+ if (!base::Contains(list, user_id_hash_value))
+ list.Append(std::move(user_id_hash_value));
}
void ClearGotoFilesClicked(PrefService* local_state,
const std::string& user_id_hash) {
- ListPrefUpdate update(local_state, kGotoFilesPref);
- base::Value* list = update.Get();
- list->GetList().EraseValue(base::Value(user_id_hash));
+ ScopedListPrefUpdate update(local_state, kGotoFilesPref);
+ update->EraseValue(base::Value(user_id_hash));
}
bool WasGotoFilesClicked(PrefService* local_state,
diff --git a/chrome/browser/ash/crostini/crostini_port_forwarder.cc b/chrome/browser/ash/crostini/crostini_port_forwarder.cc
index c6a075f..e498aec4b 100644
--- a/chrome/browser/ash/crostini/crostini_port_forwarder.cc
+++ b/chrome/browser/ash/crostini/crostini_port_forwarder.cc
@@ -93,8 +93,9 @@
void CrostiniPortForwarder::AddNewPortPreference(const PortRuleKey& key,
const std::string& label) {
PrefService* pref_service = profile_->GetPrefs();
- ListPrefUpdate update(pref_service, crostini::prefs::kCrostiniPortForwarding);
- base::Value::List& all_ports = update.Get()->GetList();
+ ScopedListPrefUpdate update(pref_service,
+ crostini::prefs::kCrostiniPortForwarding);
+ base::Value::List& all_ports = update.Get();
base::Value::Dict new_port_metadata;
new_port_metadata.Set(kPortNumberKey, key.port_number);
new_port_metadata.Set(kPortProtocolKey, static_cast<int>(key.protocol_type));
@@ -107,8 +108,9 @@
bool CrostiniPortForwarder::RemovePortPreference(const PortRuleKey& key) {
PrefService* pref_service = profile_->GetPrefs();
- ListPrefUpdate update(pref_service, crostini::prefs::kCrostiniPortForwarding);
- base::Value::List& update_list = update->GetList();
+ ScopedListPrefUpdate update(pref_service,
+ crostini::prefs::kCrostiniPortForwarding);
+ base::Value::List& update_list = update.Get();
auto it = base::ranges::find_if(update_list, [&key, this](const auto& dict) {
return MatchPortRuleDict(dict, key);
});
@@ -356,8 +358,9 @@
void CrostiniPortForwarder::RemoveAllPorts(
const guest_os::GuestId& container_id) {
PrefService* pref_service = profile_->GetPrefs();
- ListPrefUpdate update(pref_service, crostini::prefs::kCrostiniPortForwarding);
- update->GetList().EraseIf([&container_id, this](const auto& dict) {
+ ScopedListPrefUpdate update(pref_service,
+ crostini::prefs::kCrostiniPortForwarding);
+ update->EraseIf([&container_id, this](const auto& dict) {
return MatchPortRuleContainerId(dict, container_id);
});
diff --git a/chrome/browser/ash/login/login_manager_test.cc b/chrome/browser/ash/login/login_manager_test.cc
index 3a80ecf3..c1621e1430 100644
--- a/chrome/browser/ash/login/login_manager_test.cc
+++ b/chrome/browser/ash/login/login_manager_test.cc
@@ -61,9 +61,10 @@
}
void LoginManagerTest::RegisterUser(const AccountId& account_id) {
- ListPrefUpdate users_pref(g_browser_process->local_state(), "LoggedInUsers");
+ ScopedListPrefUpdate users_pref(g_browser_process->local_state(),
+ "LoggedInUsers");
base::Value email_value(account_id.GetUserEmail());
- if (!base::Contains(users_pref->GetListDeprecated(), email_value))
+ if (!base::Contains(users_pref.Get(), email_value))
users_pref->Append(std::move(email_value));
if (user_manager::UserManager::IsInitialized()) {
user_manager::KnownUser(g_browser_process->local_state())
diff --git a/chrome/browser/ash/login/test/login_manager_mixin.cc b/chrome/browser/ash/login/test/login_manager_mixin.cc
index 3860934..e237bb05 100644
--- a/chrome/browser/ash/login/test/login_manager_mixin.cc
+++ b/chrome/browser/ash/login/test/login_manager_mixin.cc
@@ -128,10 +128,10 @@
void LoginManagerMixin::SetUpLocalState() {
for (const auto& user : initial_users_) {
- ListPrefUpdate users_pref(g_browser_process->local_state(),
- "LoggedInUsers");
+ ScopedListPrefUpdate users_pref(g_browser_process->local_state(),
+ "LoggedInUsers");
base::Value email_value(user.account_id.GetUserEmail());
- if (!base::Contains(users_pref->GetListDeprecated(), email_value))
+ if (!base::Contains(users_pref.Get(), email_value))
users_pref->Append(std::move(email_value));
DictionaryPrefUpdate user_type_update(g_browser_process->local_state(),
diff --git a/chrome/browser/ash/login/users/chrome_user_manager_impl.cc b/chrome/browser/ash/login/users/chrome_user_manager_impl.cc
index ca9fdaf2..282228d 100644
--- a/chrome/browser/ash/login/users/chrome_user_manager_impl.cc
+++ b/chrome/browser/ash/login/users/chrome_user_manager_impl.cc
@@ -764,9 +764,9 @@
// If ephemeral users are enabled and we are on the login screen, take this
// opportunity to clean up by removing all regular users except the owner.
if (GetEphemeralUsersEnabled() && !IsUserLoggedIn()) {
- ListPrefUpdate prefs_users_update(GetLocalState(),
- user_manager::kRegularUsersPref);
- prefs_users_update->ClearList();
+ ScopedListPrefUpdate prefs_users_update(GetLocalState(),
+ user_manager::kRegularUsersPref);
+ prefs_users_update->clear();
for (user_manager::UserList::iterator it = users_.begin();
it != users_.end();) {
const AccountId account_id = (*it)->GetAccountId();
@@ -1018,9 +1018,9 @@
// will be loaded in LoadDeviceLocalAccounts() on the next reboot regardless
// of whether they still exist in kAccountsPrefDeviceLocalAccounts, allowing
// us to clean up associated data if they disappear from policy.
- ListPrefUpdate prefs_device_local_accounts_update(
+ ScopedListPrefUpdate prefs_device_local_accounts_update(
GetLocalState(), kDeviceLocalAccountsWithSavedData);
- prefs_device_local_accounts_update->ClearList();
+ prefs_device_local_accounts_update->clear();
for (const auto& account : device_local_accounts)
prefs_device_local_accounts_update->Append(account.user_id);
@@ -1283,15 +1283,15 @@
}
void ChromeUserManagerImpl::AddReportingUser(const AccountId& account_id) {
- ListPrefUpdate users_update(GetLocalState(), ::prefs::kReportingUsers);
+ ScopedListPrefUpdate users_update(GetLocalState(), ::prefs::kReportingUsers);
base::Value email_value(account_id.GetUserEmail());
- if (!base::Contains(users_update->GetListDeprecated(), email_value))
+ if (!base::Contains(users_update.Get(), email_value))
users_update->Append(std::move(email_value));
}
void ChromeUserManagerImpl::RemoveReportingUser(const AccountId& account_id) {
- ListPrefUpdate users_update(GetLocalState(), ::prefs::kReportingUsers);
- base::Value::List& update_list = users_update->GetList();
+ ScopedListPrefUpdate users_update(GetLocalState(), ::prefs::kReportingUsers);
+ base::Value::List& update_list = users_update.Get();
auto it =
std::find(update_list.begin(), update_list.end(),
base::Value(FullyCanonicalize(account_id.GetUserEmail())));
diff --git a/chrome/browser/ash/login/users/supervised_user_manager_impl.cc b/chrome/browser/ash/login/users/supervised_user_manager_impl.cc
index 902725d..41fdf2d4 100644
--- a/chrome/browser/ash/login/users/supervised_user_manager_impl.cc
+++ b/chrome/browser/ash/login/users/supervised_user_manager_impl.cc
@@ -252,8 +252,8 @@
void SupervisedUserManagerImpl::RemoveNonCryptohomeData(
const std::string& user_id) {
PrefService* prefs = g_browser_process->local_state();
- ListPrefUpdate prefs_new_users_update(prefs, kSupervisedUsersFirstRun);
- prefs_new_users_update->GetList().EraseValue(base::Value(user_id));
+ ScopedListPrefUpdate prefs_new_users_update(prefs, kSupervisedUsersFirstRun);
+ prefs_new_users_update->EraseValue(base::Value(user_id));
CleanPref(user_id, kSupervisedUserSyncId);
CleanPref(user_id, kSupervisedUserManagers);
@@ -274,9 +274,9 @@
}
bool SupervisedUserManagerImpl::CheckForFirstRun(const std::string& user_id) {
- ListPrefUpdate prefs_new_users_update(g_browser_process->local_state(),
- kSupervisedUsersFirstRun);
- return prefs_new_users_update->GetList().EraseValue(base::Value(user_id));
+ ScopedListPrefUpdate prefs_new_users_update(g_browser_process->local_state(),
+ kSupervisedUsersFirstRun);
+ return prefs_new_users_update->EraseValue(base::Value(user_id));
}
} // namespace ash
diff --git a/chrome/browser/ash/policy/affiliation/affiliation_test_helper.cc b/chrome/browser/ash/policy/affiliation/affiliation_test_helper.cc
index d91a147..9573d317 100644
--- a/chrome/browser/ash/policy/affiliation/affiliation_test_helper.cc
+++ b/chrome/browser/ash/policy/affiliation/affiliation_test_helper.cc
@@ -168,9 +168,10 @@
// static
void AffiliationTestHelper::PreLoginUser(const AccountId& account_id) {
- ListPrefUpdate users_pref(g_browser_process->local_state(), "LoggedInUsers");
+ ScopedListPrefUpdate users_pref(g_browser_process->local_state(),
+ "LoggedInUsers");
base::Value email_value(account_id.GetUserEmail());
- if (!base::Contains(users_pref->GetListDeprecated(), email_value))
+ if (!base::Contains(users_pref.Get(), email_value))
users_pref->Append(std::move(email_value));
user_manager::KnownUser(g_browser_process->local_state())
diff --git a/chrome/browser/ash/policy/dlp/data_transfer_dlp_controller_ash_browsertest.cc b/chrome/browser/ash/policy/dlp/data_transfer_dlp_controller_ash_browsertest.cc
index 5f27645..6179631 100644
--- a/chrome/browser/ash/policy/dlp/data_transfer_dlp_controller_ash_browsertest.cc
+++ b/chrome/browser/ash/policy/dlp/data_transfer_dlp_controller_ash_browsertest.cc
@@ -245,8 +245,8 @@
IN_PROC_BROWSER_TEST_F(DataTransferDlpAshBrowserTest, MAYBE_BlockComponent) {
SetupCrostini();
{
- ListPrefUpdate update(g_browser_process->local_state(),
- policy_prefs::kDlpRulesList);
+ ScopedListPrefUpdate update(g_browser_process->local_state(),
+ policy_prefs::kDlpRulesList);
base::Value src_urls(base::Value::Type::LIST);
src_urls.Append(kMailUrl);
@@ -307,8 +307,8 @@
SetupCrostini();
{
- ListPrefUpdate update(g_browser_process->local_state(),
- policy_prefs::kDlpRulesList);
+ ScopedListPrefUpdate update(g_browser_process->local_state(),
+ policy_prefs::kDlpRulesList);
base::Value rule(base::Value::Type::DICTIONARY);
base::Value src_urls(base::Value::Type::DICTIONARY);
base::Value src_urls_list(base::Value::Type::LIST);
diff --git a/chrome/browser/ash/smb_client/smb_persisted_share_registry.cc b/chrome/browser/ash/smb_client/smb_persisted_share_registry.cc
index 6399a1a..c18f4a5 100644
--- a/chrome/browser/ash/smb_client/smb_persisted_share_registry.cc
+++ b/chrome/browser/ash/smb_client/smb_persisted_share_registry.cc
@@ -97,10 +97,10 @@
: profile_(profile) {}
void SmbPersistedShareRegistry::Save(const SmbShareInfo& share) {
- ListPrefUpdate pref(profile_->GetPrefs(),
- prefs::kNetworkFileSharesSavedShares);
+ ScopedListPrefUpdate pref(profile_->GetPrefs(),
+ prefs::kNetworkFileSharesSavedShares);
- base::Value::ListView share_list = pref->GetListDeprecated();
+ base::Value::List& share_list = pref.Get();
for (auto it = share_list.begin(); it != share_list.end(); ++it) {
if (GetStringValue(*it, kShareUrlKey) == share.share_url().ToString()) {
*it = ShareToDict(share);
@@ -113,10 +113,10 @@
}
void SmbPersistedShareRegistry::Delete(const SmbUrl& share_url) {
- ListPrefUpdate pref(profile_->GetPrefs(),
- prefs::kNetworkFileSharesSavedShares);
+ ScopedListPrefUpdate pref(profile_->GetPrefs(),
+ prefs::kNetworkFileSharesSavedShares);
- base::Value::List& list_update = pref->GetList();
+ base::Value::List& list_update = pref.Get();
for (auto it = list_update.begin(); it != list_update.end(); ++it) {
if (GetStringValue(*it, kShareUrlKey) == share_url.ToString()) {
list_update.erase(it);
diff --git a/chrome/browser/ash/system_web_apps/system_web_app_manager_browsertest.cc b/chrome/browser/ash/system_web_apps/system_web_app_manager_browsertest.cc
index 638cbaf..c3e05a7 100644
--- a/chrome/browser/ash/system_web_apps/system_web_app_manager_browsertest.cc
+++ b/chrome/browser/ash/system_web_apps/system_web_app_manager_browsertest.cc
@@ -1426,10 +1426,10 @@
.GetAppIdForSystemApp(SystemWebAppType::SETTINGS)
.has_value());
{
- ListPrefUpdate update(TestingBrowserProcess::GetGlobal()->local_state(),
- policy::policy_prefs::kSystemFeaturesDisableList);
- base::Value* list = update.Get();
- list->Append(static_cast<int>(policy::SystemFeature::kOsSettings));
+ ScopedListPrefUpdate update(
+ TestingBrowserProcess::GetGlobal()->local_state(),
+ policy::policy_prefs::kSystemFeaturesDisableList);
+ update->Append(static_cast<int>(policy::SystemFeature::kOsSettings));
}
WaitForTestSystemAppInstall();
absl::optional<web_app::AppId> settings_id =
@@ -1441,10 +1441,10 @@
GetAppIconKey(*settings_id)->icon_effects);
{
- ListPrefUpdate update(TestingBrowserProcess::GetGlobal()->local_state(),
- policy::policy_prefs::kSystemFeaturesDisableList);
- base::Value* list = update.Get();
- list->ClearList();
+ ScopedListPrefUpdate update(
+ TestingBrowserProcess::GetGlobal()->local_state(),
+ policy::policy_prefs::kSystemFeaturesDisableList);
+ update->clear();
}
EXPECT_EQ(apps::Readiness::kReady, GetAppReadiness(*settings_id));
EXPECT_FALSE(apps::IconEffects::kBlocked &
@@ -1462,10 +1462,10 @@
EXPECT_EQ(apps::Readiness::kReady, GetAppReadiness(*settings_id));
{
- ListPrefUpdate update(TestingBrowserProcess::GetGlobal()->local_state(),
- policy::policy_prefs::kSystemFeaturesDisableList);
- base::Value* list = update.Get();
- list->Append(static_cast<int>(policy::SystemFeature::kOsSettings));
+ ScopedListPrefUpdate update(
+ TestingBrowserProcess::GetGlobal()->local_state(),
+ policy::policy_prefs::kSystemFeaturesDisableList);
+ update->Append(static_cast<int>(policy::SystemFeature::kOsSettings));
}
EXPECT_EQ(apps::Readiness::kDisabledByPolicy, GetAppReadiness(*settings_id));
@@ -1473,10 +1473,10 @@
GetAppIconKey(*settings_id)->icon_effects);
{
- ListPrefUpdate update(TestingBrowserProcess::GetGlobal()->local_state(),
- policy::policy_prefs::kSystemFeaturesDisableList);
- base::Value* list = update.Get();
- list->ClearList();
+ ScopedListPrefUpdate update(
+ TestingBrowserProcess::GetGlobal()->local_state(),
+ policy::policy_prefs::kSystemFeaturesDisableList);
+ update->clear();
}
EXPECT_EQ(apps::Readiness::kReady, GetAppReadiness(*settings_id));
EXPECT_FALSE(apps::IconEffects::kBlocked &
diff --git a/chrome/browser/ash/web_applications/scanning_app_integration_browsertest.cc b/chrome/browser/ash/web_applications/scanning_app_integration_browsertest.cc
index 8e65bcd..0ea4136f 100644
--- a/chrome/browser/ash/web_applications/scanning_app_integration_browsertest.cc
+++ b/chrome/browser/ash/web_applications/scanning_app_integration_browsertest.cc
@@ -33,10 +33,10 @@
// set to be disabled via the SystemFeaturesDisableList policy.
IN_PROC_BROWSER_TEST_P(ScanningAppIntegrationTest, ScanningAppDisabled) {
{
- ListPrefUpdate update(TestingBrowserProcess::GetGlobal()->local_state(),
- policy::policy_prefs::kSystemFeaturesDisableList);
- base::Value* list = update.Get();
- list->Append(static_cast<int>(policy::SystemFeature::kScanning));
+ ScopedListPrefUpdate update(
+ TestingBrowserProcess::GetGlobal()->local_state(),
+ policy::policy_prefs::kSystemFeaturesDisableList);
+ update->Append(static_cast<int>(policy::SystemFeature::kScanning));
}
ASSERT_FALSE(GetManager()
diff --git a/chrome/browser/ash/web_applications/settings_app_integration_browsertest.cc b/chrome/browser/ash/web_applications/settings_app_integration_browsertest.cc
index 1fbf871..76d8cb9 100644
--- a/chrome/browser/ash/web_applications/settings_app_integration_browsertest.cc
+++ b/chrome/browser/ash/web_applications/settings_app_integration_browsertest.cc
@@ -31,10 +31,10 @@
// via SystemFeaturesDisableList policy, but doesn't launch.
IN_PROC_BROWSER_TEST_P(SettingsAppIntegrationTest, SettingsAppDisabled) {
{
- ListPrefUpdate update(TestingBrowserProcess::GetGlobal()->local_state(),
- policy::policy_prefs::kSystemFeaturesDisableList);
- base::Value* list = update.Get();
- list->Append(static_cast<int>(policy::SystemFeature::kOsSettings));
+ ScopedListPrefUpdate update(
+ TestingBrowserProcess::GetGlobal()->local_state(),
+ policy::policy_prefs::kSystemFeaturesDisableList);
+ update->Append(static_cast<int>(policy::SystemFeature::kOsSettings));
}
ASSERT_FALSE(GetManager()