Commit 37ab83c3 authored by Ramya Nagarajan's avatar Ramya Nagarajan Committed by Commit Bot

[NTP] Configure thumbnail resolution for custom backgrounds dialog.

Images are requested at the exact resolution required for tiles in the
custom background selection dialog, reducing the overall data loaded.

Bug: 851990
Change-Id: I2e29e6d8f7e888ef4c02fdaf156a360471662435
Reviewed-on: https://chromium-review.googlesource.com/1163293Reviewed-by: default avatarKristi Park <kristipark@chromium.org>
Commit-Queue: Ramya Nagarajan <ramyan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580916}
parent dea56ad5
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
#include "chrome/browser/search/background/ntp_background_data.h" #include "chrome/browser/search/background/ntp_background_data.h"
namespace {
// The options to be added to a thumbnail image URL, specifying resolution,
// cropping, etc. Options appear on an image URL after the '=' character. This
// resolution matches the height an width of bg-sel-tile.
constexpr char kThumbnailImageOptions[] = "=w156-h117-p-k-no-nd-mv";
} // namespace
std::string GetThumbnailImageOptionsForTesting() {
return kThumbnailImageOptions;
}
CollectionInfo::CollectionInfo() = default; CollectionInfo::CollectionInfo() = default;
CollectionInfo::CollectionInfo(const CollectionInfo&) = default; CollectionInfo::CollectionInfo(const CollectionInfo&) = default;
CollectionInfo::CollectionInfo(CollectionInfo&&) = default; CollectionInfo::CollectionInfo(CollectionInfo&&) = default;
...@@ -29,7 +40,11 @@ CollectionInfo CollectionInfo::CreateFromProto( ...@@ -29,7 +40,11 @@ CollectionInfo CollectionInfo::CreateFromProto(
collection_info.collection_name = collection.collection_name(); collection_info.collection_name = collection.collection_name();
// Use the first preview image as the representative one for the collection. // Use the first preview image as the representative one for the collection.
if (collection.preview_size() > 0 && collection.preview(0).has_image_url()) { if (collection.preview_size() > 0 && collection.preview(0).has_image_url()) {
collection_info.preview_image_url = GURL(collection.preview(0).image_url()); collection_info.preview_image_url =
GURL(collection.preview(0).image_url() +
((collection.preview(0).image_url().find('=') == std::string::npos)
? kThumbnailImageOptions
: std::string("")));
} }
return collection_info; return collection_info;
...@@ -63,7 +78,10 @@ CollectionImage CollectionImage::CreateFromProto( ...@@ -63,7 +78,10 @@ CollectionImage CollectionImage::CreateFromProto(
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. // Without options added to the image, it is 512x512.
collection_image.thumbnail_image_url = GURL(image.image_url()); collection_image.thumbnail_image_url = GURL(
image.image_url() + ((image.image_url().find('=') == std::string::npos)
? kThumbnailImageOptions
: std::string("")));
// TODO(ramyan): Request resolution from service, instead of setting it here. // 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)
......
...@@ -24,6 +24,8 @@ enum class ErrorType { ...@@ -24,6 +24,8 @@ enum class ErrorType {
AUTH_ERROR AUTH_ERROR
}; };
std::string GetThumbnailImageOptionsForTesting();
// Background images are organized into collections, according to a theme. This // Background images are organized into collections, according to a theme. This
// struct contains the data required to display information about a collection, // struct contains the data required to display information about a collection,
// including a representative image. The complete set of CollectionImages must // including a representative image. The complete set of CollectionImages must
......
...@@ -131,7 +131,8 @@ TEST_F(NtpBackgroundServiceTest, GoodCollectionsResponse) { ...@@ -131,7 +131,8 @@ TEST_F(NtpBackgroundServiceTest, GoodCollectionsResponse) {
CollectionInfo collection_info; CollectionInfo collection_info;
collection_info.collection_id = collection.collection_id(); collection_info.collection_id = collection.collection_id();
collection_info.collection_name = collection.collection_name(); collection_info.collection_name = collection.collection_name();
collection_info.preview_image_url = GURL(collection.preview(0).image_url()); collection_info.preview_image_url = GURL(
collection.preview(0).image_url() + GetThumbnailImageOptionsForTesting());
EXPECT_FALSE(service()->collection_info().empty()); EXPECT_FALSE(service()->collection_info().empty());
EXPECT_THAT(service()->collection_info().at(0), Eq(collection_info)); EXPECT_THAT(service()->collection_info().at(0), Eq(collection_info));
...@@ -186,7 +187,8 @@ TEST_F(NtpBackgroundServiceTest, GoodCollectionImagesResponse) { ...@@ -186,7 +187,8 @@ 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.thumbnail_image_url =
GURL(image.image_url() + GetThumbnailImageOptionsForTesting());
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());
collection_image.attribution_action_url = GURL(image.action_url()); collection_image.attribution_action_url = GURL(image.action_url());
...@@ -233,12 +235,14 @@ TEST_F(NtpBackgroundServiceTest, MultipleRequests) { ...@@ -233,12 +235,14 @@ TEST_F(NtpBackgroundServiceTest, MultipleRequests) {
CollectionInfo collection_info; CollectionInfo collection_info;
collection_info.collection_id = collection.collection_id(); collection_info.collection_id = collection.collection_id();
collection_info.collection_name = collection.collection_name(); collection_info.collection_name = collection.collection_name();
collection_info.preview_image_url = GURL(collection.preview(0).image_url()); collection_info.preview_image_url = GURL(
collection.preview(0).image_url() + GetThumbnailImageOptionsForTesting());
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.thumbnail_image_url =
GURL(image.image_url() + GetThumbnailImageOptionsForTesting());
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());
......
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