Commit a60028f5 authored by Ramya Nagarajan's avatar Ramya Nagarajan Committed by Commit Bot

[NTP] Use lower res thumbnail images for tiles.

Confirmed with the service provider that default image size returned
is 512x512, which is fine to use as-is for tile thumbnails. Options
need to be applied to the same URL to request the image at a higher
resolution when setting as the background image. Using the high res
image for tiles causes a noticeable delay in load time.

Bug: 850314
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Ic0c758d6326ad34017831bc1340cc292242cfa79
Reviewed-on: https://chromium-review.googlesource.com/1098380
Commit-Queue: Ramya Nagarajan <ramyan@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#566992}
parent 8e0b906b
...@@ -175,7 +175,7 @@ customBackgrounds.showImageSelectionDialog = function(dialogTitle) { ...@@ -175,7 +175,7 @@ customBackgrounds.showImageSelectionDialog = function(dialogTitle) {
for (var i = 0; i < coll_img.length; ++i) { for (var i = 0; i < coll_img.length; ++i) {
var tile = document.createElement('div'); var tile = document.createElement('div');
tile.classList.add(customBackgrounds.CLASSES.COLLECTION_TILE); tile.classList.add(customBackgrounds.CLASSES.COLLECTION_TILE);
tile.style.backgroundImage = 'url(' + coll_img[i].imageUrl + ')'; tile.style.backgroundImage = 'url(' + coll_img[i].thumbnailImageUrl + ')';
tile.id = 'img_tile_' + i; tile.id = 'img_tile_' + i;
tile.dataset.url = coll_img[i].imageUrl; tile.dataset.url = coll_img[i].imageUrl;
......
...@@ -45,8 +45,9 @@ CollectionImage& CollectionImage::operator=(CollectionImage&&) = default; ...@@ -45,8 +45,9 @@ CollectionImage& CollectionImage::operator=(CollectionImage&&) = default;
bool operator==(const CollectionImage& lhs, const CollectionImage& rhs) { bool operator==(const CollectionImage& lhs, const CollectionImage& rhs) {
return lhs.collection_id == rhs.collection_id && return lhs.collection_id == rhs.collection_id &&
lhs.asset_id == rhs.asset_id && lhs.image_url == rhs.image_url && lhs.asset_id == rhs.asset_id &&
lhs.attribution == rhs.attribution; lhs.thumbnail_image_url == rhs.thumbnail_image_url &&
lhs.image_url == rhs.image_url && lhs.attribution == rhs.attribution;
} }
bool operator!=(const CollectionImage& lhs, const CollectionImage& rhs) { bool operator!=(const CollectionImage& lhs, const CollectionImage& rhs) {
...@@ -60,6 +61,9 @@ CollectionImage CollectionImage::CreateFromProto( ...@@ -60,6 +61,9 @@ CollectionImage CollectionImage::CreateFromProto(
CollectionImage collection_image; CollectionImage collection_image;
collection_image.collection_id = collection_id; collection_image.collection_id = collection_id;
collection_image.asset_id = image.asset_id(); collection_image.asset_id = image.asset_id();
// Without options added to the image, it is 512x512.
collection_image.thumbnail_image_url = GURL(image.image_url());
// TODO(ramyan): Request resolution from service, instead of setting it here.
collection_image.image_url = GURL( collection_image.image_url = GURL(
image.image_url() + ((image.image_url().find('=') == std::string::npos) image.image_url() + ((image.image_url().find('=') == std::string::npos)
? default_image_options ? default_image_options
......
...@@ -59,6 +59,8 @@ struct CollectionImage { ...@@ -59,6 +59,8 @@ struct CollectionImage {
std::string collection_id; std::string collection_id;
// A unique identifier for the image. // A unique identifier for the image.
uint64_t asset_id; uint64_t asset_id;
// The thumbnail image URL, typically lower resolution than the image_url.
GURL thumbnail_image_url;
// The image URL. // The image URL.
GURL image_url; GURL image_url;
// The attribution list for the image. // The attribution list for the image.
......
...@@ -169,6 +169,7 @@ TEST_F(NtpBackgroundServiceTest, GoodCollectionImagesResponse) { ...@@ -169,6 +169,7 @@ TEST_F(NtpBackgroundServiceTest, GoodCollectionImagesResponse) {
CollectionImage collection_image; CollectionImage collection_image;
collection_image.collection_id = "shapes"; collection_image.collection_id = "shapes";
collection_image.asset_id = image.asset_id(); collection_image.asset_id = image.asset_id();
collection_image.thumbnail_image_url = GURL(image.image_url());
collection_image.image_url = GURL(image.image_url() + kImageOptions); collection_image.image_url = GURL(image.image_url() + kImageOptions);
collection_image.attribution.push_back(image.attribution(0).text()); collection_image.attribution.push_back(image.attribution(0).text());
...@@ -218,6 +219,7 @@ TEST_F(NtpBackgroundServiceTest, MultipleRequests) { ...@@ -218,6 +219,7 @@ TEST_F(NtpBackgroundServiceTest, MultipleRequests) {
CollectionImage collection_image; CollectionImage collection_image;
collection_image.collection_id = "shapes"; collection_image.collection_id = "shapes";
collection_image.asset_id = image.asset_id(); collection_image.asset_id = image.asset_id();
collection_image.thumbnail_image_url = GURL(image.image_url());
collection_image.image_url = GURL(image.image_url() + kImageOptions); collection_image.image_url = GURL(image.image_url() + kImageOptions);
collection_image.attribution.push_back(image.attribution(0).text()); collection_image.attribution.push_back(image.attribution(0).text());
......
...@@ -263,6 +263,8 @@ base::Value ConvertCollectionImageToDict( ...@@ -263,6 +263,8 @@ base::Value ConvertCollectionImageToDict(
images.GetList().reserve(collection_image.size()); images.GetList().reserve(collection_image.size());
for (const CollectionImage& image : collection_image) { for (const CollectionImage& image : collection_image) {
base::Value dict(base::Value::Type::DICTIONARY); base::Value dict(base::Value::Type::DICTIONARY);
dict.SetKey("thumbnailImageUrl",
base::Value(image.thumbnail_image_url.spec()));
dict.SetKey("imageUrl", base::Value(image.image_url.spec())); dict.SetKey("imageUrl", base::Value(image.image_url.spec()));
dict.SetKey("collectionId", base::Value(image.collection_id)); dict.SetKey("collectionId", base::Value(image.collection_id));
base::Value attributions(base::Value::Type::LIST); base::Value attributions(base::Value::Type::LIST);
......
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