Skip to content

Commit

Permalink
CodeHealth: Avoid ListValue::Clear()
Browse files Browse the repository at this point in the history
Replace every occurrence with Value::ClearList().

Will follow up with a CL that actually removes ListValue::Clear() when
this one has landed.

Bug: 1187063
Change-Id: Iff16d0f893b7d549012069872de5ffe19a975c22
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3006068
Reviewed-by: Finnur Thorarinsson <finnur@chromium.org>
Reviewed-by: Michael Crouse <mcrouse@chromium.org>
Reviewed-by: Camille Lamy <clamy@chromium.org>
Reviewed-by: Xiaoqian Dai <xdai@chromium.org>
Reviewed-by: Mark Pearson <mpearson@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Marc Treib <treib@chromium.org>
Reviewed-by: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: Maksim Ivanov <emaxx@chromium.org>
Reviewed-by: Josh Karlin <jkarlin@chromium.org>
Reviewed-by: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: Alexander Alekseev <alemate@chromium.org>
Reviewed-by: Bruce Dawson <brucedawson@chromium.org>
Reviewed-by: Evan Liu <evliu@google.com>
Reviewed-by: Yuchen Liu <yucliu@chromium.org>
Commit-Queue: Morten Stenshorne <mstensho@chromium.org>
Cr-Commit-Position: refs/heads/master@{#900907}
  • Loading branch information
mstensho authored and Chromium LUCI CQ committed Jul 13, 2021
1 parent 494206e commit 03129fe
Show file tree
Hide file tree
Showing 42 changed files with 72 additions and 72 deletions.
2 changes: 1 addition & 1 deletion ash/display/display_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ void StoreDisplayTouchAssociations(PrefService* pref_service) {
void StoreExternalDisplayMirrorInfo(PrefService* pref_service) {
ListPrefUpdate update(pref_service, prefs::kExternalDisplayMirrorInfo);
base::ListValue* pref_data = update.Get();
pref_data->Clear();
pref_data->ClearList();
const std::set<int64_t>& external_display_mirror_info =
GetDisplayManager()->external_display_mirror_info();
for (const auto& id : external_display_mirror_info)
Expand Down
2 changes: 1 addition & 1 deletion ash/display/display_prefs_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class DisplayPrefsTest : public AshTestBase {
const std::set<int64_t>& external_display_mirror_info) {
ListPrefUpdate update(local_state(), prefs::kExternalDisplayMirrorInfo);
base::ListValue* pref_data = update.Get();
pref_data->Clear();
pref_data->ClearList();
for (const auto& id : external_display_mirror_info)
pref_data->Append(base::Value(base::NumberToString(id)));
}
Expand Down
4 changes: 2 additions & 2 deletions ash/wm/desks/desks_restore_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void UpdatePrimaryUserDeskNamesPrefs() {

ListPrefUpdate name_update(primary_user_prefs, prefs::kDesksNamesList);
base::ListValue* name_pref_data = name_update.Get();
name_pref_data->Clear();
name_pref_data->ClearList();

const auto& desks = DesksController::Get()->desks();
for (const auto& desk : desks) {
Expand Down Expand Up @@ -234,7 +234,7 @@ void UpdatePrimaryUserDeskMetricsPrefs() {
// Save per-desk metrics.
ListPrefUpdate metrics_update(primary_user_prefs, prefs::kDesksMetricsList);
base::ListValue* metrics_pref_data = metrics_update.Get();
metrics_pref_data->Clear();
metrics_pref_data->ClearList();

auto* desks_controller = DesksController::Get();
const auto& desks = desks_controller->desks();
Expand Down
2 changes: 1 addition & 1 deletion base/values_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ TEST(ValuesTest, ListDeletion) {
ListValue list;
list.Append(std::make_unique<Value>());
EXPECT_FALSE(list.GetList().empty());
list.Clear();
list.ClearList();
EXPECT_TRUE(list.GetList().empty());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void EasyUnlockKeyManager::DeviceDataListToRemoteDeviceList(
const AccountId& account_id,
const EasyUnlockDeviceKeyDataList& data_list,
base::ListValue* device_list) {
device_list->Clear();
device_list->ClearList();
for (size_t i = 0; i < data_list.size(); ++i) {
std::unique_ptr<base::DictionaryValue> device_dict(
new base::DictionaryValue);
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ash/login/users/chrome_user_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ void ChromeUserManagerImpl::RetrieveTrustedDevicePolicies() {
if (GetEphemeralUsersEnabled() && !IsUserLoggedIn()) {
ListPrefUpdate prefs_users_update(GetLocalState(),
user_manager::kRegularUsersPref);
prefs_users_update->Clear();
prefs_users_update->ClearList();
for (user_manager::UserList::iterator it = users_.begin();
it != users_.end();) {
const AccountId account_id = (*it)->GetAccountId();
Expand Down Expand Up @@ -1014,7 +1014,7 @@ bool ChromeUserManagerImpl::UpdateAndCleanUpDeviceLocalAccounts(
// us to clean up associated data if they disappear from policy.
ListPrefUpdate prefs_device_local_accounts_update(
GetLocalState(), kDeviceLocalAccountsWithSavedData);
prefs_device_local_accounts_update->Clear();
prefs_device_local_accounts_update->ClearList();
for (const auto& account : device_local_accounts)
prefs_device_local_accounts_update->AppendString(account.user_id);

Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/chrome_browser_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ StartupProfileInfo CreatePrimaryProfile(
ListPrefUpdate update(g_browser_process->local_state(),
prefs::kProfilesLastActive);
base::ListValue* profile_list = update.Get();
profile_list->Clear();
profile_list->ClearList();
}

StartupProfileInfo profile_info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ IN_PROC_BROWSER_TEST_F(DevToolsAndroidBridgeTest, DiscoveryListChanges) {
EXPECT_STREQ("somehost:2000", AllTargetsString(provider).c_str());

invocations = called;
list.Clear();
list.ClearList();
service->Set(prefs::kDevToolsTCPDiscoveryConfig, list);

EXPECT_LT(invocations, called);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateChoosePath) {
base::FilePath expected_file_path =
data_dir().AppendASCII("simple_with_popup.pem");
api::EntryPicker::SkipPickerAndAlwaysSelectPathForTest(&expected_file_path);
choose_args.Clear();
choose_args.ClearList();
choose_args.AppendString("FILE");
choose_args.AppendString("PEM");
function = new api::DeveloperPrivateChoosePathFunction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ LanguageSettingsPrivateGetLanguageListFunction::Run() {
std::move(spellcheck_languages));

// Build the language list.
language_list_->Clear();
language_list_->ClearList();
#if BUILDFLAG(IS_CHROMEOS_ASH)
const base::flat_set<std::string> allowed_ui_locales(GetAllowedLanguages(
Profile::FromBrowserContext(browser_context())->GetPrefs()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void TabCaptureRegistry::GetCapturedTabs(
base::ListValue* list_of_capture_info) const {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(list_of_capture_info);
list_of_capture_info->Clear();
list_of_capture_info->ClearList();
for (const std::unique_ptr<LiveRequest>& request : requests_) {
if (request->is_anonymous() || !request->is_verified() ||
request->extension_id() != extension_id)
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/extensions/api/tabs/tabs_event_router.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ bool WillDispatchTabCreatedEvent(WebContents* contents,
const Extension* extension,
Event* event,
const base::DictionaryValue* listener_filter) {
event->event_args->Clear();
event->event_args->ClearList();
ExtensionTabUtil::ScrubTabBehavior scrub_tab_behavior =
ExtensionTabUtil::GetScrubTabBehavior(extension, target_context,
contents);
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/extensions/api/tabs/windows_event_router.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ bool WillDispatchWindowFocusedEvent(
window_controller, extension, listener_filter);

if (cant_cross_incognito || !visible_to_listener) {
event->event_args->Clear();
event->event_args->ClearList();
event->event_args->AppendInteger(extension_misc::kUnknownWindowId);
} else {
event->event_args->Clear();
event->event_args->ClearList();
event->event_args->AppendInteger(window_id);
}
return true;
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/extensions/extension_management_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ TEST_F(ExtensionAdminPolicyTest, BlocklistedByDefault) {
blocklist.AppendString("*");
EXPECT_TRUE(BlocklistedByDefault(&blocklist));

blocklist.Clear();
blocklist.ClearList();
blocklist.AppendString("*");
EXPECT_TRUE(BlocklistedByDefault(&blocklist));
}
Expand Down Expand Up @@ -1171,7 +1171,7 @@ TEST_F(ExtensionAdminPolicyTest, UserMayLoadBlocklisted) {
blocklist.AppendString(extension_->id());
EXPECT_FALSE(UserMayLoad(&blocklist, nullptr, nullptr, nullptr,
extension_.get(), nullptr));
blocklist.Clear();
blocklist.ClearList();
blocklist.AppendString(extension_->id());
EXPECT_FALSE(UserMayLoad(&blocklist, nullptr, nullptr, nullptr,
extension_.get(), nullptr));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, SafeBrowsingWhitelistDomains) {
EXPECT_EQ("mydomain.net", canonicalized_domains[1]);

// Invalid domains will be skipped.
whitelist_domains.Clear();
whitelist_domains.ClearList();
whitelist_domains.AppendString(std::string("%EF%BF%BDzyx.com"));
policies.Set(key::kSafeBrowsingWhitelistDomains, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
Expand Down Expand Up @@ -195,7 +195,7 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, PasswordProtectionLoginURLs) {
EXPECT_EQ(GURL("https://mydomian.com/login.html"), login_urls[1]);

// Verify non-http/https schemes, or invalid URLs will be skipped.
login_url_values.Clear();
login_url_values.ClearList();
login_url_values.AppendString(std::string("invalid"));
login_url_values.AppendString(std::string("ftp://login.mydomain.com"));
policies.Set(key::kPasswordProtectionLoginURLs, POLICY_LEVEL_MANDATORY,
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/prefs/session_startup_pref.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void SessionStartupPref::SetStartupPref(PrefService* prefs,
ListPrefUpdate update(prefs, prefs::kURLsToRestoreOnStartup);
base::ListValue* url_pref_list = update.Get();
DCHECK(url_pref_list);
url_pref_list->Clear();
url_pref_list->ClearList();
for (size_t i = 0; i < pref.urls.size(); ++i) {
url_pref_list->Set(static_cast<int>(i),
std::make_unique<base::Value>(pref.urls[i].spec()));
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/profiles/profile_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2172,7 +2172,7 @@ void ProfileManager::SaveActiveProfiles() {
ListPrefUpdate update(local_state, prefs::kProfilesLastActive);
base::ListValue* profile_list = update.Get();

profile_list->Clear();
profile_list->ClearList();

// crbug.com/120112 -> several non-off-the-record profiles might have the same
// GetBaseName(). In that case, we cannot restore both
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ void SetAnalysisConnector(PrefService* prefs,
ListPrefUpdate settings_list(prefs, ConnectorPref(connector));
DCHECK(settings_list.Get());
if (!settings_list->GetList().empty())
settings_list->Clear();
settings_list->ClearList();

settings_list->Append(*base::JSONReader::Read(pref_value));
prefs->SetInteger(
Expand Down Expand Up @@ -453,7 +453,7 @@ void ClearAnalysisConnector(
enterprise_connectors::AnalysisConnector connector) {
ListPrefUpdate settings_list(prefs, ConnectorPref(connector));
DCHECK(settings_list.Get());
settings_list->Clear();
settings_list->ClearList();
prefs->ClearPref(ConnectorScopePref(connector));
}

Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/toolbar/app_menu_model_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ TEST_F(AppMenuModelTest, DisableSettingsItem) {
ListPrefUpdate update(TestingBrowserProcess::GetGlobal()->local_state(),
policy::policy_prefs::kSystemFeaturesDisableList);
base::ListValue* list = update.Get();
list->Clear();
list->ClearList();
}
EXPECT_TRUE(model.IsEnabledAt(options_index));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ TEST_F(SiteSettingsHelperTest, CheckExceptionOrder) {
map, std::move(extension_provider),
HostContentSettingsMap::CUSTOM_EXTENSION_PROVIDER);

exceptions.Clear();
exceptions.ClearList();
GetExceptionsForContentType(kContentType, &profile,
/*extension_registry=*/nullptr,
/*web_ui=*/nullptr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppManagerAppSuspensionBrowserTest,
ListPrefUpdate update(TestingBrowserProcess::GetGlobal()->local_state(),
policy::policy_prefs::kSystemFeaturesDisableList);
base::ListValue* list = update.Get();
list->Clear();
list->ClearList();
}
GetAppServiceProxy(browser()->profile())->FlushMojoCallsForTesting();
EXPECT_EQ(apps::mojom::Readiness::kReady, GetAppReadiness(*settings_id));
Expand Down Expand Up @@ -1430,7 +1430,7 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppManagerAppSuspensionBrowserTest,
ListPrefUpdate update(TestingBrowserProcess::GetGlobal()->local_state(),
policy::policy_prefs::kSystemFeaturesDisableList);
base::ListValue* list = update.Get();
list->Clear();
list->ClearList();
}
proxy->FlushMojoCallsForTesting();
EXPECT_EQ(apps::mojom::Readiness::kReady, GetAppReadiness(*settings_id));
Expand Down
2 changes: 1 addition & 1 deletion chrome/test/chromedriver/window_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1935,7 +1935,7 @@ Status ExecuteReleaseActions(Session* session,

session->input_cancel_list.clear();
session->input_state_table.Clear();
session->active_input_sources.Clear();
session->active_input_sources.ClearList();
session->mouse_position = WebPoint(0, 0);
session->click_count = 0;
session->mouse_click_timestamp = base::TimeTicks::Now();
Expand Down
2 changes: 1 addition & 1 deletion chromecast/crash/linux/synchronized_minidump_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ std::vector<std::unique_ptr<DumpInfo>> SynchronizedMinidumpManager::GetDumps() {

bool SynchronizedMinidumpManager::SetCurrentDumps(
const std::vector<std::unique_ptr<DumpInfo>>& dumps) {
dumps_->Clear();
dumps_->ClearList();

for (auto& dump : dumps)
dumps_->Append(dump->GetAsValue());
Expand Down
4 changes: 2 additions & 2 deletions chromeos/dbus/shill/fake_shill_manager_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ void FakeShillManagerClient::RemoveDevice(const std::string& device_path) {
}

void FakeShillManagerClient::ClearDevices() {
GetListProperty(shill::kDevicesProperty)->Clear();
GetListProperty(shill::kDevicesProperty)->ClearList();
CallNotifyObserversPropertyChanged(shill::kDevicesProperty);
}

Expand Down Expand Up @@ -623,7 +623,7 @@ void FakeShillManagerClient::RemoveManagerService(

void FakeShillManagerClient::ClearManagerServices() {
VLOG(1) << "ClearManagerServices";
GetListProperty(shill::kServiceCompleteListProperty)->Clear();
GetListProperty(shill::kServiceCompleteListProperty)->ClearList();
CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty);
}

Expand Down
2 changes: 1 addition & 1 deletion chromeos/network/network_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ TEST_F(NetworkUtilTest, ParseScanResults) {
EXPECT_FALSE(ParseCellularScanResults(list, &scan_results));

// Scan result has no network id.
list.Clear();
list.ClearList();
auto dict_value = std::make_unique<base::DictionaryValue>();
dict_value->SetString(shill::kStatusProperty, "available");
list.Append(std::move(dict_value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ TEST_F(
InitWithExistingPrefs_MigrateDeprecateBooleansFromPrefsToSoftwareFeature) {
ListPrefUpdate update_clear(&pref_service_,
prefs::kCryptAuthDeviceSyncUnlockKeys);
update_clear.Get()->Clear();
update_clear.Get()->ClearList();

// Simulate a deprecated device being persisted to prefs.
auto device_dictionary = std::make_unique<base::DictionaryValue>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class DataReductionProxyCompressionStats::DailyContentLengthUpdate {
} else if (days_since_last_update < -1) {
// Erase all entries if the system went backwards in time by more than
// a day.
update_->Clear();
update_->ClearList();

days_since_last_update = kNumDaysInHistory;
}
Expand Down Expand Up @@ -464,8 +464,8 @@ void DataReductionProxyCompressionStats::ResetStatistics() {
GetList(prefs::kDailyHttpOriginalContentLength);
base::ListValue* received_update =
GetList(prefs::kDailyHttpReceivedContentLength);
original_update->Clear();
received_update->Clear();
original_update->ClearList();
received_update->ClearList();
for (size_t i = 0; i < kNumDaysInHistory; ++i) {
original_update->AppendString(base::NumberToString(0));
received_update->AppendString(base::NumberToString(0));
Expand Down Expand Up @@ -610,7 +610,7 @@ void DataReductionProxyCompressionStats::ClearDataSavingStatistics(

for (auto iter = list_pref_map_.begin(); iter != list_pref_map_.end();
++iter) {
iter->second->Clear();
iter->second->ClearList();
}

RecordSavingsClearedMetric(reason);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class DataReductionProxyCompressionStatsTest : public testing::Test {
i, std::make_unique<base::Value>(base::NumberToString(i)));
}

received_daily_content_length_list->Clear();
received_daily_content_length_list->ClearList();
for (size_t i = 0; i < kNumDaysInHistory / 2; ++i) {
received_daily_content_length_list->AppendString(base::NumberToString(i));
}
Expand Down
6 changes: 3 additions & 3 deletions components/flags_ui/pref_service_flags_storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ bool PrefServiceFlagsStorage::SetFlags(const std::set<std::string>& flags) {
ListPrefUpdate update(prefs_, prefs::kAboutFlagsEntries);
base::ListValue* experiments_list = update.Get();

experiments_list->Clear();
for (auto it = flags.begin(); it != flags.end(); ++it) {
experiments_list->AppendString(*it);
experiments_list->ClearList();
for (const auto& item : flags) {
experiments_list->AppendString(item);
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion components/metrics/unsent_log_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ void UnsentLogStore::TrimLogs() {
}

void UnsentLogStore::WriteLogsToPrefList(base::ListValue* list_value) const {
list_value->Clear();
list_value->ClearList();

base::HistogramBase::Count unsent_samples_count = 0;
size_t unsent_persisted_size = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ TEST_F(MutableProfileOAuth2TokenServiceDelegateTest, GaiaIdMigration) {
AccountTrackerService::MIGRATION_NOT_STARTED);

ListPrefUpdate update(&pref_service_, prefs::kAccountInfo);
update->Clear();
update->ClearList();
auto dict = std::make_unique<base::DictionaryValue>();
dict->SetString("account_id", email);
dict->SetString("email", email);
Expand Down Expand Up @@ -1162,7 +1162,7 @@ TEST_F(MutableProfileOAuth2TokenServiceDelegateTest,
AccountTrackerService::MIGRATION_NOT_STARTED);

ListPrefUpdate update(&pref_service_, prefs::kAccountInfo);
update->Clear();
update->ClearList();
auto dict = std::make_unique<base::DictionaryValue>();
dict->SetString("account_id", email1);
dict->SetString("email", email1);
Expand Down
Loading

0 comments on commit 03129fe

Please sign in to comment.