Skip to content

Commit

Permalink
Migrate base::Value::GetList() to base::Value::GetListDeprecated(): 2/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.cc base/values.h
git checkout -- base/values_unittest.cc third_party/dom_distiller_js
git checkout -- tools/clang
git cl format

Bug: 1291666
Change-Id: I0413b4857cbf38943333988e36da53f44aab7a15
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3435727
Reviewed-by: danakj chromium <danakj@chromium.org>
Commit-Queue: danakj chromium <danakj@chromium.org>
Owners-Override: danakj chromium <danakj@chromium.org>
Cr-Commit-Position: refs/heads/main@{#966793}
  • Loading branch information
zetafunction authored and Chromium LUCI CQ committed Feb 3, 2022
1 parent 0010162 commit 91148c1
Show file tree
Hide file tree
Showing 338 changed files with 1,001 additions and 892 deletions.
2 changes: 1 addition & 1 deletion ash/accessibility/accessibility_controller_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2027,7 +2027,7 @@ void AccessibilityControllerImpl::UpdateSwitchAccessKeyCodesFromPref(

key_codes[key_code] = std::set<std::string>();

for (const base::Value& device_type : v.second.GetList())
for (const base::Value& device_type : v.second.GetListDeprecated())
key_codes[key_code].insert(device_type.GetString());

DCHECK(!key_codes[key_code].empty());
Expand Down
2 changes: 1 addition & 1 deletion ash/ambient/backdrop/ambient_backend_controller_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ absl::optional<WeatherInfo> ToWeatherInfo(const base::Value& result) {
return absl::nullopt;

WeatherInfo weather_info;
const auto& list_result = result.GetList();
const auto& list_result = result.GetListDeprecated();

weather_info.condition_icon_url = GetStringValue(
list_result, backdrop::WeatherInfo::kConditionIconUrlFieldNumber);
Expand Down
12 changes: 6 additions & 6 deletions ash/clipboard/clipboard_history_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,9 @@ TEST_F(ClipboardHistoryControllerTest, EncodeImage) {
// newly-encoded PNG is included.
base::Value result = future.Take();
EXPECT_TRUE(result.is_list());
EXPECT_EQ(1u, result.GetList().size());
EXPECT_EQ(1u, result.GetListDeprecated().size());

ExpectHistoryValueMatchesBitmap(result.GetList()[0], test_bitmap);
ExpectHistoryValueMatchesBitmap(result.GetListDeprecated()[0], test_bitmap);
}

TEST_F(ClipboardHistoryControllerTest, EncodeMultipleImages) {
Expand All @@ -377,12 +377,12 @@ TEST_F(ClipboardHistoryControllerTest, EncodeMultipleImages) {
// newly-encoded PNGs are included.
base::Value result = future.Take();
EXPECT_TRUE(result.is_list());
auto num_results = result.GetList().size();
auto num_results = result.GetListDeprecated().size();
EXPECT_EQ(num_results, test_bitmaps.size());

// History values should be sorted by recency.
for (uint i = 0; i < num_results; ++i) {
ExpectHistoryValueMatchesBitmap(result.GetList()[i],
ExpectHistoryValueMatchesBitmap(result.GetListDeprecated()[i],
test_bitmaps[num_results - 1 - i]);
}
}
Expand Down Expand Up @@ -413,12 +413,12 @@ TEST_F(ClipboardHistoryControllerTest, WriteBitmapWhileEncodingImage) {
// newly-encoded PNGs are included.
base::Value result = future.Take();
EXPECT_TRUE(result.is_list());
auto num_results = result.GetList().size();
auto num_results = result.GetListDeprecated().size();
EXPECT_EQ(num_results, test_bitmaps.size());

// History values should be sorted by recency.
for (uint i = 0; i < num_results; ++i) {
ExpectHistoryValueMatchesBitmap(result.GetList()[i],
ExpectHistoryValueMatchesBitmap(result.GetListDeprecated()[i],
test_bitmaps[num_results - 1 - i]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ bool DeserializeChallengeResponseKeyFromKnownUser(
deserialized_challenge_response_keys->clear();
if (!pref_value.is_list())
return false;
for (const base::Value& key_representation : pref_value.GetList()) {
for (const base::Value& key_representation : pref_value.GetListDeprecated()) {
if (!key_representation.is_dict()) {
LOG(WARNING) << "Ignoring challenge-response key info: not a dictionary";
continue;
Expand Down
3 changes: 2 additions & 1 deletion ash/components/tether/tether_host_response_recorder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ bool TetherHostResponseRecorder::AddRecentResponse(
updated_ids.EraseListValue(device_id_value);

// Add the device ID to the front of the queue.
updated_ids.Insert(updated_ids.GetList().begin(), std::move(device_id_value));
updated_ids.Insert(updated_ids.GetListDeprecated().begin(),
std::move(device_id_value));

// Store the updated list back in |pref_service_|.
pref_service_->Set(pref_name, std::move(updated_ids));
Expand Down
15 changes: 8 additions & 7 deletions ash/webui/projector_app/projector_message_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ bool GetUserPrefName(const base::Value& args, std::string* out) {
if (!args.is_list())
return false;

const auto& args_list = args.GetList();
const auto& args_list = args.GetListDeprecated();

if (args_list.size() != 1 || !args_list[0].is_string())
return false;
Expand All @@ -128,7 +128,7 @@ bool GetSetUserPrefArgs(const base::Value& args, SetUserPrefArgs* out) {
if (!args.is_list())
return false;

const auto& args_list = args.GetList();
const auto& args_list = args.GetListDeprecated();

if (args_list.size() != 2 || !args_list[0].is_string()) {
return false;
Expand Down Expand Up @@ -301,8 +301,8 @@ void ProjectorMessageHandler::StartProjectorSession(
// The first entry is the drive directory to save the screen cast to.
// TODO(b/177959166): Pass the directory to ProjectorController when starting
// a new session.
DCHECK_EQ(func_args.GetList().size(), 1u);
auto storage_dir_name = func_args.GetList()[0].GetString();
DCHECK_EQ(func_args.GetListDeprecated().size(), 1u);
auto storage_dir_name = func_args.GetListDeprecated()[0].GetString();
if (RE2::PartialMatch(storage_dir_name, kInvalidStorageDirNameRegex)) {
ResolveJavascriptCallback(args[0], base::Value(false));
return;
Expand Down Expand Up @@ -330,10 +330,11 @@ void ProjectorMessageHandler::GetOAuthTokenForAccount(

const auto& requested_account = args[1];
DCHECK(requested_account.is_list());
DCHECK_EQ(requested_account.GetList().size(), 1u);
DCHECK_EQ(requested_account.GetListDeprecated().size(), 1u);

auto& oauth_token_fetch_callback = args[0].GetString();
const std::string& email = requested_account.GetList()[0].GetString();
const std::string& email =
requested_account.GetListDeprecated()[0].GetString();

oauth_token_fetcher_.GetAccessTokenFor(
email,
Expand All @@ -347,7 +348,7 @@ void ProjectorMessageHandler::SendXhr(const base::Value::ConstListView args) {
DCHECK_EQ(args.size(), 2u);
const auto& callback_id = args[0].GetString();

const auto& func_args = args[1].GetList();
const auto& func_args = args[1].GetListDeprecated();
// Four function arguments:
// 1. The request URL.
// 2. The request method, for example: GET
Expand Down
2 changes: 1 addition & 1 deletion ash/webui/scanning/scanning_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void ScanningHandler::HandleOpenFilesInMediaApp(const base::ListValue* args) {
CHECK_EQ(1U, args->GetListDeprecated().size());
DCHECK(args->GetListDeprecated()[0].is_list());
const base::Value::ConstListView& value_list =
args->GetListDeprecated()[0].GetList();
args->GetListDeprecated()[0].GetListDeprecated();
DCHECK(!value_list.empty());

std::vector<base::FilePath> file_paths;
Expand Down
12 changes: 6 additions & 6 deletions base/json/json_value_converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ class RepeatedValueConverter
return false;
}

field->reserve(value.GetList().size());
field->reserve(value.GetListDeprecated().size());
size_t i = 0;
for (const Value& element : value.GetList()) {
for (const Value& element : value.GetListDeprecated()) {
auto e = std::make_unique<Element>();
if (basic_converter_.Convert(element, e.get())) {
field->push_back(std::move(e));
Expand Down Expand Up @@ -301,9 +301,9 @@ class RepeatedMessageConverter
if (!value.is_list())
return false;

field->reserve(value.GetList().size());
field->reserve(value.GetListDeprecated().size());
size_t i = 0;
for (const Value& element : value.GetList()) {
for (const Value& element : value.GetListDeprecated()) {
auto nested = std::make_unique<NestedType>();
if (converter_.Convert(element, nested.get())) {
field->push_back(std::move(nested));
Expand Down Expand Up @@ -338,9 +338,9 @@ class RepeatedCustomValueConverter
if (!value.is_list())
return false;

field->reserve(value.GetList().size());
field->reserve(value.GetListDeprecated().size());
size_t i = 0;
for (const Value& element : value.GetList()) {
for (const Value& element : value.GetListDeprecated()) {
auto nested = std::make_unique<NestedType>();
if ((*convert_func_)(&element, nested.get())) {
field->push_back(std::move(nested));
Expand Down
2 changes: 1 addition & 1 deletion base/json/json_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ bool JSONWriter::BuildJSONString(const Value& node, size_t depth) {

bool first_value_has_been_output = false;
bool result = true;
for (const auto& value : node.GetList()) {
for (const auto& value : node.GetListDeprecated()) {
if (omit_binary_values_ && value.type() == Value::Type::BINARY)
continue;

Expand Down
2 changes: 1 addition & 1 deletion base/metrics/histogram_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ TEST_P(HistogramTest, CheckGetCountAndBucketData) {
EXPECT_EQ(1440, count_and_data_bucket.sum);

const base::Value::ConstListView buckets_list =
count_and_data_bucket.buckets.GetList();
count_and_data_bucket.buckets.GetListDeprecated();
ASSERT_EQ(2u, buckets_list.size());

// Check the first bucket.
Expand Down
2 changes: 1 addition & 1 deletion base/metrics/sparse_histogram_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ TEST_P(SparseHistogramTest, CheckGetCountAndBucketData) {
EXPECT_EQ(4000, count_and_data_bucket.sum);

const base::Value::ConstListView buckets_list =
count_and_data_bucket.buckets.GetList();
count_and_data_bucket.buckets.GetListDeprecated();
ASSERT_EQ(2u, buckets_list.size());

// Check the first bucket.
Expand Down
4 changes: 2 additions & 2 deletions base/rs_glue/values_glue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ void ValueAppendString(base::Value& v, rust::Str value) {

base::Value& ValueAppendDict(base::Value& v) {
v.Append(base::Value(base::Value::Type::DICTIONARY));
return v.GetList().back();
return v.GetListDeprecated().back();
}

base::Value& ValueAppendList(base::Value& v) {
v.Append(base::Value(base::Value::Type::LIST));
return v.GetList().back();
return v.GetListDeprecated().back();
}

void ValueReserveSize(base::Value& v, size_t len) {
Expand Down
4 changes: 2 additions & 2 deletions base/trace_event/trace_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -567,15 +567,15 @@ void TraceConfig::SetProcessFilterConfig(const ProcessFilterConfig& config) {
void TraceConfig::SetHistogramNamesFromConfigList(
const Value& histogram_names) {
histogram_names_.clear();
for (const Value& value : histogram_names.GetList())
for (const Value& value : histogram_names.GetListDeprecated())
histogram_names_.insert(value.GetString());
}

void TraceConfig::SetEventFiltersFromConfigList(
const Value& category_event_filters) {
event_filters_.clear();

for (const Value& event_filter : category_event_filters.GetList()) {
for (const Value& event_filter : category_event_filters.GetListDeprecated()) {
if (!event_filter.is_dict())
continue;

Expand Down
4 changes: 2 additions & 2 deletions base/trace_event/trace_config_category_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ std::string TraceConfigCategoryFilter::ToFilterString() const {
void TraceConfigCategoryFilter::SetCategoriesFromIncludedList(
const Value& included_list) {
included_categories_.clear();
for (const Value& item : included_list.GetList()) {
for (const Value& item : included_list.GetListDeprecated()) {
if (!item.is_string())
continue;
const std::string& category = item.GetString();
Expand All @@ -195,7 +195,7 @@ void TraceConfigCategoryFilter::SetCategoriesFromIncludedList(
void TraceConfigCategoryFilter::SetCategoriesFromExcludedList(
const Value& excluded_list) {
excluded_categories_.clear();
for (const Value& item : excluded_list.GetList()) {
for (const Value& item : excluded_list.GetListDeprecated()) {
if (item.is_string())
excluded_categories_.push_back(item.GetString());
}
Expand Down
2 changes: 1 addition & 1 deletion base/trace_event/trace_event_memory_overhead.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void TraceEventMemoryOverhead::AddValue(const Value& value) {

case Value::Type::LIST:
Add(kBaseValue, sizeof(Value));
for (const auto& v : value.GetList())
for (const auto& v : value.GetListDeprecated())
AddValue(v);
break;

Expand Down
18 changes: 9 additions & 9 deletions base/trace_event/trace_event_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ static bool IsAllKeyValueInDict(const JsonKeyValue* key_values,
const Value* TraceEventTestFixture::FindMatchingTraceEntry(
const JsonKeyValue* key_values) {
// Scan all items
for (const Value& value : trace_parsed_.GetList()) {
for (const Value& value : trace_parsed_.GetListDeprecated()) {
if (!value.is_dict())
continue;

Expand Down Expand Up @@ -349,7 +349,7 @@ const Value* FindTraceEntry(const Value& trace_parsed,
const char* string_to_match,
const Value* match_after_this_item = nullptr) {
// Scan all items
for (const Value& value : trace_parsed.GetList()) {
for (const Value& value : trace_parsed.GetListDeprecated()) {
if (match_after_this_item) {
if (&value == match_after_this_item)
match_after_this_item = nullptr;
Expand All @@ -367,7 +367,7 @@ const Value* FindTraceEntry(const Value& trace_parsed,
std::vector<const Value*> FindTraceEntries(const Value& trace_parsed,
const char* string_to_match) {
std::vector<const Value*> hits;
for (const Value& value : trace_parsed.GetList()) {
for (const Value& value : trace_parsed.GetListDeprecated()) {
if (!value.is_dict())
continue;

Expand Down Expand Up @@ -837,7 +837,7 @@ void ValidateInstantEventPresentOnEveryThread(const Value& trace_parsed,
int num_events) {
std::map<int, std::map<int, bool>> results;

for (const Value& value : trace_parsed.GetList()) {
for (const Value& value : trace_parsed.GetListDeprecated()) {
if (!value.is_dict())
continue;

Expand Down Expand Up @@ -895,7 +895,7 @@ TEST_F(TraceEventTestFixture, DataDiscarded) {

CancelTrace();

EXPECT_TRUE(trace_parsed_.GetList().empty());
EXPECT_TRUE(trace_parsed_.GetListDeprecated().empty());
}

class MockEnabledStateChangedObserver :
Expand Down Expand Up @@ -1195,7 +1195,7 @@ TEST_F(TraceEventTestFixture, Categories) {
TRACE_EVENT_INSTANT0("cat2", "name", TRACE_EVENT_SCOPE_THREAD);
EndTraceAndFlush();
DropTracedMetadataRecords();
EXPECT_TRUE(trace_parsed_.GetList().empty());
EXPECT_TRUE(trace_parsed_.GetListDeprecated().empty());

// Include existent category -> only events of that category
Clear();
Expand Down Expand Up @@ -2175,8 +2175,8 @@ TEST_F(TraceEventTestFixture, TraceBufferVectorReportFull) {
// Test that buffer_limit_reached_timestamp's value is between the timestamp
// of the last trace event and current time.
DropTracedMetadataRecords();
ASSERT_TRUE(!trace_parsed_.GetList().empty());
const Value& last_trace_event = trace_parsed_.GetList().back();
ASSERT_TRUE(!trace_parsed_.GetListDeprecated().empty());
const Value& last_trace_event = trace_parsed_.GetListDeprecated().back();
EXPECT_TRUE(last_trace_event.is_dict());
absl::optional<double> maybe_last_trace_event_timestamp =
last_trace_event.FindDoubleKey("ts");
Expand Down Expand Up @@ -2557,7 +2557,7 @@ TEST_F(TraceEventTestFixture, TimeOffset) {
double end_time = static_cast<double>(
(TimeTicks::Now() - time_offset).ToInternalValue());
double last_timestamp = 0;
for (const Value& item : trace_parsed_.GetList()) {
for (const Value& item : trace_parsed_.GetListDeprecated()) {
EXPECT_TRUE(item.is_dict());
absl::optional<double> timestamp = item.FindDoubleKey("ts");
EXPECT_TRUE(timestamp.has_value());
Expand Down
7 changes: 4 additions & 3 deletions base/values.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ std::unique_ptr<Value> CopyWithoutEmptyChildren(const Value& node);
// expects |node| to always be non-NULL.
std::unique_ptr<Value> CopyListWithoutEmptyChildren(const Value& list) {
Value copy(Value::Type::LIST);
for (const auto& entry : list.GetList()) {
for (const auto& entry : list.GetListDeprecated()) {
std::unique_ptr<Value> child_copy = CopyWithoutEmptyChildren(entry);
if (child_copy)
copy.Append(std::move(*child_copy));
}
return copy.GetList().empty() ? nullptr
: std::make_unique<Value>(std::move(copy));
return copy.GetListDeprecated().empty()
? nullptr
: std::make_unique<Value>(std::move(copy));
}

std::unique_ptr<DictionaryValue> CopyDictionaryWithoutEmptyChildren(
Expand Down
6 changes: 3 additions & 3 deletions base/values.h
Original file line number Diff line number Diff line change
Expand Up @@ -825,11 +825,11 @@ class BASE_EXPORT ListValue : public Value {
// ListValue no longer supports iteration. Instead, use GetList() to get the
// underlying list:
//
// for (const auto& entry : list_value.GetList()) {
// for (const auto& entry : list_value.GetListDeprecated()) {
// ...
//
// for (auto it = list_value.GetList().begin();
// it != list_value.GetList().end(); ++it) {
// for (auto it = list_value.GetListDeprecated().begin();
// it != list_value.GetListDeprecated().end(); ++it) {
// ...
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class MediaGalleriesPlatformAppBrowserTest : public PlatformAppBrowserTest {

const char* custom_arg = NULL;
std::string json_string;
if (!custom_arg_value.GetList().empty()) {
if (!custom_arg_value.GetListDeprecated().empty()) {
base::JSONWriter::Write(custom_arg_value, &json_string);
custom_arg = json_string.c_str();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ ExtensionFunction::ResponseAction SyncFileSystemGetFileStatusesFunction::Run() {
// All FileEntries converted into array of URL Strings in JS custom bindings.
EXTENSION_FUNCTION_VALIDATE(args().size() >= 1);
EXTENSION_FUNCTION_VALIDATE(args()[0].is_list());
base::Value::ConstListView file_entry_urls = args()[0].GetList();
base::Value::ConstListView file_entry_urls = args()[0].GetListDeprecated();

scoped_refptr<storage::FileSystemContext> file_system_context =
browser_context()
Expand Down
Loading

0 comments on commit 91148c1

Please sign in to comment.