Skip to content

Commit

Permalink
Image Fetcher: Add cache config to ImageFetcherParams.
Browse files Browse the repository at this point in the history
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/+/2133210
Reviewed-by: Brandon Wylie <wylieb@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#757126}
  • Loading branch information
Xing Liu authored and Commit Bot committed Apr 7, 2020
1 parent b5ce877 commit cff9eaf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions components/image_fetcher/core/image_fetcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit cff9eaf

Please sign in to comment.