Commit db91e01a authored by Dave Schuyler's avatar Dave Schuyler Committed by Commit Bot

[Omnibox] Parse and track image url and dominant color

This CL will parse the rich entity image dominant color and the image
URL. The data is not yet used on the client, that will happen in a later
CL. (Similar to the prior CLs which moved the values from the
CompleteServer to GWS; then from GWS to Chrome; now this moves the values
from the received JSON data to closer to the GUI code).

TBR=mpearson@chromium.org

Bug: 798631
Change-Id: I1d4a31e4b149669c058340ad856ebf89f0663147
Reviewed-on: https://chromium-review.googlesource.com/994129Reviewed-by: default avatarDave Schuyler <dschuyler@chromium.org>
Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Commit-Queue: Dave Schuyler <dschuyler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550500}
parent 858c8cd1
......@@ -3578,6 +3578,8 @@ TEST_F(SearchProviderTest, AnswersCache) {
/*answer=*/nullptr,
/*suggest_query_params=*/std::string(),
/*deletion_url=*/std::string(),
/*image_dominant_color=*/std::string(),
/*image_url=*/std::string(),
/*from_keyword_provider=*/false,
/*relevance=*/1200,
/*relevance_from_server=*/false,
......
......@@ -122,6 +122,8 @@ AutocompleteMatch::AutocompleteMatch(const AutocompleteMatch& match)
allowed_to_be_default_match(match.allowed_to_be_default_match),
destination_url(match.destination_url),
stripped_destination_url(match.stripped_destination_url),
image_dominant_color(match.image_dominant_color),
image_url(match.image_url),
contents(match.contents),
contents_class(match.contents_class),
description(match.description),
......@@ -163,6 +165,8 @@ AutocompleteMatch& AutocompleteMatch::operator=(
allowed_to_be_default_match = match.allowed_to_be_default_match;
destination_url = match.destination_url;
stripped_destination_url = match.stripped_destination_url;
image_dominant_color = match.image_dominant_color;
image_url = match.image_url;
contents = match.contents;
contents_class = match.contents_class;
description = match.description;
......@@ -737,6 +741,8 @@ size_t AutocompleteMatch::EstimateMemoryUsage() const {
res += base::trace_event::EstimateMemoryUsage(inline_autocompletion);
res += base::trace_event::EstimateMemoryUsage(destination_url);
res += base::trace_event::EstimateMemoryUsage(stripped_destination_url);
res += base::trace_event::EstimateMemoryUsage(image_dominant_color);
res += base::trace_event::EstimateMemoryUsage(image_url);
res += base::trace_event::EstimateMemoryUsage(contents);
res += base::trace_event::EstimateMemoryUsage(contents_class);
res += base::trace_event::EstimateMemoryUsage(description);
......
......@@ -391,6 +391,11 @@ struct AutocompleteMatch {
// duplicates.
GURL stripped_destination_url;
// Optional image information. Used for entity suggestions. The dominant color
// can be used to paint the image placeholder while fetching the image.
std::string image_dominant_color;
std::string image_url;
// The main text displayed in the address bar dropdown.
base::string16 contents;
ACMatchClassifications contents_class;
......
......@@ -158,7 +158,9 @@ AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion(
/*answer_type=*/base::string16(),
/*answer=*/nullptr,
/*suggest_query_params=*/std::string(),
/*deletion_url=*/std::string(), from_keyword_provider,
/*deletion_url=*/std::string(),
/*image_dominant_color=*/std::string(),
/*image_url=*/std::string(), from_keyword_provider,
/*relevance=*/0,
/*relevance_from_server=*/false,
/*should_prefetch=*/false,
......@@ -247,6 +249,8 @@ AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion(
if (!template_url)
return match;
match.keyword = template_url->keyword();
match.image_dominant_color = suggestion.image_dominant_color();
match.image_url = suggestion.image_url();
match.contents = suggestion.match_contents();
match.contents_class = suggestion.match_contents_class();
match.answer_contents = suggestion.answer_contents();
......
......@@ -118,6 +118,8 @@ TEST_F(BaseSearchProviderTest, PreserveAnswersWhenDeduplicating) {
/*answer=*/nullptr,
/*suggest_query_params=*/std::string(),
/*deletion_url=*/std::string(),
/*image_dominant_color=*/std::string(),
/*image_url=*/std::string(),
/*from_keyword_provider=*/false,
/*relevance=*/1300,
/*relevance_from_server=*/true,
......@@ -136,6 +138,8 @@ TEST_F(BaseSearchProviderTest, PreserveAnswersWhenDeduplicating) {
SuggestionAnswer::copy(answer.get()),
/*suggest_query_params=*/std::string(),
/*deletion_url=*/std::string(),
/*image_dominant_color=*/std::string(),
/*image_url=*/std::string(),
/*from_keyword_provider=*/false,
/*relevance=*/850,
/*relevance_from_server=*/true,
......@@ -177,6 +181,8 @@ TEST_F(BaseSearchProviderTest, PreserveAnswersWhenDeduplicating) {
SuggestionAnswer::copy(answer2.get()),
/*suggest_query_params=*/std::string(),
/*deletion_url=*/std::string(),
/*image_dominant_color=*/std::string(),
/*image_url=*/std::string(),
/*from_keyword_provider=*/false,
/*relevance=*/1300,
/*relevance_from_server=*/true,
......@@ -233,6 +239,8 @@ TEST_F(BaseSearchProviderTest, MatchTailSuggestionProperly) {
/*answer=*/nullptr,
/*suggest_query_params=*/std::string(),
/*deletion_url=*/std::string(),
/*image_dominant_color=*/std::string(),
/*image_url=*/std::string(),
/*from_keyword_provider=*/false,
/*relevance=*/1300,
/*relevance_from_server=*/true,
......
......@@ -1004,6 +1004,8 @@ void SearchProvider::ConvertResultsToAutocompleteMatches() {
/*annotation=*/base::string16(), answer_contents, answer_type,
std::move(answer), /*suggest_query_params=*/std::string(),
/*deletion_url=*/std::string(),
/*image_dominant_color=*/std::string(),
/*image_url=*/std::string(),
/*from_keyword_provider=*/false, verbatim_relevance,
relevance_from_server, /*should_prefetch=*/false,
/*input_text=*/trimmed_verbatim);
......@@ -1037,6 +1039,8 @@ void SearchProvider::ConvertResultsToAutocompleteMatches() {
/*answer=*/nullptr,
/*suggest_query_params=*/std::string(),
/*deletion_url=*/std::string(),
/*image_dominant_color=*/std::string(),
/*image_url=*/std::string(),
/*from_keyword_provider=*/true, keyword_verbatim_relevance,
keyword_relevance_from_server,
/*should_prefetch=*/false,
......@@ -1232,7 +1236,9 @@ SearchProvider::ScoreHistoryResultsHelper(const HistoryResults& results,
/*answer_type=*/base::string16(),
/*answer=*/nullptr,
/*suggest_query_params=*/std::string(),
/*deletion_url=*/std::string(), is_keyword, relevance,
/*deletion_url=*/std::string(),
/*image_dominant_color=*/std::string(),
/*image_url=*/std::string(), is_keyword, relevance,
/*relevance_from_server=*/false,
/*should_prefetch=*/false, /*input_text=*/trimmed_input);
// History results are synchronous; they are received on the last keystroke.
......
......@@ -87,6 +87,8 @@ SearchSuggestionParser::SuggestResult::SuggestResult(
std::unique_ptr<SuggestionAnswer> answer,
const std::string& suggest_query_params,
const std::string& deletion_url,
const std::string& image_dominant_color,
const std::string& image_url,
bool from_keyword_provider,
int relevance,
bool relevance_from_server,
......@@ -105,6 +107,8 @@ SearchSuggestionParser::SuggestResult::SuggestResult(
answer_contents_(answer_contents),
answer_type_(answer_type),
answer_(std::move(answer)),
image_dominant_color_(image_dominant_color),
image_url_(image_url),
should_prefetch_(should_prefetch) {
match_contents_ = match_contents;
DCHECK(!match_contents_.empty());
......@@ -121,8 +125,9 @@ SearchSuggestionParser::SuggestResult::SuggestResult(
answer_contents_(result.answer_contents_),
answer_type_(result.answer_type_),
answer_(SuggestionAnswer::copy(result.answer_.get())),
should_prefetch_(result.should_prefetch_) {
}
image_dominant_color_(result.image_dominant_color_),
image_url_(result.image_url_),
should_prefetch_(result.should_prefetch_) {}
SearchSuggestionParser::SuggestResult::~SuggestResult() {}
......@@ -141,6 +146,8 @@ SearchSuggestionParser::SuggestResult&
answer_contents_ = rhs.answer_contents_;
answer_type_ = rhs.answer_type_;
answer_ = SuggestionAnswer::copy(rhs.answer_.get());
image_dominant_color_ = rhs.image_dominant_color_;
image_url_ = rhs.image_url_;
should_prefetch_ = rhs.should_prefetch_;
return *this;
......@@ -501,8 +508,9 @@ bool SearchSuggestionParser::ParseSuggestResults(
std::string deletion_url;
if (suggestion_details &&
suggestion_details->GetDictionary(index, &suggestion_detail))
suggestion_details->GetDictionary(index, &suggestion_detail)) {
suggestion_detail->GetString("du", &deletion_url);
}
if ((match_type == AutocompleteMatchType::NAVSUGGEST) ||
(match_type == AutocompleteMatchType::NAVSUGGEST_PERSONALIZED)) {
......@@ -537,6 +545,8 @@ bool SearchSuggestionParser::ParseSuggestResults(
base::string16 answer_contents;
base::string16 answer_type_str;
std::unique_ptr<SuggestionAnswer> answer;
std::string image_dominant_color;
std::string image_url;
std::string suggest_query_params;
if (suggestion_details) {
......@@ -548,6 +558,8 @@ bool SearchSuggestionParser::ParseSuggestResults(
if (match_contents.empty())
match_contents = suggestion;
suggestion_detail->GetString("a", &annotation);
suggestion_detail->GetString("dc", &image_dominant_color);
suggestion_detail->GetString("i", &image_url);
suggestion_detail->GetString("q", &suggest_query_params);
// Extract the Answer, if provided.
......@@ -582,8 +594,8 @@ bool SearchSuggestionParser::ParseSuggestResults(
subtype_identifier, base::CollapseWhitespace(match_contents, false),
match_contents_prefix, annotation, answer_contents, answer_type_str,
std::move(answer), suggest_query_params, deletion_url,
is_keyword_result, relevance, relevances != nullptr, should_prefetch,
trimmed_input));
image_dominant_color, image_url, is_keyword_result, relevance,
relevances != nullptr, should_prefetch, trimmed_input));
}
}
results->relevances_from_server = relevances != nullptr;
......
......@@ -132,6 +132,8 @@ class SearchSuggestionParser {
std::unique_ptr<SuggestionAnswer> answer,
const std::string& suggest_query_params,
const std::string& deletion_url,
const std::string& image_dominant_color,
const std::string& image_url,
bool from_keyword_provider,
int relevance,
bool relevance_from_server,
......@@ -155,6 +157,11 @@ class SearchSuggestionParser {
const base::string16& answer_type() const { return answer_type_; }
const SuggestionAnswer* answer() const { return answer_.get(); }
const std::string& image_dominant_color() const {
return image_dominant_color_;
}
const std::string& image_url() const { return image_url_; }
bool should_prefetch() const { return should_prefetch_; }
// Fills in |match_contents_class_| to reflect how |match_contents_| should
......@@ -197,6 +204,12 @@ class SearchSuggestionParser {
// Optional short answer to the input that produced this suggestion.
std::unique_ptr<SuggestionAnswer> answer_;
// Optional image information. Used for entity suggestions. The dominant
// color can be used to paint the image placeholder while fetching the
// image.
std::string image_dominant_color_;
std::string image_url_;
// Should this result be prefetched?
bool should_prefetch_;
};
......
......@@ -110,6 +110,8 @@ TEST(SearchSuggestionParserTest, ParseSuggestResults) {
"google:suggestdetail": [{
}, {
"a": "American author",
"dc": "#424242",
"i": "http://example.com/a.png",
"q": "gs_ssp=abc",
"t": "Christopher Doe"
}],
......@@ -135,6 +137,9 @@ TEST(SearchSuggestionParserTest, ParseSuggestResults) {
const auto& suggestion_result = results.suggest_results[0];
ASSERT_EQ(base::ASCIIToUTF16("christmas"), suggestion_result.suggestion());
ASSERT_EQ(base::ASCIIToUTF16(""), suggestion_result.annotation());
// This entry has no image.
ASSERT_EQ("", suggestion_result.image_dominant_color());
ASSERT_EQ("", suggestion_result.image_url());
}
{
const auto& suggestion_result = results.suggest_results[1];
......@@ -142,5 +147,7 @@ TEST(SearchSuggestionParserTest, ParseSuggestResults) {
suggestion_result.suggestion());
ASSERT_EQ(base::ASCIIToUTF16("American author"),
suggestion_result.annotation());
ASSERT_EQ("#424242", suggestion_result.image_dominant_color());
ASSERT_EQ("http://example.com/a.png", suggestion_result.image_url());
}
}
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