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( ...@@ -469,7 +469,6 @@ bool SearchSuggestionParser::ParseSuggestResults(
const base::ListValue* relevances = nullptr; const base::ListValue* relevances = nullptr;
const base::ListValue* experiment_stats = nullptr; const base::ListValue* experiment_stats = nullptr;
const base::ListValue* suggestion_details = nullptr; const base::ListValue* suggestion_details = nullptr;
const base::DictionaryValue* headers = nullptr;
const base::ListValue* subtype_identifiers = nullptr; const base::ListValue* subtype_identifiers = nullptr;
const base::DictionaryValue* extras = nullptr; const base::DictionaryValue* extras = nullptr;
const base::Value* suggestsubtypes = nullptr; const base::Value* suggestsubtypes = nullptr;
...@@ -504,9 +503,11 @@ bool SearchSuggestionParser::ParseSuggestResults( ...@@ -504,9 +503,11 @@ bool SearchSuggestionParser::ParseSuggestResults(
} }
} }
const base::DictionaryValue* wrapper_dict = nullptr; const base::DictionaryValue* header_texts = nullptr;
if (extras->GetDictionary("google:headertexts", &wrapper_dict) && if (extras->GetDictionary("google:headertexts", &header_texts) &&
wrapper_dict && wrapper_dict->GetDictionary("a", &headers) && headers) { header_texts) {
const base::DictionaryValue* headers = nullptr;
if (header_texts->GetDictionary("a", &headers) && headers) {
for (const auto& it : headers->DictItems()) { for (const auto& it : headers->DictItems()) {
int suggestion_group_id; int suggestion_group_id;
base::StringToInt(it.first, &suggestion_group_id); base::StringToInt(it.first, &suggestion_group_id);
...@@ -515,6 +516,15 @@ bool SearchSuggestionParser::ParseSuggestResults( ...@@ -515,6 +516,15 @@ bool SearchSuggestionParser::ParseSuggestResults(
} }
} }
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());
}
}
}
const base::DictionaryValue* client_data = nullptr; const base::DictionaryValue* client_data = nullptr;
if (extras->GetDictionary("google:clientdata", &client_data) && client_data) if (extras->GetDictionary("google:clientdata", &client_data) && client_data)
client_data->GetInteger("phi", &prefetch_index); client_data->GetInteger("phi", &prefetch_index);
......
...@@ -332,8 +332,11 @@ class SearchSuggestionParser { ...@@ -332,8 +332,11 @@ class SearchSuggestionParser {
// If the relevance values of the results are from the server. // If the relevance values of the results are from the server.
bool relevances_from_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; 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 // Converts JSON loaded by a SimpleURLLoader into UTF-8 and returns the
......
...@@ -251,7 +251,8 @@ TEST(SearchSuggestionParserTest, ParseHeaderInfo) { ...@@ -251,7 +251,8 @@ TEST(SearchSuggestionParserTest, ParseHeaderInfo) {
"a":{ "a":{
"40007":"Not recommended for you", "40007":"Not recommended for you",
"40008":"Recommended for you" "40008":"Recommended for you"
} },
"h":[40007, "40008", "garbage_non_int"]
}, },
"google:suggestdetail":[ "google:suggestdetail":[
{ {
...@@ -280,6 +281,10 @@ TEST(SearchSuggestionParserTest, ParseHeaderInfo) { ...@@ -280,6 +281,10 @@ TEST(SearchSuggestionParserTest, ParseHeaderInfo) {
*root_val, input, scheme_classifier, /*default_result_relevance=*/400, *root_val, input, scheme_classifier, /*default_result_relevance=*/400,
/*is_keyword_result=*/false, &results)); /*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]; const auto& suggestion_result = results.suggest_results[0];
ASSERT_EQ(base::ASCIIToUTF16("los angeles"), 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