blob: 5166dad7dfeb5755cc2c61ce74e6381f22420a7c [file] [log] [blame]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <map>
#include <memory>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/android/explore_sites/explore_sites_types.h"
#include "services/service_manager/public/cpp/connector.h"
#include "third_party/skia/include/core/SkBitmap.h"
namespace explore_sites {
enum class ImageJobType { kSiteIcon, kCategoryImage };
// A helper for converting webp images to bitmaps for the frontend.
// The ComposeSiteImage() and ComposeCategoryImage() functions are used for
// gettting the icons for the ESP and the NTP, respectively.
class ImageHelper {
virtual ~ImageHelper();
// Compose a single site icon and return via |callback|.
void ComposeSiteImage(
BitmapCallback callback,
EncodedImageList images,
std::unique_ptr<service_manager::Connector> connector = nullptr);
// Compose a category icon containing [1 - 4] site icons and return via
// |callback|.
void ComposeCategoryImage(
BitmapCallback callback,
int pixel_size,
EncodedImageList images,
std::unique_ptr<service_manager::Connector> connector = nullptr);
class Job;
void NewJob(ImageJobType job_type,
ImageJobFinishedCallback job_finished_callback,
BitmapCallback bitmap_callback,
EncodedImageList images,
int pixel_size,
std::unique_ptr<service_manager::Connector> connector);
void OnJobFinished(int job_id);
std::map<int, std::unique_ptr<Job>> id_to_job_;
int last_used_job_id_;
base::WeakPtrFactory<ImageHelper> weak_factory_;
} // namespace explore_sites