Skip to content

Commit

Permalink
[PWA] Fix PWA mobile model metadata processing issues
Browse files Browse the repository at this point in the history
Add a check for input_context to prevent crash when input_context is null after reaching custom input processor.

Enforce input context based custom input features to be float only.

Bug: b/278782487
Change-Id: Ia75a9a562a8fb3c3821156c076df373f0d260a4e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4611100
Reviewed-by: Ella Ge <eirage@chromium.org>
Commit-Queue: Hailey Wang <haileywang@google.com>
Reviewed-by: Siddhartha S <ssid@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1158417}
  • Loading branch information
“Hailey authored and Chromium LUCI CQ committed Jun 15, 2023
1 parent a24dc67 commit f9a7487
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,16 +240,20 @@ bool CustomInputProcessor::AddFromInputContext(
input_name = custom_input_iter->second;
}

auto input_context_iter = input_context->metadata_args.find(input_name);
if (input_context_iter == input_context->metadata_args.end()) {
absl::optional<processing::ProcessedValue> input_context_value;
if (input_context) {
input_context_value = input_context->GetMetadataArgument(input_name);
}

if (!input_context || !input_context_value.has_value()) {
feature_processor_state->SetError(
stats::FeatureProcessingError::kCustomInputError,
"The model expects an input '" + input_name +
"' which wasn't found in the input context.");
return false;
}

out_tensor.emplace_back(input_context_iter->second);
out_tensor.emplace_back(input_context_value.value());
return true;
}

Expand Down
6 changes: 4 additions & 2 deletions components/webapps/browser/android/ambient_badge_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,10 @@ void AmbientBadgeManager::MaybeShowAmbientBadgeSmart(
auto input_context =
base::MakeRefCounted<segmentation_platform::InputContext>();
input_context->metadata_args.emplace("url", validated_url_);
input_context->metadata_args.emplace("maskable_icon",
a2hs_params_->HasMaskablePrimaryIcon());
input_context->metadata_args.emplace(
"maskable_icon",
segmentation_platform::processing::ProcessedValue::FromFloat(
a2hs_params_->HasMaskablePrimaryIcon()));
segmentation_platform_service_->GetClassificationResult(
segmentation_platform::kWebAppInstallationPromoKey, prediction_options,
input_context,
Expand Down

0 comments on commit f9a7487

Please sign in to comment.