blob: 7febd12b3e37ff541b4d0f87c43396fca149a68f [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 <string>
#include "base/files/file_path.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/image_decoder.h"
// Helper class to generate thumbnail for a given local image file with a given
// max size. Must be invoked on the browser thread.
class ImageThumbnailRequest : public ImageDecoder::ImageRequest {
ImageThumbnailRequest(int icon_size,
base::OnceCallback<void(const SkBitmap&)> callback);
~ImageThumbnailRequest() override;
// Kicks off an asynchronous process to retrieve the thumbnail for the file
// located at |file_path| with a max size of |icon_size_| in each dimension.
// Invokes the |callback_| method when finished.
void Start(const base::FilePath& path);
// ImageDecoder::ImageRequest implementation.
void OnImageDecoded(const SkBitmap& decoded_image) override;
void OnDecodeImageFailed() override;
void OnLoadComplete(const std::string& data);
void FinishRequest(SkBitmap thumbnail);
const int icon_size_;
base::OnceCallback<void(const SkBitmap&)> callback_;
base::WeakPtrFactory<ImageThumbnailRequest> weak_ptr_factory_;