blob: c79c0a308f84fe1db4276e93405a0102f6c9577c [file] [log] [blame]
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ASH_APP_MODE_KIOSK_APP_ICON_LOADER_H_
#define CHROME_BROWSER_ASH_APP_MODE_KIOSK_APP_ICON_LOADER_H_
#include <optional>
#include "base/functional/callback.h"
#include "base/memory/weak_ptr.h"
#include "ui/gfx/image/image_skia.h"
namespace base {
class FilePath;
}
namespace ash {
// Loads locally stored icon data and decodes it.
// New instance should be created for each request.
class KioskAppIconLoader {
public:
using ResultCallback =
base::OnceCallback<void(std::optional<gfx::ImageSkia>)>;
KioskAppIconLoader();
KioskAppIconLoader(const KioskAppIconLoader&) = delete;
KioskAppIconLoader& operator=(const KioskAppIconLoader&) = delete;
~KioskAppIconLoader();
// Starts loading `icon_path` then decoding the icon.
// `callback` is called with nullopt on error.
// `callback` will not be called when `this` is deleted earlier.
void Start(const base::FilePath& icon_path, ResultCallback callback);
private:
void OnImageDecoded(ResultCallback callback,
std::optional<gfx::ImageSkia> result);
bool started_ = false;
base::WeakPtrFactory<KioskAppIconLoader> weak_factory_{this};
};
} // namespace ash
#endif // CHROME_BROWSER_ASH_APP_MODE_KIOSK_APP_ICON_LOADER_H_