Skip to content

Commit

Permalink
[omnibox] Fix calc annotations not showing up.
Browse files Browse the repository at this point in the history
Currently, the calc suggestion for the input '3+4' will display '3+4'
instead of '3+4 \n 7'.

Before CL crrev.com/c/4067382, the suggest response parsing flow was:

    if (IsCalc())
      SetCalcAnnotation();
    if (HasJsonData()
      SetJsonAnnotation();

And that worked fine, because calc suggestions didn't have JSON data, so
they'd get the calc annotations.

CL crrev.com/c/4067382 changed the flow to:

    if (IsCalc())
      SetCalcAnnotation();
    if (HasProtoData()
      SetProtoAnnotation();
    else
      SetJsonAnnotation();

This is problematic, because the non-existent JSON annotation is
overwriting the correct calc annotation.

This CL changes the logic to:

    if (IsCalc())
      SetCalcAnnotation();
    if (HasProtoData()
      SetProtoAnnotation();
    if (HasJsonData())
      SetJsonAnnotation();

Also removes some unused leftover local variables.

Bug: 1402793, 1383985
Change-Id: I5606113334ba6b473b9c6aa562312a85d3cf5b29
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4115267
Reviewed-by: Khalid Peer <khalidpeer@chromium.org>
Commit-Queue: manuk hovanesian <manukh@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1085973}
  • Loading branch information
manukh authored and Chromium LUCI CQ committed Dec 21, 2022
1 parent 0d04fa5 commit 76ff5cf
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions components/omnibox/browser/search_suggestion_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,9 @@ SearchSuggestionParser::SuggestResult::SuggestResult(

SearchSuggestionParser::SuggestResult::~SuggestResult() {}

SearchSuggestionParser::SuggestResult& SearchSuggestionParser::SuggestResult::
operator=(const SuggestResult& rhs) = default;
SearchSuggestionParser::SuggestResult&
SearchSuggestionParser::SuggestResult::operator=(const SuggestResult& rhs) =
default;

void SearchSuggestionParser::SuggestResult::ClassifyMatchContents(
const bool allow_bolding_all,
Expand Down Expand Up @@ -797,10 +798,6 @@ bool SearchSuggestionParser::ParseSuggestResults(
std::u16string match_contents_prefix;
SuggestionAnswer answer;
bool answer_parsed_successfully = false;
std::string image_dominant_color;
std::string image_url;
std::string additional_query_params;
std::string entity_id;
absl::optional<int> suggestion_group_id;
omnibox::EntityInfo entity_info;

Expand All @@ -824,16 +821,16 @@ bool SearchSuggestionParser::ParseSuggestResults(
FindStringKeyOrEmpty(suggestion_detail, "dc"));
entity_info.set_image_url(
FindStringKeyOrEmpty(suggestion_detail, "i"));
entity_info.set_entity_id(
FindStringKeyOrEmpty(suggestion_detail, "zae"));
entity_info.set_suggest_search_parameters(
FindStringKeyOrEmpty(suggestion_detail, "q"));
entity_info.set_entity_id(
FindStringKeyOrEmpty(suggestion_detail, "zae"));
}

match_contents = base::UTF8ToUTF16(entity_info.name());
if (match_contents.empty()) {
match_contents = suggestion;
}
if (!entity_info.annotation().empty())
annotation = base::UTF8ToUTF16(entity_info.annotation());
if (!entity_info.name().empty())
match_contents = base::UTF8ToUTF16(entity_info.name());

match_contents_prefix =
base::UTF8ToUTF16(FindStringKeyOrEmpty(suggestion_detail, "mp"));
Expand Down Expand Up @@ -863,7 +860,7 @@ bool SearchSuggestionParser::ParseSuggestResults(
results->suggest_results.push_back(SuggestResult(
suggestion, match_type, subtypes[index],
base::CollapseWhitespace(match_contents, false),
match_contents_prefix, base::UTF8ToUTF16(entity_info.annotation()),
match_contents_prefix, annotation,
entity_info.suggest_search_parameters(), entity_info.entity_id(),
deletion_url, entity_info.dominant_color(), entity_info.image_url(),
is_keyword_result, relevance, relevances != nullptr, should_prefetch,
Expand Down

0 comments on commit 76ff5cf

Please sign in to comment.