#include "components/image_fetcher/core/cached_image_fetcher.h"
#include <utility>
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/metrics/histogram_macros.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/time/time.h"
#include "base/timer/elapsed_timer.h"
#include "components/image_fetcher/core/cache/image_cache.h"
#include "components/image_fetcher/core/image_decoder.h"
#include "components/image_fetcher/core/image_fetcher_metrics_reporter.h"
#include "components/image_fetcher/core/request_metadata.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
namespace image_fetcher {
struct CachedImageFetcherRequest { … };
namespace {
void DataCallbackIfPresent(ImageDataFetcherCallback data_callback,
const std::string& image_data,
const image_fetcher::RequestMetadata& metadata) { … }
void ImageCallbackIfPresent(ImageFetcherCallback image_callback,
const gfx::Image& image,
const image_fetcher::RequestMetadata& metadata) { … }
std::string EncodeSkBitmapToPNG(const std::string& uma_client_name,
const SkBitmap& bitmap) { … }
}
CachedImageFetcher::CachedImageFetcher(ImageFetcher* image_fetcher,
scoped_refptr<ImageCache> image_cache,
bool read_only)
: … { … }
CachedImageFetcher::~CachedImageFetcher() = default;
ImageDecoder* CachedImageFetcher::GetImageDecoder() { … }
void CachedImageFetcher::FetchImageAndData(
const GURL& image_url,
ImageDataFetcherCallback image_data_callback,
ImageFetcherCallback image_callback,
ImageFetcherParams params) { … }
void CachedImageFetcher::OnImageFetchedFromCache(
CachedImageFetcherRequest request,
ImageDataFetcherCallback image_data_callback,
ImageFetcherCallback image_callback,
bool cache_result_needs_transcoding,
std::string image_data) { … }
void CachedImageFetcher::OnImageDecodedFromCache(
CachedImageFetcherRequest request,
ImageDataFetcherCallback image_data_callback,
ImageFetcherCallback image_callback,
bool cache_result_needs_transcoding,
const gfx::Image& image) { … }
void CachedImageFetcher::EnqueueFetchImageFromNetwork(
CachedImageFetcherRequest request,
ImageDataFetcherCallback image_data_callback,
ImageFetcherCallback image_callback) { … }
void CachedImageFetcher::FetchImageFromNetwork(
CachedImageFetcherRequest request,
ImageDataFetcherCallback image_data_callback,
ImageFetcherCallback image_callback) { … }
void CachedImageFetcher::OnImageFetchedWithoutTranscoding(
CachedImageFetcherRequest request,
ImageDataFetcherCallback image_data_callback,
const std::string& image_data,
const RequestMetadata& request_metadata) { … }
void CachedImageFetcher::OnImageFetchedForTranscoding(
CachedImageFetcherRequest request,
ImageFetcherCallback image_callback,
const gfx::Image& image,
const RequestMetadata& request_metadata) { … }
void CachedImageFetcher::EncodeAndStoreData(bool cache_result_needs_transcoding,
bool is_image_data_transcoded,
CachedImageFetcherRequest request,
const gfx::Image& image) { … }
void CachedImageFetcher::StoreData(bool cache_result_needs_transcoding,
bool is_image_data_transcoded,
CachedImageFetcherRequest request,
std::string image_data) { … }
}