Commit 8986ac5d authored by Tommy Li's avatar Tommy Li Committed by Commit Bot

[omnibox] SearchSuggestionParser to parse hidden_group_ids from "h".

This CL updates SearchSuggestionParser to look for and parse the "h"
sublist under the "google:headertexts" metadata.

The "h" sublist is used to populate the vector of group IDs that should
be hidden by default.

Only integers are accepted out of the list. All non-integers are
discarded.

Bug: 1106096
Change-Id: Iffad7c7a08f09d18abd027c5c7ccec5b4043da82
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2324890Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Commit-Queue: Tommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792731}
parent f540c742
......@@ -469,7 +469,6 @@ bool SearchSuggestionParser::ParseSuggestResults(
const base::ListValue* relevances = nullptr;
const base::ListValue* experiment_stats = nullptr;
const base::ListValue* suggestion_details = nullptr;
const base::DictionaryValue* headers = nullptr;
const base::ListValue* subtype_identifiers = nullptr;
const base::DictionaryValue* extras = nullptr;
const base::Value* suggestsubtypes = nullptr;
......@@ -504,14 +503,25 @@ bool SearchSuggestionParser::ParseSuggestResults(
}
}
const base::DictionaryValue* wrapper_dict = nullptr;
if (extras->GetDictionary("google:headertexts", &wrapper_dict) &&
wrapper_dict && wrapper_dict->GetDictionary("a", &headers) && headers) {
for (const auto& it : headers->DictItems()) {
int suggestion_group_id;
base::StringToInt(it.first, &suggestion_group_id);
results->headers_map[suggestion_group_id] =
base::UTF8ToUTF16(it.second.GetString());
const base::DictionaryValue* header_texts = nullptr;
if (extras->GetDictionary("google:headertexts", &header_texts) &&
header_texts) {
const base::DictionaryValue* headers = nullptr;
if (header_texts->GetDictionary("a", &headers) && headers) {
for (const auto& it : headers->DictItems()) {
int suggestion_group_id;
base::StringToInt(it.first, &suggestion_group_id);
results->headers_map[suggestion_group_id] =
base::UTF8ToUTF16(it.second.GetString());
}
}
const base::ListValue* hidden_group_ids = nullptr;
if (header_texts->GetList("h", &hidden_group_ids) && hidden_group_ids) {
for (const auto& value : hidden_group_ids->GetList()) {
if (value.is_int())
results->hidden_group_ids.emplace_back(value.GetInt());
}
}
}
......
......@@ -332,8 +332,11 @@ class SearchSuggestionParser {
// If the relevance values of the results are from the server.
bool relevances_from_server;
// The server supplied map of suggestion group Ids to headers.
// The server supplied map of suggestion group IDs to header labels.
HeadersMap headers_map;
// The server supplied list of group IDs that should be hidden-by-default.
std::vector<int> hidden_group_ids;
};
// Converts JSON loaded by a SimpleURLLoader into UTF-8 and returns the
......
......@@ -251,7 +251,8 @@ TEST(SearchSuggestionParserTest, ParseHeaderInfo) {
"a":{
"40007":"Not recommended for you",
"40008":"Recommended for you"
}
},
"h":[40007, "40008", "garbage_non_int"]
},
"google:suggestdetail":[
{
......@@ -280,6 +281,10 @@ TEST(SearchSuggestionParserTest, ParseHeaderInfo) {
*root_val, input, scheme_classifier, /*default_result_relevance=*/400,
/*is_keyword_result=*/false, &results));
// Parse integers, and only integers, out of the "h" metadata list.
ASSERT_EQ(1U, results.hidden_group_ids.size());
ASSERT_EQ(40007, results.hidden_group_ids[0]);
{
const auto& suggestion_result = results.suggest_results[0];
ASSERT_EQ(base::ASCIIToUTF16("los angeles"),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment