Commit 9e191d88 authored by Theresa's avatar Theresa Committed by Commit Bot

[EoC] Use full favicon URL instead of encrypted docid

BUG=833873

Change-Id: I3f00d9258e7b2167c0cadaa41fed2506409b9496
Reviewed-on: https://chromium-review.googlesource.com/1053794Reviewed-by: default avatarNicolas Zea <zea@chromium.org>
Commit-Queue: Theresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557631}
parent 390f99c0
......@@ -60,7 +60,10 @@ void ContextualContentSuggestionsServiceProxy::FetchContextualSuggestionImage(
return;
}
FetchImageImpl(suggestion_iter->second.image_id, std::move(callback));
std::string& image_id = suggestion_iter->second.image_id;
GURL image_url = ImageUrlFromId(image_id);
FetchImageImpl(image_url, image_id, std::move(callback));
}
void ContextualContentSuggestionsServiceProxy::FetchContextualSuggestionFavicon(
......@@ -74,7 +77,8 @@ void ContextualContentSuggestionsServiceProxy::FetchContextualSuggestionFavicon(
return;
}
FetchImageImpl(suggestion_iter->second.favicon_image_id, std::move(callback));
FetchImageImpl(GURL(suggestion_iter->second.favicon_image_url),
suggestion_iter->second.favicon_image_id, std::move(callback));
}
void ContextualContentSuggestionsServiceProxy::ClearState() {
......@@ -111,10 +115,9 @@ void ContextualContentSuggestionsServiceProxy::FlushMetrics() {
}
void ContextualContentSuggestionsServiceProxy::FetchImageImpl(
const GURL& image_url,
const std::string& image_id,
ntp_snippets::ImageFetchedCallback callback) {
GURL image_url = ImageUrlFromId(image_id);
ntp_snippets::ContentSuggestion::ID synthetic_cache_id(
ntp_snippets::Category::FromKnownCategory(
ntp_snippets::KnownCategories::CONTEXTUAL),
......
......@@ -58,7 +58,8 @@ class ContextualContentSuggestionsServiceProxy {
void FlushMetrics();
private:
void FetchImageImpl(const std::string& image_id,
void FetchImageImpl(const GURL& image_url,
const std::string& image_id,
ntp_snippets::ImageFetchedCallback callback);
void CacheSuggestions(ClustersCallback callback,
......
......@@ -21,7 +21,8 @@ ContextualSuggestion::ContextualSuggestion(
publisher_name(std::move(other.publisher_name)),
snippet(std::move(other.snippet)),
image_id(std::move(other.image_id)),
favicon_image_id(std::move(other.favicon_image_id)) {}
favicon_image_id(std::move(other.favicon_image_id)),
favicon_image_url(std::move(other.favicon_image_url)) {}
ContextualSuggestion::~ContextualSuggestion() = default;
......@@ -57,8 +58,14 @@ SuggestionBuilder& SuggestionBuilder::FaviconImageId(
return *this;
}
SuggestionBuilder& SuggestionBuilder::FaviconImageUrl(
const std::string& favicon_image_url) {
suggestion_.favicon_image_url = favicon_image_url;
return *this;
}
ContextualSuggestion SuggestionBuilder::Build() {
return std::move(suggestion_);
}
} // namespace ntp_snippets
\ No newline at end of file
} // namespace ntp_snippets
......@@ -38,6 +38,9 @@ struct ContextualSuggestion {
// As above, but for identifying the favicon for the site the suggestion
// resides on.
std::string favicon_image_id;
// The favicon URL for the suggestion.
std::string favicon_image_url;
};
// Allows compact, precise construction of a ContextualSuggestion. Its main
......@@ -52,6 +55,7 @@ class SuggestionBuilder {
SuggestionBuilder& Snippet(const std::string& snippet);
SuggestionBuilder& ImageId(const std::string& image_id);
SuggestionBuilder& FaviconImageId(const std::string& favicon_image_id);
SuggestionBuilder& FaviconImageUrl(const std::string& favicon_image_url);
ContextualSuggestion Build();
private:
......
......@@ -47,12 +47,19 @@ std::string Unescape(const std::string& encoded_text) {
ContextualSuggestion ItemToSuggestion(const PivotItem& item) {
PivotDocument document = item.document();
std::string favicon_url;
if (document.favicon_image().source_data().has_raster()) {
favicon_url =
document.favicon_image().source_data().raster().url().raw_url();
}
return SuggestionBuilder(GURL(document.url().raw_url()))
.Title(Unescape(document.title()))
.Snippet(Unescape(document.summary()))
.PublisherName(Unescape(document.site_name()))
.ImageId(document.image().id().encrypted_docid())
.FaviconImageId(document.favicon_image().id().encrypted_docid())
.FaviconImageUrl(favicon_url)
.Build();
}
......@@ -301,4 +308,4 @@ void ContextualSuggestionsFetch::ReportFetchMetrics(
std::move(metrics_callback).Run(event);
}
} // namespace contextual_suggestions
\ No newline at end of file
} // namespace contextual_suggestions
......@@ -39,6 +39,7 @@ ClusterBuilder::ClusterBuilder(const ClusterBuilder& other) {
.Snippet(suggestion.snippet)
.ImageId(suggestion.image_id)
.FaviconImageId(suggestion.favicon_image_id)
.FaviconImageUrl(suggestion.favicon_image_url)
.Build());
}
}
......@@ -78,4 +79,4 @@ ContextualSuggestionsResult::~ContextualSuggestionsResult() = default;
ContextualSuggestionsResult& ContextualSuggestionsResult::operator=(
ContextualSuggestionsResult&& other) = default;
} // namespace contextual_suggestions
\ No newline at end of file
} // namespace contextual_suggestions
......@@ -108,6 +108,9 @@ message Url {
message Image {
// The identity of this image.
optional ImageId id = 1;
// The underlying source data that encodes the image.
optional ImageSource source_data = 2;
}
message ImageId {
......@@ -123,3 +126,16 @@ message ImageId {
// ... has an encrypted doc ID of "e-AB_0zkH08qtM".
optional string encrypted_docid = 1;
}
// Represents the underlying encoding / source data for an image.
message ImageSource {
// The raster image representation.
optional RasterImage raster = 1;
}
// A representation of an image as a collection of pixels at a specific size.
message RasterImage {
// A URL at which the image may be retrieved. The format of the image
// is determined by the "Content-Type" of the HTTP response for the URL.
optional Url url = 2;
}
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