0

[Code Health] Remove usage of DictionaryValue::GetBoolean() under components

Bug: 1187033
Change-Id: Ib40209840043f4c657129c49f776af5bda4a0bb9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3261897
Commit-Queue: Nan Lin <linnan@chromium.org>
Reviewed-by: Alan Screen <awscreen@chromium.org>
Reviewed-by: manuk hovanesian <manukh@chromium.org>
Reviewed-by: Marc Treib <treib@chromium.org>
Reviewed-by: Kristi Park <kristipark@chromium.org>
Reviewed-by: Alex Ilin <alexilin@chromium.org>
Reviewed-by: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: Alexander Alekseev <alemate@chromium.org>
Reviewed-by: Kevin McNee <mcnee@chromium.org>
Reviewed-by: Matt Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/main@{#940940}
This commit is contained in:
Nan Lin
2021-11-11 22:09:18 +00:00
committed by Chromium LUCI CQ
parent a57e961811
commit 5e28dd263a
9 changed files with 42 additions and 28 deletions
components
dom_distiller
guest_view
ntp_tiles
omnibox
payments
printing
safe_search_api
signin
internal
user_manager

@ -162,14 +162,13 @@ std::vector<double> CalculateDerivedFeaturesFromJSON(
return std::vector<double>();
}
bool isOGArticle = false;
std::string url, innerText, textContent, innerHTML;
absl::optional<double> numElements = dict->FindDoubleKey("numElements");
absl::optional<double> numAnchors = dict->FindDoubleKey("numAnchors");
absl::optional<double> numForms = dict->FindDoubleKey("numForms");
if (!(dict->GetBoolean("opengraph", &isOGArticle) &&
dict->GetString("url", &url) && numElements && numAnchors && numForms &&
absl::optional<bool> isOGArticle = dict->FindBoolKey("opengraph");
if (!(isOGArticle.has_value() && dict->GetString("url", &url) &&
numElements && numAnchors && numForms &&
dict->GetString("innerText", &innerText) &&
dict->GetString("textContent", &textContent) &&
dict->GetString("innerHTML", &innerHTML))) {
@ -181,7 +180,7 @@ std::vector<double> CalculateDerivedFeaturesFromJSON(
return std::vector<double>();
}
return CalculateDerivedFeatures(isOGArticle, parsed_url, *numElements,
return CalculateDerivedFeatures(isOGArticle.value(), parsed_url, *numElements,
*numAnchors, *numForms, innerText,
textContent, innerHTML);
}

@ -809,8 +809,9 @@ double GuestViewBase::GetEmbedderZoomFactor() const {
void GuestViewBase::SetUpSizing(const base::DictionaryValue& params) {
// Read the autosize parameters passed in from the embedder.
bool auto_size_enabled = auto_size_enabled_;
params.GetBoolean(kAttributeAutoSize, &auto_size_enabled);
absl::optional<bool> auto_size_enabled_opt =
params.FindBoolKey(kAttributeAutoSize);
bool auto_size_enabled = auto_size_enabled_opt.value_or(auto_size_enabled_);
int max_height = max_auto_size_.height();
int max_width = max_auto_size_.width();
@ -831,8 +832,9 @@ void GuestViewBase::SetUpSizing(const base::DictionaryValue& params) {
int normal_width = normal_size_.width();
// If the element size was provided in logical units (versus physical), then
// it will be converted to physical units.
bool element_size_is_logical = false;
params.GetBoolean(kElementSizeIsLogical, &element_size_is_logical);
absl::optional<bool> element_size_is_logical_opt =
params.FindBoolKey(kElementSizeIsLogical);
bool element_size_is_logical = element_size_is_logical_opt.value_or(false);
if (element_size_is_logical) {
// Convert the element size from logical pixels to physical pixels.
normal_height = LogicalPixelsToPhysicalPixels(element_height);

@ -147,7 +147,9 @@ PopularSites::SitesVector ParseSiteList(const base::ListValue& list) {
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);
absl::optional<bool> baked_in = item.FindBoolKey("baked_in");
if (baked_in.has_value())
sites.back().baked_in = baked_in.value();
}
return sites;
}

@ -501,9 +501,9 @@ bool SearchSuggestionParser::ParseSuggestResults(
// Check if the active suggest field trial (if any) has triggered either
// for the default provider or keyword provider.
results->field_trial_triggered = false;
extras->GetBoolean("google:fieldtrialtriggered",
&results->field_trial_triggered);
absl::optional<bool> field_trial_triggered =
extras->FindBoolKey("google:fieldtrialtriggered");
results->field_trial_triggered = field_trial_triggered.value_or(false);
results->experiment_stats.clear();
if (extras->GetList("google:experimentstats", &experiment_stats) &&

@ -251,15 +251,15 @@ void ParsePreferredRelatedApplicationIdentifiers(
if (!dict.HasKey(kPreferRelatedApplications))
return;
bool prefer_related_applications = false;
if (!dict.GetBoolean(kPreferRelatedApplications,
&prefer_related_applications)) {
absl::optional<bool> prefer_related_applications =
dict.FindBoolKey(kPreferRelatedApplications);
if (!prefer_related_applications.has_value()) {
log.Warn(base::StringPrintf("The \"%s\" field should be a boolean.",
kPreferRelatedApplications));
return;
}
if (!prefer_related_applications)
if (!prefer_related_applications.value())
return;
const base::ListValue* related_applications = nullptr;
@ -561,9 +561,10 @@ bool PaymentManifestParser::ParseWebAppInstallationInfoIntoStructs(
service_worker_dict->GetString(kServiceWorkerScope,
&installation_info->sw_scope);
bool use_cache = false;
if (service_worker_dict->GetBoolean(kServiceWorkerUseCache, &use_cache)) {
installation_info->sw_use_cache = use_cache;
absl::optional<bool> use_cache =
service_worker_dict->FindBoolKey(kServiceWorkerUseCache);
if (use_cache.has_value()) {
installation_info->sw_use_cache = use_cache.value();
}
}

@ -2292,14 +2292,16 @@ bool PrintRenderFrameHelper::UpdatePrintSettings(
}
// Validate expected print preview settings.
absl::optional<bool> is_first_request =
job_settings->FindBoolKey(kIsFirstRequest);
if (!job_settings->GetInteger(kPreviewRequestID,
&settings->params->preview_request_id) ||
!job_settings->GetBoolean(kIsFirstRequest,
&settings->params->is_first_request)) {
!is_first_request.has_value()) {
NOTREACHED();
print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING);
return false;
}
settings->params->is_first_request = is_first_request.value();
settings->params->print_to_pdf = IsPrintToPdfRequested(*job_settings);
UpdateFrameMarginsCssInfo(*job_settings);

@ -63,7 +63,10 @@ bool ParseResponse(const std::string& response, bool* is_porn) {
}
const base::DictionaryValue& classification_dict =
base::Value::AsDictionaryValue(classification_value);
classification_dict.GetBoolean("pornography", is_porn);
absl::optional<bool> is_porn_opt =
classification_dict.FindBoolKey("pornography");
if (is_porn_opt.has_value())
*is_porn = is_porn_opt.value();
return true;
}

@ -605,11 +605,11 @@ void AccountTrackerService::LoadFromPrefs() {
FindAccountCapabilityPath(dict, kAccountChildAttributePath);
}
bool is_under_advanced_protection = false;
if (dict.GetBoolean(kAdvancedProtectionAccountStatusPath,
&is_under_advanced_protection)) {
absl::optional<bool> is_under_advanced_protection =
dict.FindBoolKey(kAdvancedProtectionAccountStatusPath);
if (is_under_advanced_protection.has_value()) {
account_info.is_under_advanced_protection =
is_under_advanced_protection;
is_under_advanced_protection.value();
}
switch (FindAccountCapabilityPath(

@ -297,7 +297,12 @@ bool KnownUser::GetBooleanPref(const AccountId& account_id,
if (!FindPrefs(account_id, &user_pref_dict))
return false;
return user_pref_dict->GetBoolean(path, out_value);
absl::optional<bool> ret_value = user_pref_dict->FindBoolPath(path);
if (!ret_value.has_value())
return false;
*out_value = ret_value.value();
return true;
}
void KnownUser::SetBooleanPref(const AccountId& account_id,