base::Value::GetAsList removed
Chromium change: https://chromium.googlesource.com/chromium/src/+/949656831d4cb0bf282de7b190d84129294b12a9 commit 949656831d4cb0bf282de7b190d84129294b12a9 Author: Alex Cooper <alcooper@chromium.org> Date: Mon Jul 11 17:56:16 2022 +0000 [CodeHealth] Remove Value::GetAsList Removes the last two instances of base::Value::GetAsList. One in chromedriver, where the only usage can (and was) updated to use base::Value::List instead. One in base::ListValue::From, which now does the same cast that GetAsList used to do, but since the intention is to remove GetAsList, it seems acceptable to move it into the (slightly longer lived) helper method that will eventually be replaced itself. Fixed: 1187009
This commit is contained in:
committed by
mkarolin
parent
840781667c
commit
d6180f3707
@@ -141,11 +141,7 @@ bool RLPDecodeInternal(const std::string& s,
|
||||
std::string str = s.substr(*offset, *data_len);
|
||||
*output = base::Value(str);
|
||||
} else if (output->is_list()) {
|
||||
*output = base::ListValue();
|
||||
base::ListValue* output_list;
|
||||
if (!output->GetAsList(&output_list)) {
|
||||
return false;
|
||||
}
|
||||
base::Value::List list;
|
||||
if (!IsWithinBounds(*offset, *data_len, length)) {
|
||||
return false;
|
||||
}
|
||||
@@ -156,7 +152,7 @@ bool RLPDecodeInternal(const std::string& s,
|
||||
if (!RLPDecodeInternal(sub, &v, &offset2, &data_len2)) {
|
||||
return false;
|
||||
}
|
||||
output_list->Append(std::move(v));
|
||||
list.Append(std::move(v));
|
||||
*offset += data_len2 + offset2;
|
||||
*data_len -= data_len2 + offset2;
|
||||
if (!IsWithinBounds(*offset, *data_len, length)) {
|
||||
@@ -164,6 +160,7 @@ bool RLPDecodeInternal(const std::string& s,
|
||||
}
|
||||
sub = s.substr(*offset, *data_len);
|
||||
}
|
||||
*output = base::Value(std::move(list));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -23,9 +23,8 @@ std::string RLPTestValueToString(const base::Value& val) {
|
||||
}
|
||||
output += "[";
|
||||
std::string elems;
|
||||
const base::ListValue* list;
|
||||
val.GetAsList(&list);
|
||||
for (const auto& item : list->GetList()) {
|
||||
const base::Value::List& list = val.GetList();
|
||||
for (const auto& item : list) {
|
||||
if (elems.size()) {
|
||||
elems += ", ";
|
||||
}
|
||||
|
||||
@@ -287,17 +287,18 @@ void GreaselionDownloadService::OnDATFileDataReady(std::string contents) {
|
||||
}
|
||||
auto& root_list = root->GetList();
|
||||
for (base::Value& rule_it : root_list) {
|
||||
DCHECK(rule_it.is_dict());
|
||||
auto& rule_dict = rule_it.GetDict();
|
||||
auto* preconditions_value = rule_dict.FindDict(kPreconditions);
|
||||
auto* urls_value = rule_dict.FindList(kURLs);
|
||||
auto* scripts_value = rule_dict.FindList(kScripts);
|
||||
const std::string* run_at_ptr = rule_dict.FindStringByDottedPath(kRunAt);
|
||||
const std::string* run_at_ptr = rule_dict.FindString(kRunAt);
|
||||
const std::string run_at_value = run_at_ptr ? *run_at_ptr : "";
|
||||
const std::string* minimum_brave_version_ptr =
|
||||
rule_dict.FindStringByDottedPath(kMinimumBraveVersion);
|
||||
rule_dict.FindString(kMinimumBraveVersion);
|
||||
const std::string minimum_brave_version_value =
|
||||
minimum_brave_version_ptr ? *minimum_brave_version_ptr : "";
|
||||
const std::string* messages = rule_dict.FindStringByDottedPath(kMessages);
|
||||
const std::string* messages = rule_dict.FindString(kMessages);
|
||||
base::FilePath messages_path;
|
||||
if (messages) {
|
||||
messages_path = base::FilePath::FromUTF8Unsafe(messages->c_str());
|
||||
|
||||
+28
-73
@@ -24,12 +24,13 @@ std::unique_ptr<PurchaseIntentInfo> PurchaseIntentInfo::CreateFromValue(
|
||||
DCHECK(error_message);
|
||||
auto purchase_intent = std::make_unique<PurchaseIntentInfo>();
|
||||
|
||||
if (!resource_value.is_dict()) {
|
||||
base::Value::Dict* resource = resource_value.GetIfDict();
|
||||
if (!resource) {
|
||||
*error_message = "Failed to load from JSON, json is not a dictionary";
|
||||
return {};
|
||||
}
|
||||
|
||||
if (absl::optional<int> version = resource_value.FindIntPath("version")) {
|
||||
if (absl::optional<int> version = resource->FindInt("version")) {
|
||||
if (targeting::features::GetPurchaseIntentResourceVersion() != *version) {
|
||||
*error_message = "Failed to load from JSON, version missing";
|
||||
return {};
|
||||
@@ -39,25 +40,14 @@ std::unique_ptr<PurchaseIntentInfo> PurchaseIntentInfo::CreateFromValue(
|
||||
}
|
||||
|
||||
// Parsing field: "segments"
|
||||
base::Value* incoming_segments = resource_value.FindListPath("segments");
|
||||
base::Value::List* incoming_segments = resource->FindList("segments");
|
||||
if (!incoming_segments) {
|
||||
*error_message = "Failed to load from JSON, segments missing";
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!incoming_segments->is_list()) {
|
||||
*error_message = "Failed to load from JSON, segments is not of type list";
|
||||
return {};
|
||||
}
|
||||
|
||||
base::ListValue* list3;
|
||||
if (!incoming_segments->GetAsList(&list3)) {
|
||||
*error_message = "Failed to load from JSON, get segments as list";
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<std::string> segments;
|
||||
for (const auto& item : list3->GetList()) {
|
||||
for (const auto& item : *incoming_segments) {
|
||||
const std::string& segment = item.GetString();
|
||||
if (segment.empty()) {
|
||||
*error_message = "Failed to load from JSON, empty segment found";
|
||||
@@ -67,30 +57,18 @@ std::unique_ptr<PurchaseIntentInfo> PurchaseIntentInfo::CreateFromValue(
|
||||
}
|
||||
|
||||
// Parsing field: "segment_keywords"
|
||||
base::Value* incoming_segment_keywords =
|
||||
resource_value.FindDictPath("segment_keywords");
|
||||
base::Value::Dict* incoming_segment_keywords =
|
||||
resource->FindDict("segment_keywords");
|
||||
if (!incoming_segment_keywords) {
|
||||
*error_message = "Failed to load from JSON, segment keywords missing";
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!incoming_segment_keywords->is_dict()) {
|
||||
*error_message =
|
||||
"Failed to load from JSON, segment keywords not of type dict";
|
||||
return {};
|
||||
}
|
||||
|
||||
base::DictionaryValue* dict2;
|
||||
if (!incoming_segment_keywords->GetAsDictionary(&dict2)) {
|
||||
*error_message = "Failed to load from JSON, get segment keywords as dict";
|
||||
return {};
|
||||
}
|
||||
|
||||
for (base::DictionaryValue::Iterator it(*dict2); !it.IsAtEnd();
|
||||
it.Advance()) {
|
||||
for (const auto item : *incoming_segment_keywords) {
|
||||
PurchaseIntentSegmentKeywordInfo info;
|
||||
info.keywords = it.key();
|
||||
for (const auto& segment_ix : it.value().GetList()) {
|
||||
info.keywords = item.first;
|
||||
for (const auto& segment_ix : item.second.GetList()) {
|
||||
DCHECK(segment_ix.is_int());
|
||||
if (static_cast<size_t>(segment_ix.GetInt()) >= segments.size()) {
|
||||
*error_message =
|
||||
"Failed to load from JSON, segment keywords are ill-formed";
|
||||
@@ -103,81 +81,58 @@ std::unique_ptr<PurchaseIntentInfo> PurchaseIntentInfo::CreateFromValue(
|
||||
}
|
||||
|
||||
// Parsing field: "funnel_keywords"
|
||||
base::Value* incoming_funnel_keywords =
|
||||
resource_value.FindDictPath("funnel_keywords");
|
||||
base::Value::Dict* incoming_funnel_keywords =
|
||||
resource->FindDict("funnel_keywords");
|
||||
if (!incoming_funnel_keywords) {
|
||||
*error_message = "Failed to load from JSON, funnel keywords missing";
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!incoming_funnel_keywords->is_dict()) {
|
||||
*error_message =
|
||||
"Failed to load from JSON, funnel keywords not of type dict";
|
||||
return {};
|
||||
}
|
||||
|
||||
base::DictionaryValue* dict;
|
||||
if (!incoming_funnel_keywords->GetAsDictionary(&dict)) {
|
||||
*error_message = "Failed to load from JSON, get funnel keywords as dict";
|
||||
return {};
|
||||
}
|
||||
|
||||
for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) {
|
||||
for (const auto item : *incoming_funnel_keywords) {
|
||||
PurchaseIntentFunnelKeywordInfo info;
|
||||
info.keywords = it.key();
|
||||
info.weight = it.value().GetInt();
|
||||
info.keywords = item.first;
|
||||
info.weight = item.second.GetInt();
|
||||
purchase_intent->funnel_keywords.push_back(info);
|
||||
}
|
||||
|
||||
// Parsing field: "funnel_sites"
|
||||
base::Value* incoming_funnel_sites =
|
||||
resource_value.FindListPath("funnel_sites");
|
||||
base::Value::List* incoming_funnel_sites = resource->FindList("funnel_sites");
|
||||
if (!incoming_funnel_sites) {
|
||||
*error_message = "Failed to load from JSON, sites missing";
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!incoming_funnel_sites->is_list()) {
|
||||
*error_message = "Failed to load from JSON, sites not of type dict";
|
||||
return {};
|
||||
}
|
||||
|
||||
base::ListValue* list1;
|
||||
if (!incoming_funnel_sites->GetAsList(&list1)) {
|
||||
*error_message = "Failed to load from JSON, get sites as dict";
|
||||
return {};
|
||||
}
|
||||
|
||||
// For each set of sites and segments
|
||||
for (auto& set : list1->GetList()) {
|
||||
if (!set.is_dict()) {
|
||||
for (auto& item : *incoming_funnel_sites) {
|
||||
if (!item.is_dict()) {
|
||||
*error_message = "Failed to load from JSON, site set not of type dict";
|
||||
return {};
|
||||
}
|
||||
auto& set = item.GetDict();
|
||||
|
||||
// Get all segments...
|
||||
base::ListValue* seg_list;
|
||||
base::Value* seg_value = set.FindListPath("segments");
|
||||
if (!seg_value->GetAsList(&seg_list)) {
|
||||
base::Value::List* seg_list = set.FindList("segments");
|
||||
if (!seg_list) {
|
||||
*error_message =
|
||||
"Failed to load from JSON, get site segment list as dict";
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<std::string> site_segments;
|
||||
for (auto& seg : seg_list->GetList()) {
|
||||
for (auto& seg : *seg_list) {
|
||||
DCHECK(seg.is_int());
|
||||
site_segments.push_back(segments.at(seg.GetInt()));
|
||||
}
|
||||
|
||||
// ...and for each site create info with appended segments
|
||||
base::ListValue* site_list;
|
||||
base::Value* site_value = set.FindListPath("sites");
|
||||
if (!site_value->GetAsList(&site_list)) {
|
||||
base::Value::List* site_list = set.FindList("sites");
|
||||
if (!site_list) {
|
||||
*error_message = "Failed to load from JSON, get site list as dict";
|
||||
return {};
|
||||
}
|
||||
|
||||
for (const auto& site : site_list->GetList()) {
|
||||
for (const auto& site : *site_list) {
|
||||
DCHECK(site.is_string());
|
||||
PurchaseIntentSiteInfo info;
|
||||
info.segments = site_segments;
|
||||
info.url_netloc = GURL(site.GetString());
|
||||
|
||||
vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/gemini/post_balance/post_balance_gemini.cc
Vendored
+6
-9
@@ -40,19 +40,16 @@ type::Result PostBalance::ParseBody(const std::string& body,
|
||||
return type::Result::LEDGER_ERROR;
|
||||
}
|
||||
|
||||
base::ListValue* balances = nullptr;
|
||||
if (!value->GetAsList(&balances)) {
|
||||
BLOG(0, "Invalid JSON");
|
||||
return type::Result::LEDGER_ERROR;
|
||||
}
|
||||
|
||||
for (auto&& balance : balances->GetList()) {
|
||||
const auto* currency_code = balance.FindStringKey("currency");
|
||||
auto& balances = value->GetList();
|
||||
for (auto& item : balances) {
|
||||
DCHECK(item.is_dict());
|
||||
auto& balance = item.GetDict();
|
||||
const auto* currency_code = balance.FindString("currency");
|
||||
if (!currency_code || *currency_code != "BAT") {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto* available_value = balance.FindStringKey("available");
|
||||
const auto* available_value = balance.FindString("available");
|
||||
if (!available_value) {
|
||||
BLOG(0, "Missing available");
|
||||
return type::Result::LEDGER_ERROR;
|
||||
|
||||
+16
-17
@@ -73,27 +73,26 @@ GetCapabilities::ProcessResponse(const type::UrlResponse& response) {
|
||||
|
||||
GetCapabilities::CapabilityMap GetCapabilities::ParseBody(
|
||||
const std::string& body) {
|
||||
std::map<std::string, Capability> capability_map;
|
||||
|
||||
const auto value = base::JSONReader::Read(body);
|
||||
const base::ListValue* list_value = nullptr;
|
||||
if (!value || !value->is_list()) {
|
||||
BLOG(0, "Invalid body format!");
|
||||
return {};
|
||||
}
|
||||
|
||||
if (value && value->GetAsList(&list_value)) {
|
||||
DCHECK(list_value);
|
||||
std::map<std::string, Capability> capability_map;
|
||||
for (const auto& item : value->GetList()) {
|
||||
DCHECK(item.is_dict());
|
||||
const auto& dict = item.GetDict();
|
||||
const auto* key = dict.FindString("key");
|
||||
const auto enabled = dict.FindBool("enabled");
|
||||
const auto* requirements = dict.FindList("requirements");
|
||||
|
||||
for (const auto& item : list_value->GetList()) {
|
||||
const auto* key = item.FindStringKey("key");
|
||||
const auto enabled = item.FindBoolKey("enabled");
|
||||
const auto* requirements = item.FindListKey("requirements");
|
||||
|
||||
if (!key || !enabled || !requirements) {
|
||||
capability_map.clear();
|
||||
break;
|
||||
}
|
||||
|
||||
capability_map.emplace(
|
||||
*key, Capability{*enabled, requirements->GetList().empty()});
|
||||
if (!key || !enabled || !requirements) {
|
||||
capability_map.clear();
|
||||
break;
|
||||
}
|
||||
|
||||
capability_map.emplace(*key, Capability{*enabled, requirements->empty()});
|
||||
}
|
||||
|
||||
if (capability_map.empty()) {
|
||||
|
||||
+6
-9
@@ -54,20 +54,17 @@ type::Result GetCards::ParseBody(
|
||||
return type::Result::LEDGER_ERROR;
|
||||
}
|
||||
|
||||
base::ListValue* list = nullptr;
|
||||
if (!value->GetAsList(&list)) {
|
||||
BLOG(0, "Invalid JSON");
|
||||
return type::Result::LEDGER_ERROR;
|
||||
}
|
||||
|
||||
for (const auto& it : list->GetList()) {
|
||||
const auto* label = it.FindStringKey("label");
|
||||
auto& list = value->GetList();
|
||||
for (const auto& it : list) {
|
||||
DCHECK(it.is_dict());
|
||||
const auto& dict = it.GetDict();
|
||||
const auto* label = dict.FindString("label");
|
||||
if (!label) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (*label == ::ledger::uphold::kCardName) {
|
||||
const auto* id_str = it.FindStringKey("id");
|
||||
const auto* id_str = dict.FindString("id");
|
||||
if (!id_str) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -38,13 +38,9 @@ std::vector<double> StringToVectorDouble(const std::string& items_string) {
|
||||
return {};
|
||||
}
|
||||
|
||||
base::ListValue* list_value = nullptr;
|
||||
if (!list->GetAsList(&list_value)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto& list_value = list->GetList();
|
||||
std::vector<double> items;
|
||||
for (auto& item : list_value->GetList()) {
|
||||
for (auto& item : list_value) {
|
||||
if (!item.is_double()) {
|
||||
continue;
|
||||
}
|
||||
@@ -69,15 +65,14 @@ std::string PayoutStatusToString(
|
||||
|
||||
base::flat_map<std::string, std::string> StringToPayoutStatus(
|
||||
const std::string& payout_status_string) {
|
||||
base::DictionaryValue* dictionary_value = nullptr;
|
||||
auto dict = base::JSONReader::Read(payout_status_string);
|
||||
if (!dict || !dict->GetAsDictionary(&dictionary_value)) {
|
||||
auto json = base::JSONReader::Read(payout_status_string);
|
||||
if (!json || !json->is_dict()) {
|
||||
return {};
|
||||
}
|
||||
DCHECK(dictionary_value);
|
||||
|
||||
auto& dict = json->GetDict();
|
||||
base::flat_map<std::string, std::string> payout_status;
|
||||
for (const auto [key, value] : dictionary_value->GetDict()) {
|
||||
for (const auto [key, value] : dict) {
|
||||
if (!value.is_string()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user