Skip to content

Commit

Permalink
Migrate base::Value::GetList() to base::Value::GetListDeprecated(): 1/N.
Browse files Browse the repository at this point in the history
GetList() will be reimplemented in a future CL with an updated
signature, so existing uses need to be renamed out of the way.

Unlike TakeList() and TakeDict(), GetList() is used quite widely. This
CL migrates a number of uses using the following set of automated steps:

sed -i "s|->GetList()|->GetListDeprecated()|g" \
    $(git gs "GetList()" --name-only)
git checkout -- base/values_unittest.cc third_party/dom_distiller_js
git cl format

Bug: 1291666
Change-Id: I1b7a92fcb4874e7afb82d4bd092c1c9de2cc3d05
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3430698
Reviewed-by: danakj chromium <danakj@chromium.org>
Owners-Override: danakj chromium <danakj@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#966487}
  • Loading branch information
zetafunction authored and Chromium LUCI CQ committed Feb 2, 2022
1 parent c8cd30c commit 354945d
Show file tree
Hide file tree
Showing 983 changed files with 3,996 additions and 3,548 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void AssertOnDemandRequest(bool on_demand, std::string post_data) {
ASSERT_TRUE(root);
const auto* request = root->FindKey("request");
ASSERT_TRUE(request);
const auto& app = request->FindKey("app")->GetList()[0];
const auto& app = request->FindKey("app")->GetListDeprecated()[0];
if (on_demand) {
EXPECT_EQ("ondemand", app.FindKey("installsource")->GetString());
} else {
Expand Down
4 changes: 2 additions & 2 deletions ash/components/arc/arc_features_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ absl::optional<ArcFeatures> ParseFeaturesJson(base::StringPiece input_json) {
LOG(ERROR) << "No feature list in JSON.";
return absl::nullopt;
}
for (auto& feature_item : feature_list->GetList()) {
for (auto& feature_item : feature_list->GetListDeprecated()) {
const base::Value* feature_name =
feature_item.FindKeyOfType("name", base::Value::Type::STRING);
const base::Value* feature_version =
Expand All @@ -71,7 +71,7 @@ absl::optional<ArcFeatures> ParseFeaturesJson(base::StringPiece input_json) {
LOG(ERROR) << "No unavailable feature list in JSON.";
return absl::nullopt;
}
for (auto& feature_item : unavailable_feature_list->GetList()) {
for (auto& feature_item : unavailable_feature_list->GetListDeprecated()) {
if (!feature_item.is_string()) {
LOG(ERROR) << "Item in the unavailable feature list is not a string.";
return absl::nullopt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void SnapshotHoursPolicyService::UpdatePolicy() {
if (!intervals)
return;

for (const auto& entry : intervals->GetList()) {
for (const auto& entry : intervals->GetListDeprecated()) {
if (!entry.is_dict())
continue;
auto interval =
Expand Down
4 changes: 2 additions & 2 deletions ash/components/arc/net/arc_net_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ void AddIpConfiguration(arc::mojom::NetworkConfiguration* network,
// the kStaticIPConfigProperty object will be empty except for DNS addresses.
if (const auto* dns_list =
shill_ipconfig->FindListKey(shill::kNameServersProperty)) {
for (const auto& dns_value : dns_list->GetList()) {
for (const auto& dns_value : dns_list->GetListDeprecated()) {
const std::string& dns = dns_value.GetString();
if (dns.empty())
continue;
Expand All @@ -264,7 +264,7 @@ void AddIpConfiguration(arc::mojom::NetworkConfiguration* network,
if (const auto* domains =
shill_ipconfig->FindKey(shill::kSearchDomainsProperty)) {
if (domains->is_list()) {
for (const auto& domain : domains->GetList())
for (const auto& domain : domains->GetListDeprecated())
network->host_search_domains->push_back(domain.GetString());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ bool ArcVolumeMounterBridge::IsVisibleToAndroidApps(
const std::string& uuid) const {
const base::Value* uuid_list =
pref_service_->GetList(prefs::kArcVisibleExternalStorages);
for (auto& value : uuid_list->GetList()) {
for (auto& value : uuid_list->GetListDeprecated()) {
if (value.is_string() && value.GetString() == uuid)
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion ash/components/login/auth/sync_trusted_vault_keys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ std::vector<T> ParseList(
}

std::vector<T> parsed_list;
for (const base::Value& list_entry : list->GetList()) {
for (const base::Value& list_entry : list->GetListDeprecated()) {
absl::optional<T> parsed_entry = entry_parser.Run(list_entry);
if (parsed_entry.has_value()) {
parsed_list.push_back(std::move(*parsed_entry));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void RecentAppsInteractionHandlerImpl::
PA_LOG(INFO) << "LoadRecentAppMetadataListFromPref";
const base::Value* recent_apps_history_pref =
pref_service_->GetList(prefs::kRecentAppsHistory);
for (const auto& value : recent_apps_history_pref->GetList()) {
for (const auto& value : recent_apps_history_pref->GetListDeprecated()) {
DCHECK(value.is_dict());
recent_app_metadata_list_.emplace_back(
Notification::AppMetadata::FromValue(value),
Expand Down
2 changes: 1 addition & 1 deletion ash/components/tether/persistent_host_scan_cache_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ PersistentHostScanCacheImpl::GetStoredCacheEntries() {

std::unordered_map<std::string, HostScanCacheEntry> entries;
std::unordered_set<std::string> ids_processed_so_far;
for (auto& cache_entry_value : cache_entry_list->GetList()) {
for (auto& cache_entry_value : cache_entry_list->GetListDeprecated()) {
const base::DictionaryValue* cache_entry_dict;

if (!cache_entry_value.GetAsDictionary(&cache_entry_dict)) {
Expand Down
4 changes: 2 additions & 2 deletions ash/components/tether/tether_host_response_recorder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bool TetherHostResponseRecorder::AddRecentResponse(
const std::string& device_id,
const std::string& pref_name) {
const base::Value* ids = pref_service_->GetList(pref_name);
base::Value::ConstListView ids_list = ids->GetList();
base::Value::ConstListView ids_list = ids->GetListDeprecated();

std::string first_device_id_in_list;
if (!ids_list.empty() && ids_list[0].is_string())
Expand Down Expand Up @@ -116,7 +116,7 @@ std::vector<std::string> TetherHostResponseRecorder::GetDeviceIdsForPref(
if (!ids)
return device_ids;

for (const auto& entry : ids->GetList()) {
for (const auto& entry : ids->GetListDeprecated()) {
if (entry.is_string())
device_ids.push_back(entry.GetString());
}
Expand Down
5 changes: 3 additions & 2 deletions ash/display/display_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ void LoadExternalDisplayMirrorInfo(PrefService* local_state) {
const base::Value* pref_data =
local_state->Get(prefs::kExternalDisplayMirrorInfo);
std::set<int64_t> external_display_mirror_info;
for (const auto& it : pref_data->GetList()) {
for (const auto& it : pref_data->GetListDeprecated()) {
const std::string* display_id_str = it.GetIfString();
if (!display_id_str)
continue;
Expand Down Expand Up @@ -452,7 +452,8 @@ void LoadDisplayMixedMirrorModeParams(PrefService* local_state) {

DCHECK(mirroring_destination_ids_value->is_list());
display::DisplayIdList mirroring_destination_ids;
for (const auto& entry : mirroring_destination_ids_value->GetList()) {
for (const auto& entry :
mirroring_destination_ids_value->GetListDeprecated()) {
DCHECK(entry.is_string());
int64_t id;
if (!base::StringToInt64(entry.GetString(), &id))
Expand Down
60 changes: 33 additions & 27 deletions ash/display/display_prefs_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class DisplayPrefsTest : public AshTestBase {
const auto* mirror_ids = prefs->FindListKey("mirroring_destination_ids");
ASSERT_TRUE(mirror_ids);
display::DisplayIdList pref_dest_ids;
for (const auto& value : mirror_ids->GetList()) {
for (const auto& value : mirror_ids->GetListDeprecated()) {
int64_t id;
EXPECT_TRUE(base::StringToInt64(value.GetString(), &id));
pref_dest_ids.push_back(id);
Expand All @@ -287,7 +287,7 @@ class DisplayPrefsTest : public AshTestBase {
local_state()->Get(prefs::kExternalDisplayMirrorInfo);
ASSERT_TRUE(prefs);
std::set<int64_t> read_ids;
for (const auto& value : prefs->GetList()) {
for (const auto& value : prefs->GetListDeprecated()) {
int64_t id;
EXPECT_TRUE(base::StringToInt64(value.GetString(), &id));
read_ids.insert(id);
Expand Down Expand Up @@ -463,7 +463,7 @@ TEST_F(DisplayPrefsTest, BasicStores) {

const base::Value* external_display_mirror_info =
local_state()->GetList(prefs::kExternalDisplayMirrorInfo);
EXPECT_EQ(0U, external_display_mirror_info->GetList().size());
EXPECT_EQ(0U, external_display_mirror_info->GetListDeprecated().size());

const base::Value* properties =
local_state()->GetDictionary(prefs::kDisplayProperties);
Expand Down Expand Up @@ -595,10 +595,10 @@ TEST_F(DisplayPrefsTest, BasicStores) {

external_display_mirror_info =
local_state()->GetList(prefs::kExternalDisplayMirrorInfo);
EXPECT_EQ(1U, external_display_mirror_info->GetList().size());
EXPECT_EQ(1U, external_display_mirror_info->GetListDeprecated().size());
// ExternalDisplayInfo stores ID without output index.
EXPECT_EQ(base::NumberToString(display::GetDisplayIdWithoutOutputIndex(id2)),
external_display_mirror_info->GetList()[0].GetString());
external_display_mirror_info->GetListDeprecated()[0].GetString());

// External display's selected resolution must not change
// by mirroring.
Expand Down Expand Up @@ -1421,9 +1421,10 @@ TEST_F(DisplayPrefsTest, ExternalDisplayMirrorInfo) {
LoadDisplayPreferences();
const base::Value* pref_external_display_mirror_info =
local_state()->GetList(prefs::kExternalDisplayMirrorInfo);
EXPECT_EQ(1U, pref_external_display_mirror_info->GetList().size());
EXPECT_EQ(base::NumberToString(first_display_masked_id),
pref_external_display_mirror_info->GetList()[0].GetString());
EXPECT_EQ(1U, pref_external_display_mirror_info->GetListDeprecated().size());
EXPECT_EQ(
base::NumberToString(first_display_masked_id),
pref_external_display_mirror_info->GetListDeprecated()[0].GetString());

// Add first display, mirror mode restores and the external display mirror
// info does not change.
Expand All @@ -1432,9 +1433,10 @@ TEST_F(DisplayPrefsTest, ExternalDisplayMirrorInfo) {
EXPECT_TRUE(display_manager()->IsInMirrorMode());
pref_external_display_mirror_info =
local_state()->GetList(prefs::kExternalDisplayMirrorInfo);
EXPECT_EQ(1U, pref_external_display_mirror_info->GetList().size());
EXPECT_EQ(base::NumberToString(first_display_masked_id),
pref_external_display_mirror_info->GetList()[0].GetString());
EXPECT_EQ(1U, pref_external_display_mirror_info->GetListDeprecated().size());
EXPECT_EQ(
base::NumberToString(first_display_masked_id),
pref_external_display_mirror_info->GetListDeprecated()[0].GetString());

// Add second display, mirror mode persists and the second display id is added
// to the external display mirror info.
Expand All @@ -1443,11 +1445,13 @@ TEST_F(DisplayPrefsTest, ExternalDisplayMirrorInfo) {
EXPECT_TRUE(display_manager()->IsInMirrorMode());
pref_external_display_mirror_info =
local_state()->GetList(prefs::kExternalDisplayMirrorInfo);
EXPECT_EQ(2U, pref_external_display_mirror_info->GetList().size());
EXPECT_EQ(base::NumberToString(first_display_masked_id),
pref_external_display_mirror_info->GetList()[0].GetString());
EXPECT_EQ(base::NumberToString(second_display_masked_id),
pref_external_display_mirror_info->GetList()[1].GetString());
EXPECT_EQ(2U, pref_external_display_mirror_info->GetListDeprecated().size());
EXPECT_EQ(
base::NumberToString(first_display_masked_id),
pref_external_display_mirror_info->GetListDeprecated()[0].GetString());
EXPECT_EQ(
base::NumberToString(second_display_masked_id),
pref_external_display_mirror_info->GetListDeprecated()[1].GetString());

// Disconnect all external displays.
display_info_list.erase(display_info_list.begin() + 1,
Expand All @@ -1461,9 +1465,10 @@ TEST_F(DisplayPrefsTest, ExternalDisplayMirrorInfo) {
LoadDisplayPreferences();
pref_external_display_mirror_info =
local_state()->GetList(prefs::kExternalDisplayMirrorInfo);
EXPECT_EQ(1U, pref_external_display_mirror_info->GetList().size());
EXPECT_EQ(base::NumberToString(second_display_masked_id),
pref_external_display_mirror_info->GetList()[0].GetString());
EXPECT_EQ(1U, pref_external_display_mirror_info->GetListDeprecated().size());
EXPECT_EQ(
base::NumberToString(second_display_masked_id),
pref_external_display_mirror_info->GetListDeprecated()[0].GetString());

// Add first display, mirror mode is off and the external display mirror info
// does not change.
Expand All @@ -1472,9 +1477,10 @@ TEST_F(DisplayPrefsTest, ExternalDisplayMirrorInfo) {
EXPECT_FALSE(display_manager()->IsInMirrorMode());
pref_external_display_mirror_info =
local_state()->GetList(prefs::kExternalDisplayMirrorInfo);
EXPECT_EQ(1U, pref_external_display_mirror_info->GetList().size());
EXPECT_EQ(base::NumberToString(second_display_masked_id),
pref_external_display_mirror_info->GetList()[0].GetString());
EXPECT_EQ(1U, pref_external_display_mirror_info->GetListDeprecated().size());
EXPECT_EQ(
base::NumberToString(second_display_masked_id),
pref_external_display_mirror_info->GetListDeprecated()[0].GetString());

// Add second display, mirror mode remains off and the second display id is
// removed from the external display mirror info.
Expand All @@ -1483,7 +1489,7 @@ TEST_F(DisplayPrefsTest, ExternalDisplayMirrorInfo) {
EXPECT_FALSE(display_manager()->IsInMirrorMode());
pref_external_display_mirror_info =
local_state()->GetList(prefs::kExternalDisplayMirrorInfo);
EXPECT_EQ(0U, pref_external_display_mirror_info->GetList().size());
EXPECT_EQ(0U, pref_external_display_mirror_info->GetListDeprecated().size());
}

TEST_F(DisplayPrefsTest, ExternalDisplayConnectedBeforeLoadingPrefs) {
Expand Down Expand Up @@ -1573,9 +1579,9 @@ TEST_F(DisplayPrefsTest, DisplayMixedMirrorMode) {
pref_data->FindKey("mirroring_source_id")->GetString());
const base::Value* destination_ids_value =
pref_data->FindKey("mirroring_destination_ids");
EXPECT_EQ(1U, destination_ids_value->GetList().size());
EXPECT_EQ(1U, destination_ids_value->GetListDeprecated().size());
EXPECT_EQ(base::NumberToString(first_display_id),
destination_ids_value->GetList()[0].GetString());
destination_ids_value->GetListDeprecated()[0].GetString());

// Overwrite current mixed mirror mode with a new configuration. (Mirror from
// the first external display to the second external display)
Expand All @@ -1597,9 +1603,9 @@ TEST_F(DisplayPrefsTest, DisplayMixedMirrorMode) {
EXPECT_EQ(base::NumberToString(first_display_id),
pref_data->FindKey("mirroring_source_id")->GetString());
destination_ids_value = pref_data->FindKey("mirroring_destination_ids");
EXPECT_EQ(1U, destination_ids_value->GetList().size());
EXPECT_EQ(1U, destination_ids_value->GetListDeprecated().size());
EXPECT_EQ(base::NumberToString(second_display_id),
destination_ids_value->GetList()[0].GetString());
destination_ids_value->GetListDeprecated()[0].GetString());

// Turn off mirror mode.
display_manager()->SetMirrorMode(display::MirrorMode::kOff, absl::nullopt);
Expand Down
2 changes: 1 addition & 1 deletion ash/quick_pair/repository/fast_pair/pending_write_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ std::vector<const std::string> PendingWriteStore::GetPendingDeletes() {
return list;
}

for (const auto& item : result->GetList()) {
for (const auto& item : result->GetListDeprecated()) {
list.emplace_back(item.GetString());
}

Expand Down
2 changes: 1 addition & 1 deletion ash/session/fullscreen_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ bool FullscreenController::ShouldExitFullscreenBeforeLock() {
auto* prefs = Shell::Get()->session_controller()->GetPrimaryUserPrefService();
const auto* url_allow_list =
prefs->GetList(prefs::kKeepFullscreenWithoutNotificationUrlAllowList);
if (url_allow_list->GetList().size() == 0)
if (url_allow_list->GetListDeprecated().size() == 0)
return true;

// Get the URL of the active window from the shell delegate.
Expand Down
7 changes: 4 additions & 3 deletions ash/wallpaper/wallpaper_controller_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ void PopulateOnlineWallpaperInfo(WallpaperInfo* info,
}
if (variant_list) {
std::vector<OnlineWallpaperVariant> variants;
for (const auto& variant_info : variant_list->GetList()) {
for (const auto& variant_info : variant_list->GetListDeprecated()) {
const std::string* variant_asset_id_str = variant_info.FindStringPath(
WallpaperControllerImpl::kNewWallpaperAssetIdNodeName);
const std::string* url = variant_info.FindStringPath(
Expand Down Expand Up @@ -2439,8 +2439,9 @@ absl::optional<std::vector<SkColor>> WallpaperControllerImpl::GetCachedColors(

absl::optional<std::vector<SkColor>> cached_colors_out;
cached_colors_out = std::vector<SkColor>();
cached_colors_out.value().reserve(prominent_colors->GetList().size());
for (const auto& value : prominent_colors->GetList()) {
cached_colors_out.value().reserve(
prominent_colors->GetListDeprecated().size());
for (const auto& value : prominent_colors->GetListDeprecated()) {
cached_colors_out.value().push_back(
static_cast<SkColor>(value.GetDouble()));
}
Expand Down
8 changes: 4 additions & 4 deletions ash/webui/common/backend/plural_string_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ void PluralStringHandler::AddStringToPluralMap(const std::string& name,

void PluralStringHandler::HandleGetPluralString(const base::ListValue* args) {
AllowJavascript();
CHECK_EQ(3U, args->GetList().size());
const std::string callback = args->GetList()[0].GetString();
const std::string name = args->GetList()[1].GetString();
const int count = args->GetList()[2].GetInt();
CHECK_EQ(3U, args->GetListDeprecated().size());
const std::string callback = args->GetListDeprecated()[0].GetString();
const std::string name = args->GetListDeprecated()[1].GetString();
const int count = args->GetListDeprecated()[2].GetInt();
DCHECK(base::Contains(string_id_map_, name));
const std::u16string localized_string =
l10n_util::GetPluralStringFUTF16(string_id_map_.at(name), count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class ConnectivityDiagnosticsMessageHandler
// TODO(crbug/1220965): Remove conditional feedback button when WebUI feedback
// is launched.
void GetShowFeedbackButton(const base::ListValue* value) {
auto args = value->GetList();
auto args = value->GetListDeprecated();
if (args.size() < 1 || !args[0].is_string())
return;

Expand Down
6 changes: 3 additions & 3 deletions ash/webui/diagnostics_ui/backend/session_log_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ bool SessionLogHandler::CreateSessionLog(const base::FilePath& file_path) {

void SessionLogHandler::HandleSaveSessionLogRequest(
const base::ListValue* args) {
CHECK_EQ(1U, args->GetList().size());
CHECK_EQ(1U, args->GetListDeprecated().size());
DCHECK(save_session_log_callback_id_.empty());
save_session_log_callback_id_ = args->GetList()[0].GetString();
save_session_log_callback_id_ = args->GetListDeprecated()[0].GetString();

content::WebContents* web_contents = web_ui()->GetWebContents();
gfx::NativeWindow owning_window =
Expand All @@ -205,7 +205,7 @@ void SessionLogHandler::HandleSaveSessionLogRequest(
}

void SessionLogHandler::HandleInitialize(const base::ListValue* args) {
DCHECK(args && args->GetList().empty());
DCHECK(args && args->GetListDeprecated().empty());
AllowJavascript();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ TEST_F(ProjectorMessageHandlerUnitTest, GetAccounts) {
EXPECT_TRUE(call_data.arg2()->GetBool());
ASSERT_TRUE(call_data.arg3()->is_list());

const auto& list_view = call_data.arg3()->GetList();
const auto& list_view = call_data.arg3()->GetListDeprecated();
// There is only one account in the identity manager.
EXPECT_EQ(list_view.size(), 1u);

Expand Down Expand Up @@ -371,7 +371,7 @@ TEST_F(ProjectorMessageHandlerUnitTest, GetPendingScreencasts) {
EXPECT_TRUE(call_data.arg2()->GetBool());
ASSERT_TRUE(call_data.arg3()->is_list());

const auto& list_view = call_data.arg3()->GetList();
const auto& list_view = call_data.arg3()->GetListDeprecated();
// There is only one screencast.
EXPECT_EQ(list_view.size(), 1u);

Expand Down
Loading

0 comments on commit 354945d

Please sign in to comment.