Commit cff9eaf9 authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Image Fetcher: Add cache config to ImageFetcherParams.

This CL adds a cache config in ImageFetcherParams public API. There is
no internal change in this CL.

Also use reduced mode image fetcher for query tiles project.

Bug: 1067049,1058534
Change-Id: I3accc828e3436d71fbf801f6bdd33d934c51f091
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2133210Reviewed-by: default avatarBrandon Wylie <wylieb@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#757126}
parent b5ce8778
......@@ -20,6 +20,11 @@ namespace {
// A string used to log UMA for query tiles in image fetcher service.
constexpr char kImageFetcherUmaClientName[] = "QueryTiles";
// The time interval for the images to stay in image fetcher's cache after last
// used time.
constexpr base::TimeDelta kImageCacheExpirationInterval =
base::TimeDelta::FromDays(1);
constexpr net::NetworkTrafficAnnotationTag kQueryTilesTrafficAnnotation =
net::DefineNetworkTrafficAnnotation("query_tiles_image_loader", R"(
semantics {
......@@ -63,9 +68,9 @@ CachedImageLoader::~CachedImageLoader() = default;
void CachedImageLoader::FetchImage(const GURL& url, BitmapCallback callback) {
// Fetch and decode the image from network or disk cache.
// TODO(xingliu): Add custom expiration to ImageFetcherParams.
image_fetcher::ImageFetcherParams params(kQueryTilesTrafficAnnotation,
kImageFetcherUmaClientName);
params.set_hold_for_expiration_interval(kImageCacheExpirationInterval);
image_fetcher_->FetchImage(
url, base::BindOnce(&OnImageFetched, std::move(callback)), params);
}
......
......@@ -33,7 +33,7 @@ TileServiceFactory::~TileServiceFactory() {}
std::unique_ptr<KeyedService> TileServiceFactory::BuildServiceInstanceFor(
SimpleFactoryKey* key) const {
// TODO(xingliu): Use network only fetcher if needed.
// TODO(xingliu): Add reduced mode image fetcher for prefetch.
auto* image_fetcher =
ImageFetcherServiceFactory::GetForKey(key)->GetImageFetcher(
image_fetcher::ImageFetcherConfig::kDiskCacheOnly);
......
......@@ -11,6 +11,7 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/optional.h"
#include "base/time/time.h"
#include "components/image_fetcher/core/image_fetcher_types.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "ui/gfx/geometry/size.h"
......@@ -88,6 +89,15 @@ class ImageFetcherParams {
skip_disk_cache_read_ = skip_disk_cache_read;
}
const base::Optional<base::TimeDelta>& expiration_interval() const {
return expiration_interval_;
}
void set_hold_for_expiration_interval(
const base::TimeDelta& expiration_interval) {
expiration_interval_ = expiration_interval;
}
private:
void set_skip_transcoding(bool skip_transcoding) {
skip_transcoding_ = skip_transcoding;
......@@ -100,6 +110,10 @@ class ImageFetcherParams {
const net::NetworkTrafficAnnotationTag network_traffic_annotation_tag_;
base::Optional<int64_t> max_download_bytes_;
// Only used in rare cases to keep the cache file on disk for certain period
// of time. Image files will stay in cache at least for |expiration_interval_|
// after last use.
base::Optional<base::TimeDelta> expiration_interval_;
gfx::Size desired_frame_size_;
std::string uma_client_name_;
// When true, the image fetcher will skip transcoding whenever possible. Only
......
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