#ifndef CHROME_BROWSER_ASH_APPS_APK_WEB_APP_INSTALLER_H_
#define CHROME_BROWSER_ASH_APPS_APK_WEB_APP_INSTALLER_H_
#include <memory>
#include <optional>
#include <vector>
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "chromeos/ash/experiences/arc/mojom/app.mojom.h"
#include "components/webapps/common/web_app_id.h"
class GURL;
class Profile;
namespace webapps {
enum class InstallResultCode;
}
namespace ash {
class ApkWebAppInstaller {
public:
using InstallFinishCallback = base::OnceCallback<void(
const webapps::AppId&,
const bool is_web_only_twa,
const std::optional<std::string> sha256_fingerprint,
webapps::InstallResultCode)>;
class Owner {};
ApkWebAppInstaller(const ApkWebAppInstaller&) = delete;
ApkWebAppInstaller& operator=(const ApkWebAppInstaller&) = delete;
static void Install(Profile* profile,
const std::string& package_name,
arc::mojom::WebAppInfoPtr web_app_info,
arc::mojom::RawIconPngDataPtr icon,
InstallFinishCallback callback,
base::WeakPtr<Owner> weak_owner);
protected:
ApkWebAppInstaller(Profile* profile,
InstallFinishCallback callback,
base::WeakPtr<Owner> weak_owner);
virtual ~ApkWebAppInstaller();
void Start(const std::string& package_name,
arc::mojom::WebAppInfoPtr web_app_info,
arc::mojom::RawIconPngDataPtr icon);
virtual void CompleteInstallation(const webapps::AppId& id,
webapps::InstallResultCode code);
void OnWebAppCreated(const GURL& start_url,
const webapps::AppId& app_id,
webapps::InstallResultCode code);
void OnImageDecoded(const SkBitmap& decoded_image);
virtual void DoInstall();
bool has_web_app_install_info() const {
return web_app_install_info_ != nullptr;
}
const web_app::WebAppInstallInfo& web_app_install_info() const {
return *web_app_install_info_;
}
private:
raw_ptr<Profile, DanglingUntriaged> profile_;
bool is_web_only_twa_;
std::optional<std::string> sha256_fingerprint_;
InstallFinishCallback callback_;
base::WeakPtr<Owner> weak_owner_;
std::unique_ptr<web_app::WebAppInstallInfo> web_app_install_info_;
};
}
#endif