[Code Health] Remove usage of ListValue::GetDictionary() under content
and components Bug: 1187091 Change-Id: I55c151799e4e682b4a67f0e3c64789d802cd79b7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3259825 Reviewed-by: Danil Somsikov <dsv@chromium.org> Reviewed-by: Matt Reynolds <mattreynolds@chromium.org> Reviewed-by: manuk hovanesian <manukh@chromium.org> Reviewed-by: Matt Menke <mmenke@chromium.org> Reviewed-by: Elad Alon <eladalon@chromium.org> Reviewed-by: Ben Kelly <wanderview@chromium.org> Reviewed-by: David Bokan <bokan@chromium.org> Reviewed-by: Liquan (Max) Gu <maxlg@chromium.org> Reviewed-by: Xinghui Lu <xinghuilu@chromium.org> Reviewed-by: Josh Simmons <jds@google.com> Reviewed-by: Kristi Park <kristipark@chromium.org> Reviewed-by: Alex Ilin <alexilin@chromium.org> Reviewed-by: Marc Treib <treib@chromium.org> Reviewed-by: Alexander Alekseev <alemate@chromium.org> Reviewed-by: Caitlin Fischer <caitlinfischer@google.com> Commit-Queue: Nan Lin <linnan@chromium.org> Cr-Commit-Position: refs/heads/main@{#939907}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
6fffd3ad16
commit
26e10b33aa
components
language
content
browser
ulp_language_code_locator
metrics
ntp_tiles
omnibox
browser
payments
content
utility
safe_browsing
safe_search_api
safe_search
search_engines
signin
internal
identity_manager
spellcheck
browser
sync
user_manager
content/browser
devtools
renderer_host
service_worker
webrtc
services
@ -59,9 +59,12 @@ std::vector<std::string> UlpLanguageCodeLocator::GetLanguageCodes(
|
||||
for (size_t index = 0; index < serialized_langtrees_.size(); index++) {
|
||||
std::string language;
|
||||
|
||||
const base::DictionaryValue* celllang_cached;
|
||||
const bool is_cached =
|
||||
celllangs_cached->GetDictionary(index, &celllang_cached);
|
||||
bool is_cached = false;
|
||||
const base::Value* celllang_cached = nullptr;
|
||||
if (index < celllangs_cached->GetList().size()) {
|
||||
celllang_cached = &celllangs_cached->GetList()[index];
|
||||
is_cached = celllang_cached->is_dict();
|
||||
}
|
||||
|
||||
const std::string* token_cached =
|
||||
is_cached ? celllang_cached->FindStringKey(kCellTokenKey) : nullptr;
|
||||
|
@ -249,10 +249,12 @@ void UnsentLogStore::ReadLogsFromPrefList(const base::ListValue& list_value) {
|
||||
list_.resize(log_count);
|
||||
|
||||
for (size_t i = 0; i < log_count; ++i) {
|
||||
const base::DictionaryValue* dict;
|
||||
const base::Value& value = list_value.GetList()[i];
|
||||
const base::DictionaryValue* dict = nullptr;
|
||||
if (value.is_dict())
|
||||
dict = &base::Value::AsDictionaryValue(value);
|
||||
LogInfo info;
|
||||
if (!list_value.GetDictionary(i, &dict) ||
|
||||
!dict->GetString(kLogDataKey, &info.compressed_log_data) ||
|
||||
if (!dict || !dict->GetString(kLogDataKey, &info.compressed_log_data) ||
|
||||
!dict->GetString(kLogHashKey, &info.hash) ||
|
||||
!dict->GetString(kLogTimestampKey, &info.timestamp) ||
|
||||
!dict->GetString(kLogSignatureKey, &info.signature)) {
|
||||
|
@ -117,21 +117,22 @@ std::string GetVariationDirectory() {
|
||||
|
||||
PopularSites::SitesVector ParseSiteList(const base::ListValue& list) {
|
||||
PopularSites::SitesVector sites;
|
||||
for (size_t i = 0; i < list.GetList().size(); i++) {
|
||||
const base::DictionaryValue* item;
|
||||
if (!list.GetDictionary(i, &item))
|
||||
for (const base::Value& item_value : list.GetList()) {
|
||||
if (!item_value.is_dict())
|
||||
continue;
|
||||
const base::DictionaryValue& item =
|
||||
base::Value::AsDictionaryValue(item_value);
|
||||
std::u16string title;
|
||||
std::string url;
|
||||
if (!item->GetString("title", &title) || !item->GetString("url", &url))
|
||||
if (!item.GetString("title", &title) || !item.GetString("url", &url))
|
||||
continue;
|
||||
std::string favicon_url;
|
||||
item->GetString("favicon_url", &favicon_url);
|
||||
item.GetString("favicon_url", &favicon_url);
|
||||
std::string large_icon_url;
|
||||
item->GetString("large_icon_url", &large_icon_url);
|
||||
item.GetString("large_icon_url", &large_icon_url);
|
||||
|
||||
TileTitleSource title_source = TileTitleSource::UNKNOWN;
|
||||
absl::optional<int> title_source_int = item->FindIntKey("title_source");
|
||||
absl::optional<int> title_source_int = item.FindIntKey("title_source");
|
||||
if (!title_source_int) {
|
||||
// Only v6 and later have "title_source". Earlier versions use title tags.
|
||||
title_source = TileTitleSource::TITLE_TAG;
|
||||
@ -143,10 +144,10 @@ PopularSites::SitesVector ParseSiteList(const base::ListValue& list) {
|
||||
sites.emplace_back(title, GURL(url), GURL(favicon_url),
|
||||
GURL(large_icon_url), title_source);
|
||||
absl::optional<int> default_icon_resource =
|
||||
item->FindIntKey("default_icon_resource");
|
||||
item.FindIntKey("default_icon_resource");
|
||||
if (default_icon_resource)
|
||||
sites.back().default_icon_resource = *default_icon_resource;
|
||||
item->GetBoolean("baked_in", &sites.back().baked_in);
|
||||
item.GetBoolean("baked_in", &sites.back().baked_in);
|
||||
}
|
||||
return sites;
|
||||
}
|
||||
@ -162,13 +163,13 @@ std::map<SectionType, PopularSites::SitesVector> ParseVersion6OrAbove(
|
||||
std::map<SectionType, PopularSites::SitesVector> sections = {
|
||||
std::make_pair(SectionType::PERSONALIZED, PopularSites::SitesVector{})};
|
||||
for (size_t i = 0; i < list.GetList().size(); i++) {
|
||||
const base::DictionaryValue* item;
|
||||
if (!list.GetDictionary(i, &item)) {
|
||||
const base::Value& item_value = list.GetList()[i];
|
||||
if (!item_value.is_dict()) {
|
||||
LOG(WARNING) << "Parsed SitesExploration list contained an invalid "
|
||||
<< "section at position " << i << ".";
|
||||
continue;
|
||||
}
|
||||
int section = item->FindIntKey("section").value_or(-1);
|
||||
int section = item_value.FindIntKey("section").value_or(-1);
|
||||
if (section < 0 || section > static_cast<int>(SectionType::LAST)) {
|
||||
LOG(WARNING) << "Parsed SitesExploration list contained a section with "
|
||||
<< "invalid ID (" << section << ")";
|
||||
@ -179,8 +180,10 @@ std::map<SectionType, PopularSites::SitesVector> ParseVersion6OrAbove(
|
||||
SectionType section_type = static_cast<SectionType>(section);
|
||||
if (section_type != SectionType::PERSONALIZED)
|
||||
continue;
|
||||
const base::DictionaryValue& item =
|
||||
base::Value::AsDictionaryValue(item_value);
|
||||
const base::ListValue* sites_list;
|
||||
if (!item->GetList("sites", &sites_list))
|
||||
if (!item.GetList("sites", &sites_list))
|
||||
continue;
|
||||
sections[section_type] = ParseSiteList(*sites_list);
|
||||
}
|
||||
|
@ -728,22 +728,24 @@ ACMatches DocumentProvider::ParseDocumentSearchResults(
|
||||
// Ensure server's suggestions are added with monotonically decreasing scores.
|
||||
int previous_score = INT_MAX;
|
||||
for (size_t i = 0; i < num_results; i++) {
|
||||
const base::DictionaryValue* result = nullptr;
|
||||
if (!results_list->GetDictionary(i, &result)) {
|
||||
const base::Value& result_value = results_list->GetList()[i];
|
||||
if (!result_value.is_dict()) {
|
||||
return matches;
|
||||
}
|
||||
const base::DictionaryValue& result =
|
||||
base::Value::AsDictionaryValue(result_value);
|
||||
std::u16string title;
|
||||
std::u16string url;
|
||||
result->GetString("title", &title);
|
||||
result->GetString("url", &url);
|
||||
result.GetString("title", &title);
|
||||
result.GetString("url", &url);
|
||||
if (title.empty() || url.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Both client and server scores are calculated regardless of usage in order
|
||||
// to log them with |AutocompleteMatch::RecordAdditionalInfo| below.
|
||||
int client_score = CalculateScore(input_.text(), result);
|
||||
int server_score = result->FindIntKey("score").value_or(0);
|
||||
int client_score = CalculateScore(input_.text(), &result);
|
||||
int server_score = result.FindIntKey("score").value_or(0);
|
||||
int score = 0;
|
||||
|
||||
if (use_client_score && use_server_score)
|
||||
@ -757,7 +759,7 @@ ACMatches DocumentProvider::ParseDocumentSearchResults(
|
||||
}
|
||||
|
||||
if (boost_owned)
|
||||
score = BoostOwned(score, client_->ProfileUserName(), result);
|
||||
score = BoostOwned(score, client_->ProfileUserName(), &result);
|
||||
|
||||
// Decrement scores if necessary to ensure suggestion order is preserved.
|
||||
// Don't decrement client scores which don't necessarily rank suggestions
|
||||
@ -773,7 +775,7 @@ ACMatches DocumentProvider::ParseDocumentSearchResults(
|
||||
match.fill_into_edit = url;
|
||||
match.destination_url = GURL(url);
|
||||
std::u16string original_url;
|
||||
if (result->GetString("originalUrl", &original_url)) {
|
||||
if (result.GetString("originalUrl", &original_url)) {
|
||||
// |AutocompleteMatch::GURLToStrippedGURL()| will try to use
|
||||
// |GetURLForDeduping()| to extract a doc ID and generate a canonical doc
|
||||
// URL; this is ideal as it handles different URL formats pointing to the
|
||||
@ -788,7 +790,7 @@ ACMatches DocumentProvider::ParseDocumentSearchResults(
|
||||
match.contents = AutocompleteMatch::SanitizeString(title);
|
||||
match.contents_class = Classify(match.contents, input_.text());
|
||||
const base::DictionaryValue* metadata = nullptr;
|
||||
if (result->GetDictionary("metadata", &metadata)) {
|
||||
if (result.GetDictionary("metadata", &metadata)) {
|
||||
std::string mimetype;
|
||||
if (metadata->GetString("mimeType", &mimetype)) {
|
||||
match.document_type = GetIconForMIMEType(mimetype);
|
||||
@ -798,7 +800,7 @@ ACMatches DocumentProvider::ParseDocumentSearchResults(
|
||||
}
|
||||
std::string update_time;
|
||||
metadata->GetString("updateTime", &update_time);
|
||||
auto owners = ExtractResultList(result, "metadata.owner.personNames",
|
||||
auto owners = ExtractResultList(&result, "metadata.owner.personNames",
|
||||
"displayName");
|
||||
if (!owners.empty())
|
||||
match.RecordAdditionalInfo("document owner", *owners[0]);
|
||||
@ -823,7 +825,7 @@ ACMatches DocumentProvider::ParseDocumentSearchResults(
|
||||
match.RecordAdditionalInfo("server score", server_score);
|
||||
if (matches.size() >= provider_max_matches_)
|
||||
match.RecordAdditionalInfo("for deduping only", "true");
|
||||
const std::string* snippet = result->FindStringPath("snippet.snippet");
|
||||
const std::string* snippet = result.FindStringPath("snippet.snippet");
|
||||
if (snippet)
|
||||
match.RecordAdditionalInfo("snippet", *snippet);
|
||||
matches.push_back(match);
|
||||
|
@ -279,16 +279,19 @@ void ParsePreferredRelatedApplicationIdentifiers(
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
const base::DictionaryValue* related_application = nullptr;
|
||||
if (!related_applications->GetDictionary(i, &related_application)) {
|
||||
const base::Value& related_application_value =
|
||||
related_applications->GetList()[i];
|
||||
if (!related_application_value.is_dict()) {
|
||||
log.Warn(
|
||||
base::StringPrintf("Element #%zu in \"%s\" should be a dictionary.",
|
||||
i, kRelatedApplications));
|
||||
continue;
|
||||
}
|
||||
|
||||
const base::DictionaryValue& related_application =
|
||||
base::Value::AsDictionaryValue(related_application_value);
|
||||
std::string platform;
|
||||
if (!related_application->GetString(kPlatform, &platform) ||
|
||||
if (!related_application.GetString(kPlatform, &platform) ||
|
||||
platform != kPlay) {
|
||||
continue;
|
||||
}
|
||||
@ -302,7 +305,7 @@ void ParsePreferredRelatedApplicationIdentifiers(
|
||||
}
|
||||
|
||||
std::string id;
|
||||
if (!related_application->GetString(kId, &id)) {
|
||||
if (!related_application.GetString(kId, &id)) {
|
||||
log.Warn(base::StringPrintf(
|
||||
"Elements in \"%s\" with \"%s\":\"%s\" should have \"%s\" field.",
|
||||
kRelatedApplications, kPlatform, kPlay, kId));
|
||||
@ -413,18 +416,19 @@ bool PaymentManifestParser::ParseWebAppManifestIntoVector(
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t related_applications_size = list->GetList().size();
|
||||
for (size_t i = 0; i < related_applications_size; ++i) {
|
||||
base::DictionaryValue* related_application = nullptr;
|
||||
if (!list->GetDictionary(i, &related_application) || !related_application) {
|
||||
for (const base::Value& related_application_value : list->GetList()) {
|
||||
if (!related_application_value.is_dict()) {
|
||||
log.Error(base::StringPrintf("\"%s\" must be a list of dictionaries.",
|
||||
kRelatedApplications));
|
||||
output->clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
const base::DictionaryValue& related_application =
|
||||
base::Value::AsDictionaryValue(related_application_value);
|
||||
|
||||
std::string platform;
|
||||
if (!related_application->GetString(kPlatform, &platform) ||
|
||||
if (!related_application.GetString(kPlatform, &platform) ||
|
||||
platform != kPlay) {
|
||||
continue;
|
||||
}
|
||||
@ -437,9 +441,9 @@ bool PaymentManifestParser::ParseWebAppManifestIntoVector(
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!related_application->HasKey(kId) ||
|
||||
!related_application->HasKey(kMinVersion) ||
|
||||
!related_application->HasKey(kFingerprints)) {
|
||||
if (!related_application.HasKey(kId) ||
|
||||
!related_application.HasKey(kMinVersion) ||
|
||||
!related_application.HasKey(kFingerprints)) {
|
||||
log.Error(
|
||||
base::StringPrintf("Each \"%s\": \"%s\" entry in \"%s\" must contain "
|
||||
"\"%s\", \"%s\", and \"%s\".",
|
||||
@ -451,7 +455,7 @@ bool PaymentManifestParser::ParseWebAppManifestIntoVector(
|
||||
WebAppManifestSection section;
|
||||
section.min_version = 0;
|
||||
|
||||
if (!related_application->GetString(kId, §ion.id) ||
|
||||
if (!related_application.GetString(kId, §ion.id) ||
|
||||
section.id.empty() || !base::IsStringASCII(section.id)) {
|
||||
log.Error(
|
||||
base::StringPrintf("\"%s\" must be a non-empty ASCII string.", kId));
|
||||
@ -460,7 +464,7 @@ bool PaymentManifestParser::ParseWebAppManifestIntoVector(
|
||||
}
|
||||
|
||||
std::string min_version;
|
||||
if (!related_application->GetString(kMinVersion, &min_version) ||
|
||||
if (!related_application.GetString(kMinVersion, &min_version) ||
|
||||
min_version.empty() || !base::IsStringASCII(min_version) ||
|
||||
!base::StringToInt64(min_version, §ion.min_version)) {
|
||||
log.Error(base::StringPrintf(
|
||||
@ -469,8 +473,8 @@ bool PaymentManifestParser::ParseWebAppManifestIntoVector(
|
||||
return false;
|
||||
}
|
||||
|
||||
base::ListValue* fingerprints_list = nullptr;
|
||||
if (!related_application->GetList(kFingerprints, &fingerprints_list) ||
|
||||
const base::ListValue* fingerprints_list = nullptr;
|
||||
if (!related_application.GetList(kFingerprints, &fingerprints_list) ||
|
||||
fingerprints_list->GetList().empty() ||
|
||||
fingerprints_list->GetList().size() > kMaximumNumberOfItems) {
|
||||
log.Error(base::StringPrintf(
|
||||
@ -480,13 +484,16 @@ bool PaymentManifestParser::ParseWebAppManifestIntoVector(
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t fingerprints_size = fingerprints_list->GetList().size();
|
||||
for (size_t j = 0; j < fingerprints_size; ++j) {
|
||||
base::DictionaryValue* fingerprint_dict = nullptr;
|
||||
for (const base::Value& fingerprint_dict_value :
|
||||
fingerprints_list->GetList()) {
|
||||
const base::DictionaryValue* fingerprint_dict = nullptr;
|
||||
if (fingerprint_dict_value.is_dict()) {
|
||||
fingerprint_dict =
|
||||
&base::Value::AsDictionaryValue(fingerprint_dict_value);
|
||||
}
|
||||
std::string fingerprint_type;
|
||||
std::string fingerprint_value;
|
||||
if (!fingerprints_list->GetDictionary(j, &fingerprint_dict) ||
|
||||
!fingerprint_dict ||
|
||||
if (!fingerprint_dict ||
|
||||
!fingerprint_dict->GetString("type", &fingerprint_type) ||
|
||||
fingerprint_type != "sha256_cert" ||
|
||||
!fingerprint_dict->GetString("value", &fingerprint_value) ||
|
||||
|
@ -149,14 +149,16 @@ UmaRemoteCallResult ParseJsonFromGMSCore(const std::string& metadata_str,
|
||||
// Go through each matched threat type and pick the most severe.
|
||||
JavaThreatTypes worst_threat_type = JAVA_THREAT_TYPE_MAX_VALUE;
|
||||
const base::DictionaryValue* worst_match = nullptr;
|
||||
for (size_t i = 0; i < matches->GetList().size(); i++) {
|
||||
for (const base::Value& match_value : matches->GetList()) {
|
||||
// Get the threat number
|
||||
const base::DictionaryValue* match;
|
||||
const base::DictionaryValue* match = nullptr;
|
||||
if (match_value.is_dict())
|
||||
match = &base::Value::AsDictionaryValue(match_value);
|
||||
|
||||
std::string threat_num_str;
|
||||
|
||||
int threat_type_num;
|
||||
if (!matches->GetDictionary(i, &match) ||
|
||||
!match->GetString(kJsonKeyThreatType, &threat_num_str) ||
|
||||
if (!match || !match->GetString(kJsonKeyThreatType, &threat_num_str) ||
|
||||
!base::StringToInt(threat_num_str, &threat_type_num)) {
|
||||
continue; // Skip malformed list entries
|
||||
}
|
||||
|
@ -56,12 +56,14 @@ bool ParseResponse(const std::string& response, bool* is_porn) {
|
||||
DLOG(WARNING) << "ParseResponse expected exactly one result";
|
||||
return false;
|
||||
}
|
||||
const base::DictionaryValue* classification_dict = nullptr;
|
||||
if (!classifications_list->GetDictionary(0, &classification_dict)) {
|
||||
const base::Value& classification_value = classifications_list->GetList()[0];
|
||||
if (!classification_value.is_dict()) {
|
||||
DLOG(WARNING) << "ParseResponse failed to parse classification dict";
|
||||
return false;
|
||||
}
|
||||
classification_dict->GetBoolean("pornography", is_porn);
|
||||
const base::DictionaryValue& classification_dict =
|
||||
base::Value::AsDictionaryValue(classification_value);
|
||||
classification_dict.GetBoolean("pornography", is_porn);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -269,7 +269,7 @@ std::unique_ptr<TemplateURLData> TemplateURLDataFromPrepopulatedEngine(
|
||||
}
|
||||
|
||||
std::unique_ptr<TemplateURLData> TemplateURLDataFromOverrideDictionary(
|
||||
const base::DictionaryValue& engine) {
|
||||
const base::Value& engine) {
|
||||
const std::string* string_value = nullptr;
|
||||
|
||||
std::u16string name;
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
namespace base {
|
||||
class DictionaryValue;
|
||||
class Value;
|
||||
}
|
||||
|
||||
namespace TemplateURLPrepopulateData {
|
||||
@ -34,6 +35,6 @@ std::unique_ptr<TemplateURLData> TemplateURLDataFromPrepopulatedEngine(
|
||||
// used in the To/FromDictionary functions above for historical reasons.
|
||||
// TODO(a-v-y) Migrate to single TemplateURLData serialization format.
|
||||
std::unique_ptr<TemplateURLData> TemplateURLDataFromOverrideDictionary(
|
||||
const base::DictionaryValue& engine);
|
||||
const base::Value& engine);
|
||||
|
||||
#endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_DATA_UTIL_H_
|
||||
|
@ -1338,11 +1338,9 @@ std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulatedTemplateURLData(
|
||||
if (!list)
|
||||
return t_urls;
|
||||
|
||||
size_t num_engines = list->GetList().size();
|
||||
for (size_t i = 0; i != num_engines; ++i) {
|
||||
const base::DictionaryValue* engine;
|
||||
if (list->GetDictionary(i, &engine)) {
|
||||
auto t_url = TemplateURLDataFromOverrideDictionary(*engine);
|
||||
for (const base::Value& engine : list->GetList()) {
|
||||
if (engine.is_dict()) {
|
||||
auto t_url = TemplateURLDataFromOverrideDictionary(engine);
|
||||
if (t_url)
|
||||
t_urls.push_back(std::move(t_url));
|
||||
}
|
||||
|
@ -525,11 +525,14 @@ void AccountTrackerService::OnAccountImageUpdated(
|
||||
base::DictionaryValue* dict = nullptr;
|
||||
ListPrefUpdate update(pref_service_, prefs::kAccountInfo);
|
||||
for (size_t i = 0; i < update->GetList().size(); ++i, dict = nullptr) {
|
||||
if (update->GetDictionary(i, &dict)) {
|
||||
base::Value& dict_value = update->GetList()[i];
|
||||
if (dict_value.is_dict()) {
|
||||
dict = static_cast<base::DictionaryValue*>(&dict_value);
|
||||
std::string value;
|
||||
if (dict->GetString(kAccountKeyPath, &value) &&
|
||||
value == account_id.ToString())
|
||||
value == account_id.ToString()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -551,10 +554,12 @@ void AccountTrackerService::LoadFromPrefs() {
|
||||
const base::ListValue* list = pref_service_->GetList(prefs::kAccountInfo);
|
||||
std::set<CoreAccountId> to_remove;
|
||||
for (size_t i = 0; i < list->GetList().size(); ++i) {
|
||||
const base::DictionaryValue* dict = nullptr;
|
||||
if (list->GetDictionary(i, &dict)) {
|
||||
const base::Value& dict_value = list->GetList()[i];
|
||||
if (dict_value.is_dict()) {
|
||||
const base::DictionaryValue& dict =
|
||||
base::Value::AsDictionaryValue(dict_value);
|
||||
std::string value;
|
||||
if (dict->GetString(kAccountKeyPath, &value)) {
|
||||
if (dict.GetString(kAccountKeyPath, &value)) {
|
||||
// Ignore incorrectly persisted non-canonical account ids.
|
||||
if (value.find('@') != std::string::npos &&
|
||||
value != gaia::CanonicalizeEmail(value)) {
|
||||
@ -566,50 +571,49 @@ void AccountTrackerService::LoadFromPrefs() {
|
||||
StartTrackingAccount(account_id);
|
||||
AccountInfo& account_info = accounts_[account_id];
|
||||
|
||||
if (dict->GetString(kAccountGaiaPath, &value))
|
||||
if (dict.GetString(kAccountGaiaPath, &value))
|
||||
account_info.gaia = value;
|
||||
if (dict->GetString(kAccountEmailPath, &value))
|
||||
if (dict.GetString(kAccountEmailPath, &value))
|
||||
account_info.email = value;
|
||||
if (dict->GetString(kAccountHostedDomainPath, &value))
|
||||
if (dict.GetString(kAccountHostedDomainPath, &value))
|
||||
account_info.hosted_domain = value;
|
||||
if (dict->GetString(kAccountFullNamePath, &value))
|
||||
if (dict.GetString(kAccountFullNamePath, &value))
|
||||
account_info.full_name = value;
|
||||
if (dict->GetString(kAccountGivenNamePath, &value))
|
||||
if (dict.GetString(kAccountGivenNamePath, &value))
|
||||
account_info.given_name = value;
|
||||
if (dict->GetString(kAccountLocalePath, &value))
|
||||
if (dict.GetString(kAccountLocalePath, &value))
|
||||
account_info.locale = value;
|
||||
if (dict->GetString(kAccountPictureURLPath, &value))
|
||||
if (dict.GetString(kAccountPictureURLPath, &value))
|
||||
account_info.picture_url = value;
|
||||
if (dict->GetString(kLastDownloadedImageURLWithSizePath, &value))
|
||||
if (dict.GetString(kLastDownloadedImageURLWithSizePath, &value))
|
||||
account_info.last_downloaded_image_url_with_size = value;
|
||||
|
||||
if (absl::optional<bool> is_child_status =
|
||||
dict->FindBoolKey(kDeprecatedChildStatusPath)) {
|
||||
dict.FindBoolKey(kDeprecatedChildStatusPath)) {
|
||||
account_info.is_child_account = is_child_status.value()
|
||||
? signin::Tribool::kTrue
|
||||
: signin::Tribool::kFalse;
|
||||
// Migrate to kAccountChildAttributePath.
|
||||
ListPrefUpdate update(pref_service_, prefs::kAccountInfo);
|
||||
base::DictionaryValue* update_dict = nullptr;
|
||||
update->GetDictionary(i, &update_dict);
|
||||
DCHECK(update_dict);
|
||||
base::Value* update_dict = &update->GetList()[i];
|
||||
DCHECK(update_dict->is_dict());
|
||||
SetAccountCapabilityPath(update_dict, kAccountChildAttributePath,
|
||||
account_info.is_child_account);
|
||||
update_dict->RemoveKey(kDeprecatedChildStatusPath);
|
||||
} else {
|
||||
account_info.is_child_account =
|
||||
FindAccountCapabilityPath(*dict, kAccountChildAttributePath);
|
||||
FindAccountCapabilityPath(dict, kAccountChildAttributePath);
|
||||
}
|
||||
|
||||
bool is_under_advanced_protection = false;
|
||||
if (dict->GetBoolean(kAdvancedProtectionAccountStatusPath,
|
||||
&is_under_advanced_protection)) {
|
||||
if (dict.GetBoolean(kAdvancedProtectionAccountStatusPath,
|
||||
&is_under_advanced_protection)) {
|
||||
account_info.is_under_advanced_protection =
|
||||
is_under_advanced_protection;
|
||||
}
|
||||
|
||||
switch (FindAccountCapabilityPath(
|
||||
*dict, kCanOfferExtendedChromeSyncPromosCapabilityPrefsPath)) {
|
||||
dict, kCanOfferExtendedChromeSyncPromosCapabilityPrefsPath)) {
|
||||
case signin::Tribool::kUnknown:
|
||||
break;
|
||||
case signin::Tribool::kTrue:
|
||||
@ -660,11 +664,14 @@ void AccountTrackerService::SaveToPrefs(const AccountInfo& account_info) {
|
||||
base::DictionaryValue* dict = nullptr;
|
||||
ListPrefUpdate update(pref_service_, prefs::kAccountInfo);
|
||||
for (size_t i = 0; i < update->GetList().size(); ++i, dict = nullptr) {
|
||||
if (update->GetDictionary(i, &dict)) {
|
||||
base::Value& dict_value = update->GetList()[i];
|
||||
if (dict_value.is_dict()) {
|
||||
dict = static_cast<base::DictionaryValue*>(&dict_value);
|
||||
std::string value;
|
||||
if (dict->GetString(kAccountKeyPath, &value) &&
|
||||
value == account_info.account_id.ToString())
|
||||
value == account_info.account_id.ToString()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -672,7 +679,9 @@ void AccountTrackerService::SaveToPrefs(const AccountInfo& account_info) {
|
||||
dict = new base::DictionaryValue();
|
||||
update->Append(base::WrapUnique(dict));
|
||||
// |dict| is invalidated at this point, so it needs to be reset.
|
||||
update->GetDictionary(update->GetList().size() - 1, &dict);
|
||||
base::Value& dict_value = update->GetList().back();
|
||||
DCHECK(dict_value.is_dict());
|
||||
dict = static_cast<base::DictionaryValue*>(&dict_value);
|
||||
dict->SetString(kAccountKeyPath, account_info.account_id.ToString());
|
||||
}
|
||||
|
||||
|
@ -264,27 +264,32 @@ bool SpellingServiceClient::ParseResponse(
|
||||
if (!value->GetList(kMisspellingsRestPath, &misspellings))
|
||||
return true;
|
||||
|
||||
for (size_t i = 0; i < misspellings->GetList().size(); ++i) {
|
||||
for (const base::Value& misspelling_value : misspellings->GetList()) {
|
||||
// Retrieve the i-th misspelling region and put it to the given vector. When
|
||||
// the Spelling service sends two or more suggestions, we read only the
|
||||
// first one because SpellCheckResult can store only one suggestion.
|
||||
base::DictionaryValue* misspelling = nullptr;
|
||||
if (!misspellings->GetDictionary(i, &misspelling))
|
||||
if (!misspelling_value.is_dict())
|
||||
return false;
|
||||
|
||||
const base::DictionaryValue& misspelling =
|
||||
base::Value::AsDictionaryValue(misspelling_value);
|
||||
|
||||
int start = 0;
|
||||
int length = 0;
|
||||
base::ListValue* suggestions = nullptr;
|
||||
if (!misspelling->GetInteger("charStart", &start) ||
|
||||
!misspelling->GetInteger("charLength", &length) ||
|
||||
!misspelling->GetList("suggestions", &suggestions)) {
|
||||
const base::ListValue* suggestions = nullptr;
|
||||
if (!misspelling.GetInteger("charStart", &start) ||
|
||||
!misspelling.GetInteger("charLength", &length) ||
|
||||
!misspelling.GetList("suggestions", &suggestions)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
base::DictionaryValue* suggestion = nullptr;
|
||||
const base::Value& suggestion_value = suggestions->GetList()[0];
|
||||
const base::DictionaryValue* suggestion = nullptr;
|
||||
if (suggestion_value.is_dict())
|
||||
suggestion = &base::Value::AsDictionaryValue(suggestion_value);
|
||||
|
||||
std::u16string replacement;
|
||||
if (!suggestions->GetDictionary(0, &suggestion) ||
|
||||
!suggestion->GetString("suggestion", &replacement)) {
|
||||
if (!suggestion || !suggestion->GetString("suggestion", &replacement)) {
|
||||
return false;
|
||||
}
|
||||
SpellCheckResult result(SpellCheckResult::SPELLING, start, length,
|
||||
|
@ -169,15 +169,20 @@ TEST(ProtoValueConversionsTest, BookmarkSpecificsData) {
|
||||
base::ListValue* meta_info_list;
|
||||
ASSERT_TRUE(value->GetList("meta_info", &meta_info_list));
|
||||
EXPECT_EQ(2u, meta_info_list->GetList().size());
|
||||
base::DictionaryValue* meta_info;
|
||||
const base::Value* meta_info_value;
|
||||
const base::DictionaryValue* meta_info;
|
||||
std::string meta_key;
|
||||
std::string meta_value;
|
||||
ASSERT_TRUE(meta_info_list->GetDictionary(0, &meta_info));
|
||||
meta_info_value = &meta_info_list->GetList()[0];
|
||||
ASSERT_TRUE(meta_info_value->is_dict());
|
||||
meta_info = &base::Value::AsDictionaryValue(*meta_info_value);
|
||||
EXPECT_TRUE(meta_info->GetString("key", &meta_key));
|
||||
EXPECT_TRUE(meta_info->GetString("value", &meta_value));
|
||||
EXPECT_EQ("key1", meta_key);
|
||||
EXPECT_EQ("value1", meta_value);
|
||||
ASSERT_TRUE(meta_info_list->GetDictionary(1, &meta_info));
|
||||
meta_info_value = &meta_info_list->GetList()[1];
|
||||
ASSERT_TRUE(meta_info_value->is_dict());
|
||||
meta_info = &base::Value::AsDictionaryValue(*meta_info_value);
|
||||
EXPECT_TRUE(meta_info->GetString("key", &meta_key));
|
||||
EXPECT_TRUE(meta_info->GetString("value", &meta_value));
|
||||
EXPECT_EQ("key2", meta_key);
|
||||
@ -214,16 +219,17 @@ namespace {
|
||||
bool ValueHasSpecifics(const base::DictionaryValue& value,
|
||||
const std::string& path) {
|
||||
const base::ListValue* entities_list = nullptr;
|
||||
const base::DictionaryValue* entry_dictionary = nullptr;
|
||||
const base::DictionaryValue* specifics_dictionary = nullptr;
|
||||
|
||||
if (!value.GetList(path, &entities_list))
|
||||
return false;
|
||||
|
||||
if (!entities_list->GetDictionary(0, &entry_dictionary))
|
||||
const base::Value& entry_dictionary_value = entities_list->GetList()[0];
|
||||
if (!entry_dictionary_value.is_dict())
|
||||
return false;
|
||||
|
||||
return entry_dictionary->GetDictionary("specifics", &specifics_dictionary);
|
||||
const base::DictionaryValue& entry_dictionary =
|
||||
base::Value::AsDictionaryValue(entry_dictionary_value);
|
||||
const base::DictionaryValue* specifics_dictionary = nullptr;
|
||||
return entry_dictionary.GetDictionary("specifics", &specifics_dictionary);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
@ -224,11 +224,14 @@ bool KnownUser::FindPrefs(const AccountId& account_id,
|
||||
return false;
|
||||
|
||||
const base::ListValue* known_users = local_state_->GetList(kKnownUsers);
|
||||
for (size_t i = 0; i < known_users->GetList().size(); ++i) {
|
||||
const base::DictionaryValue* element = nullptr;
|
||||
if (known_users->GetDictionary(i, &element)) {
|
||||
if (UserMatches(account_id, *element)) {
|
||||
known_users->GetDictionary(i, out_value);
|
||||
for (const base::Value& element_value : known_users->GetList()) {
|
||||
if (element_value.is_dict()) {
|
||||
const base::DictionaryValue& element =
|
||||
base::Value::AsDictionaryValue(element_value);
|
||||
if (UserMatches(account_id, element)) {
|
||||
if (out_value)
|
||||
*out_value = &element;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -250,9 +253,10 @@ void KnownUser::UpdatePrefs(const AccountId& account_id,
|
||||
return;
|
||||
|
||||
ListPrefUpdate update(local_state_, kKnownUsers);
|
||||
for (size_t i = 0; i < update->GetList().size(); ++i) {
|
||||
base::DictionaryValue* element = nullptr;
|
||||
if (update->GetDictionary(i, &element)) {
|
||||
for (base::Value& element_value : update->GetList()) {
|
||||
if (element_value.is_dict()) {
|
||||
base::DictionaryValue* element =
|
||||
static_cast<base::DictionaryValue*>(&element_value);
|
||||
if (UserMatches(account_id, *element)) {
|
||||
if (clear)
|
||||
element->Clear();
|
||||
@ -426,18 +430,19 @@ std::vector<AccountId> KnownUser::GetKnownAccountIds() {
|
||||
std::vector<AccountId> result;
|
||||
|
||||
const base::ListValue* known_users = local_state_->GetList(kKnownUsers);
|
||||
for (size_t i = 0; i < known_users->GetList().size(); ++i) {
|
||||
const base::DictionaryValue* element = nullptr;
|
||||
if (known_users->GetDictionary(i, &element)) {
|
||||
for (const base::Value& element_value : known_users->GetList()) {
|
||||
if (element_value.is_dict()) {
|
||||
const base::DictionaryValue& element =
|
||||
base::Value::AsDictionaryValue(element_value);
|
||||
std::string email;
|
||||
std::string gaia_id;
|
||||
std::string obj_guid;
|
||||
const bool has_email = element->GetString(kCanonicalEmail, &email);
|
||||
const bool has_gaia_id = element->GetString(kGAIAIdKey, &gaia_id);
|
||||
const bool has_obj_guid = element->GetString(kObjGuidKey, &obj_guid);
|
||||
const bool has_email = element.GetString(kCanonicalEmail, &email);
|
||||
const bool has_gaia_id = element.GetString(kGAIAIdKey, &gaia_id);
|
||||
const bool has_obj_guid = element.GetString(kObjGuidKey, &obj_guid);
|
||||
AccountType account_type = AccountType::GOOGLE;
|
||||
std::string account_type_string;
|
||||
if (element->GetString(kAccountTypeKey, &account_type_string)) {
|
||||
if (element.GetString(kAccountTypeKey, &account_type_string)) {
|
||||
account_type = AccountId::StringToAccountType(account_type_string);
|
||||
}
|
||||
switch (account_type) {
|
||||
|
@ -1493,13 +1493,15 @@ IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, BrowserGetTargets) {
|
||||
base::ListValue* target_infos;
|
||||
EXPECT_TRUE(result_->GetList("targetInfos", &target_infos));
|
||||
EXPECT_EQ(1u, target_infos->GetList().size());
|
||||
base::DictionaryValue* target_info;
|
||||
EXPECT_TRUE(target_infos->GetDictionary(0u, &target_info));
|
||||
const base::Value& target_info_value = target_infos->GetList()[0u];
|
||||
EXPECT_TRUE(target_info_value.is_dict());
|
||||
const base::DictionaryValue& target_info =
|
||||
base::Value::AsDictionaryValue(target_info_value);
|
||||
std::string target_id, type, title, url;
|
||||
EXPECT_TRUE(target_info->GetString("targetId", &target_id));
|
||||
EXPECT_TRUE(target_info->GetString("type", &type));
|
||||
EXPECT_TRUE(target_info->GetString("title", &title));
|
||||
EXPECT_TRUE(target_info->GetString("url", &url));
|
||||
EXPECT_TRUE(target_info.GetString("targetId", &target_id));
|
||||
EXPECT_TRUE(target_info.GetString("type", &type));
|
||||
EXPECT_TRUE(target_info.GetString("title", &title));
|
||||
EXPECT_TRUE(target_info.GetString("url", &url));
|
||||
EXPECT_EQ("page", type);
|
||||
EXPECT_EQ("about:blank", title);
|
||||
EXPECT_EQ("about:blank", url);
|
||||
@ -1916,12 +1918,14 @@ IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, SetAndGetCookies) {
|
||||
EXPECT_TRUE(result_->GetList("cookies", &cookies));
|
||||
EXPECT_EQ(1u, cookies->GetList().size());
|
||||
|
||||
base::DictionaryValue* cookie;
|
||||
const base::Value& cookie_value = cookies->GetList()[0];
|
||||
EXPECT_TRUE(cookie_value.is_dict());
|
||||
const base::DictionaryValue& cookie =
|
||||
base::Value::AsDictionaryValue(cookie_value);
|
||||
std::string name;
|
||||
std::string value;
|
||||
EXPECT_TRUE(cookies->GetDictionary(0, &cookie));
|
||||
EXPECT_TRUE(cookie->GetString("name", &name));
|
||||
EXPECT_TRUE(cookie->GetString("value", &value));
|
||||
EXPECT_TRUE(cookie.GetString("name", &name));
|
||||
EXPECT_TRUE(cookie.GetString("value", &value));
|
||||
EXPECT_EQ("cookie_for_this_url", name);
|
||||
EXPECT_EQ("mendacious", value);
|
||||
|
||||
@ -1934,15 +1938,17 @@ IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, SetAndGetCookies) {
|
||||
|
||||
// Note: the cookies will be returned in unspecified order.
|
||||
size_t found = 0;
|
||||
for (size_t i = 0; i < cookies->GetList().size(); i++) {
|
||||
EXPECT_TRUE(cookies->GetDictionary(i, &cookie));
|
||||
EXPECT_TRUE(cookie->GetString("name", &name));
|
||||
for (const base::Value& cookie_value : cookies->GetList()) {
|
||||
EXPECT_TRUE(cookie_value.is_dict());
|
||||
const base::DictionaryValue& cookie =
|
||||
base::Value::AsDictionaryValue(cookie_value);
|
||||
EXPECT_TRUE(cookie.GetString("name", &name));
|
||||
if (name == "cookie_for_this_url") {
|
||||
EXPECT_TRUE(cookie->GetString("value", &value));
|
||||
EXPECT_TRUE(cookie.GetString("value", &value));
|
||||
EXPECT_EQ("mendacious", value);
|
||||
found++;
|
||||
} else if (name == "cookie_for_another_url") {
|
||||
EXPECT_TRUE(cookie->GetString("value", &value));
|
||||
EXPECT_TRUE(cookie.GetString("value", &value));
|
||||
EXPECT_EQ("polyglottal", value);
|
||||
found++;
|
||||
} else {
|
||||
|
@ -98,12 +98,13 @@ bool DevToolsProtocolTest::HasListItem(const std::string& path_to_list,
|
||||
if (!result_->GetList(path_to_list, &list))
|
||||
return false;
|
||||
|
||||
for (size_t i = 0; i != list->GetList().size(); i++) {
|
||||
base::DictionaryValue* item;
|
||||
if (!list->GetDictionary(i, &item))
|
||||
for (const base::Value& item_value : list->GetList()) {
|
||||
if (!item_value.is_dict())
|
||||
return false;
|
||||
const base::DictionaryValue& item =
|
||||
base::Value::AsDictionaryValue(item_value);
|
||||
std::string id;
|
||||
if (!item->GetString(name, &id))
|
||||
if (!item.GetString(name, &id))
|
||||
return false;
|
||||
if (id == value)
|
||||
return true;
|
||||
|
@ -257,17 +257,18 @@ class MouseLatencyBrowserTest : public ContentBrowserTest {
|
||||
std::string ShowTraceEventsWithId(const std::string& id_to_show,
|
||||
const base::ListValue* traceEvents) {
|
||||
std::stringstream stream;
|
||||
for (size_t i = 0; i < traceEvents->GetList().size(); ++i) {
|
||||
const base::DictionaryValue* traceEvent;
|
||||
if (!traceEvents->GetDictionary(i, &traceEvent))
|
||||
for (const base::Value& traceEvent_value : traceEvents->GetList()) {
|
||||
if (!traceEvent_value.is_dict())
|
||||
continue;
|
||||
const base::DictionaryValue& traceEvent =
|
||||
base::Value::AsDictionaryValue(traceEvent_value);
|
||||
|
||||
std::string id;
|
||||
if (!traceEvent->GetString("id", &id))
|
||||
if (!traceEvent.GetString("id", &id))
|
||||
continue;
|
||||
|
||||
if (id == id_to_show)
|
||||
stream << *traceEvent;
|
||||
stream << traceEvent;
|
||||
}
|
||||
return stream.str();
|
||||
}
|
||||
@ -282,18 +283,19 @@ class MouseLatencyBrowserTest : public ContentBrowserTest {
|
||||
|
||||
std::map<std::string, int> trace_ids;
|
||||
|
||||
for (size_t i = 0; i < traceEvents->GetList().size(); ++i) {
|
||||
const base::DictionaryValue* traceEvent;
|
||||
ASSERT_TRUE(traceEvents->GetDictionary(i, &traceEvent));
|
||||
for (const base::Value& traceEvent_value : traceEvents->GetList()) {
|
||||
ASSERT_TRUE(traceEvent_value.is_dict());
|
||||
const base::DictionaryValue& traceEvent =
|
||||
base::Value::AsDictionaryValue(traceEvent_value);
|
||||
|
||||
std::string name;
|
||||
ASSERT_TRUE(traceEvent->GetString("name", &name));
|
||||
ASSERT_TRUE(traceEvent.GetString("name", &name));
|
||||
|
||||
if (name != trace_event_name)
|
||||
continue;
|
||||
|
||||
std::string id;
|
||||
if (traceEvent->GetString("id", &id))
|
||||
if (traceEvent.GetString("id", &id))
|
||||
++trace_ids[id];
|
||||
}
|
||||
|
||||
@ -335,12 +337,13 @@ IN_PROC_BROWSER_TEST_F(MouseLatencyBrowserTest,
|
||||
|
||||
std::vector<std::string> trace_event_names;
|
||||
|
||||
for (size_t i = 0; i < traceEvents->GetList().size(); ++i) {
|
||||
const base::DictionaryValue* traceEvent;
|
||||
ASSERT_TRUE(traceEvents->GetDictionary(i, &traceEvent));
|
||||
for (const base::Value& traceEvent_value : traceEvents->GetList()) {
|
||||
ASSERT_TRUE(traceEvent_value.is_dict());
|
||||
const base::DictionaryValue& traceEvent =
|
||||
base::Value::AsDictionaryValue(traceEvent_value);
|
||||
|
||||
std::string name;
|
||||
ASSERT_TRUE(traceEvent->GetString("name", &name));
|
||||
ASSERT_TRUE(traceEvent.GetString("name", &name));
|
||||
|
||||
if (name != "InputLatency::MouseUp" && name != "InputLatency::MouseDown")
|
||||
continue;
|
||||
|
@ -570,14 +570,14 @@ void ServiceWorkerInternalsHandler::HandleStopWorker(const ListValue* args) {
|
||||
return;
|
||||
std::string callback_id = args->GetList()[0].GetString();
|
||||
|
||||
const DictionaryValue* cmd_args = nullptr;
|
||||
if (!args->GetDictionary(1, &cmd_args))
|
||||
const base::Value& cmd_args = args->GetList()[1];
|
||||
if (!cmd_args.is_dict())
|
||||
return;
|
||||
|
||||
absl::optional<int> partition_id = cmd_args->FindIntKey("partition_id");
|
||||
absl::optional<int> partition_id = cmd_args.FindIntKey("partition_id");
|
||||
scoped_refptr<ServiceWorkerContextWrapper> context;
|
||||
int64_t version_id = 0;
|
||||
const std::string* version_id_string = cmd_args->FindStringKey("version_id");
|
||||
const std::string* version_id_string = cmd_args.FindStringKey("version_id");
|
||||
if (!partition_id || !GetServiceWorkerContext(*partition_id, &context) ||
|
||||
!version_id_string ||
|
||||
!base::StringToInt64(*version_id_string, &version_id)) {
|
||||
@ -596,13 +596,13 @@ void ServiceWorkerInternalsHandler::HandleInspectWorker(const ListValue* args) {
|
||||
return;
|
||||
std::string callback_id = args->GetList()[0].GetString();
|
||||
|
||||
const DictionaryValue* cmd_args = nullptr;
|
||||
if (!args->GetDictionary(1, &cmd_args))
|
||||
const base::Value& cmd_args = args->GetList()[1];
|
||||
if (!cmd_args.is_dict())
|
||||
return;
|
||||
|
||||
absl::optional<int> process_host_id = cmd_args->FindIntKey("process_host_id");
|
||||
absl::optional<int> process_host_id = cmd_args.FindIntKey("process_host_id");
|
||||
absl::optional<int> devtools_agent_route_id =
|
||||
cmd_args->FindIntKey("devtools_agent_route_id");
|
||||
cmd_args.FindIntKey("devtools_agent_route_id");
|
||||
if (!process_host_id || !devtools_agent_route_id) {
|
||||
return;
|
||||
}
|
||||
@ -627,13 +627,13 @@ void ServiceWorkerInternalsHandler::HandleUnregister(const ListValue* args) {
|
||||
return;
|
||||
std::string callback_id = args->GetList()[0].GetString();
|
||||
|
||||
const DictionaryValue* cmd_args = nullptr;
|
||||
if (!args->GetDictionary(1, &cmd_args))
|
||||
const base::Value& cmd_args = args->GetList()[1];
|
||||
if (!cmd_args.is_dict())
|
||||
return;
|
||||
|
||||
absl::optional<int> partition_id = cmd_args->FindIntKey("partition_id");
|
||||
absl::optional<int> partition_id = cmd_args.FindIntKey("partition_id");
|
||||
scoped_refptr<ServiceWorkerContextWrapper> context;
|
||||
const std::string* scope_string = cmd_args->FindStringKey("scope");
|
||||
const std::string* scope_string = cmd_args.FindStringKey("scope");
|
||||
if (!partition_id || !GetServiceWorkerContext(*partition_id, &context) ||
|
||||
!scope_string) {
|
||||
return;
|
||||
@ -651,14 +651,14 @@ void ServiceWorkerInternalsHandler::HandleStartWorker(const ListValue* args) {
|
||||
return;
|
||||
std::string callback_id = args->GetList()[0].GetString();
|
||||
|
||||
const DictionaryValue* cmd_args = nullptr;
|
||||
if (!args->GetDictionary(1, &cmd_args))
|
||||
const base::Value& cmd_args = args->GetList()[1];
|
||||
if (!cmd_args.is_dict())
|
||||
return;
|
||||
|
||||
absl::optional<int> partition_id = cmd_args->FindIntKey("partition_id");
|
||||
absl::optional<int> partition_id = cmd_args.FindIntKey("partition_id");
|
||||
|
||||
scoped_refptr<ServiceWorkerContextWrapper> context;
|
||||
const std::string* scope_string = cmd_args->FindStringKey("scope");
|
||||
const std::string* scope_string = cmd_args.FindStringKey("scope");
|
||||
if (!partition_id || !GetServiceWorkerContext(*partition_id, &context) ||
|
||||
!scope_string) {
|
||||
return;
|
||||
|
@ -256,16 +256,17 @@ class MAYBE_WebRtcInternalsBrowserTest: public ContentBrowserTest {
|
||||
EXPECT_EQ(requests.size(), list_request->GetList().size());
|
||||
|
||||
for (size_t i = 0; i < requests.size(); ++i) {
|
||||
base::DictionaryValue* dict = nullptr;
|
||||
ASSERT_TRUE(list_request->GetDictionary(i, &dict));
|
||||
absl::optional<int> rid = dict->FindIntKey("rid");
|
||||
absl::optional<int> pid = dict->FindIntKey("pid");
|
||||
const base::Value& value = list_request->GetList()[i];
|
||||
ASSERT_TRUE(value.is_dict());
|
||||
absl::optional<int> rid = value.FindIntKey("rid");
|
||||
absl::optional<int> pid = value.FindIntKey("pid");
|
||||
std::string origin, audio, video;
|
||||
ASSERT_TRUE(rid);
|
||||
ASSERT_TRUE(pid);
|
||||
ASSERT_TRUE(dict->GetString("origin", &origin));
|
||||
ASSERT_TRUE(dict->GetString("audio", &audio));
|
||||
ASSERT_TRUE(dict->GetString("video", &video));
|
||||
const base::DictionaryValue& dict = base::Value::AsDictionaryValue(value);
|
||||
ASSERT_TRUE(dict.GetString("origin", &origin));
|
||||
ASSERT_TRUE(dict.GetString("audio", &audio));
|
||||
ASSERT_TRUE(dict.GetString("video", &video));
|
||||
EXPECT_EQ(requests[i].rid, *rid);
|
||||
EXPECT_EQ(requests[i].pid, *pid);
|
||||
EXPECT_EQ(requests[i].origin, origin);
|
||||
|
@ -301,17 +301,21 @@ class GeolocationNetworkProviderTest : public testing::Test {
|
||||
ASSERT_TRUE(
|
||||
JsonGetList("wifiAccessPoints", *request_json, &wifi_aps_json));
|
||||
for (size_t i = 0; i < expected_wifi_aps_json.GetList().size(); ++i) {
|
||||
const base::DictionaryValue* expected_json;
|
||||
ASSERT_TRUE(expected_wifi_aps_json.GetDictionary(i, &expected_json));
|
||||
const base::DictionaryValue* actual_json;
|
||||
ASSERT_TRUE(wifi_aps_json->GetDictionary(i, &actual_json));
|
||||
const base::Value& expected_json_value =
|
||||
expected_wifi_aps_json.GetList()[i];
|
||||
ASSERT_TRUE(expected_json_value.is_dict());
|
||||
const base::DictionaryValue& expected_json =
|
||||
base::Value::AsDictionaryValue(expected_json_value);
|
||||
const base::Value& actual_json_value = wifi_aps_json->GetList()[i];
|
||||
ASSERT_TRUE(actual_json_value.is_dict());
|
||||
const base::DictionaryValue& actual_json =
|
||||
base::Value::AsDictionaryValue(actual_json_value);
|
||||
ASSERT_TRUE(JsonFieldEquals("macAddress", expected_json, actual_json));
|
||||
ASSERT_TRUE(
|
||||
JsonFieldEquals("macAddress", *expected_json, *actual_json));
|
||||
JsonFieldEquals("signalStrength", expected_json, actual_json));
|
||||
ASSERT_TRUE(JsonFieldEquals("channel", expected_json, actual_json));
|
||||
ASSERT_TRUE(
|
||||
JsonFieldEquals("signalStrength", *expected_json, *actual_json));
|
||||
ASSERT_TRUE(JsonFieldEquals("channel", *expected_json, *actual_json));
|
||||
ASSERT_TRUE(JsonFieldEquals("signalToNoiseRatio", *expected_json,
|
||||
*actual_json));
|
||||
JsonFieldEquals("signalToNoiseRatio", expected_json, actual_json));
|
||||
}
|
||||
} else {
|
||||
ASSERT_FALSE(request_json->HasKey("wifiAccessPoints"));
|
||||
|
@ -171,26 +171,26 @@ net::ct::SignedCertificateTimestamp::Origin SCTOriginStringToOrigin(
|
||||
return ::testing::AssertionFailure() << "Failed to serialize SCT";
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < report_list.GetList().size(); i++) {
|
||||
const base::DictionaryValue* report_sct;
|
||||
if (!report_list.GetDictionary(i, &report_sct)) {
|
||||
for (const base::Value& report_sct_value : report_list.GetList()) {
|
||||
if (!report_sct_value.is_dict()) {
|
||||
return ::testing::AssertionFailure()
|
||||
<< "Failed to get dictionary value from report SCT list";
|
||||
}
|
||||
|
||||
const base::DictionaryValue& report_sct =
|
||||
base::Value::AsDictionaryValue(report_sct_value);
|
||||
std::string serialized_sct;
|
||||
EXPECT_TRUE(report_sct->GetString("serialized_sct", &serialized_sct));
|
||||
EXPECT_TRUE(report_sct.GetString("serialized_sct", &serialized_sct));
|
||||
std::string decoded_serialized_sct;
|
||||
EXPECT_TRUE(base::Base64Decode(serialized_sct, &decoded_serialized_sct));
|
||||
if (decoded_serialized_sct != expected_serialized_sct)
|
||||
continue;
|
||||
|
||||
std::string source;
|
||||
EXPECT_TRUE(report_sct->GetString("source", &source));
|
||||
EXPECT_TRUE(report_sct.GetString("source", &source));
|
||||
EXPECT_EQ(expected_sct->origin, SCTOriginStringToOrigin(source));
|
||||
|
||||
std::string report_status;
|
||||
EXPECT_TRUE(report_sct->GetString("status", &report_status));
|
||||
EXPECT_TRUE(report_sct.GetString("status", &report_status));
|
||||
switch (expected_status) {
|
||||
case net::ct::SCT_STATUS_LOG_UNKNOWN:
|
||||
EXPECT_EQ("unknown", report_status);
|
||||
|
Reference in New Issue
Block a user