#ifndef CHROME_UPDATER_APP_APP_INSTALL_H_
#define CHROME_UPDATER_APP_APP_INSTALL_H_
#include <memory>
#include <string>
#include "base/functional/callback_forward.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "base/sequence_checker.h"
#include "chrome/updater/app/app.h"
#include "chrome/updater/lock.h"
namespace base {
class Version;
}
namespace updater {
class ExternalConstants;
class UpdateService;
class AppInstallController
: public base::RefCountedThreadSafe<AppInstallController> {
public:
using Maker = base::RepeatingCallback<scoped_refptr<AppInstallController>()>;
virtual void Initialize() = 0;
virtual void InstallApp(const std::string& app_id,
const std::string& app_name,
base::OnceCallback<void(int)> callback) = 0;
virtual void InstallAppOffline(const std::string& app_id,
const std::string& app_name,
base::OnceCallback<void(int)> callback) = 0;
virtual void Exit(int exit_code) = 0;
virtual void set_update_service(
scoped_refptr<UpdateService> update_service) = 0;
protected:
virtual ~AppInstallController() = default;
private:
friend class base::RefCountedThreadSafe<AppInstallController>;
};
class AppInstall : public App {
public:
explicit AppInstall(AppInstallController::Maker app_install_controller_maker);
private:
~AppInstall() override;
void SendPing(int exit_code, base::OnceClosure callback);
void PingAndShutdown(int exit_code);
void ShutdownNow(int exit_code);
[[nodiscard]] int Initialize() override;
void FirstTaskRun() override;
void CreateUpdateServiceProxy();
void GetVersionDone(const base::Version& version);
void InstallCandidateDone(bool valid_version, int result);
void WakeCandidate();
void RegisterUpdater();
void MaybeInstallApp();
SEQUENCE_CHECKER(sequence_checker_);
std::unique_ptr<ScopedLock> setup_lock_;
std::string app_id_;
std::string app_name_;
AppInstallController::Maker app_install_controller_maker_;
scoped_refptr<AppInstallController> app_install_controller_;
scoped_refptr<ExternalConstants> external_constants_;
scoped_refptr<UpdateService> update_service_;
};
scoped_refptr<App> MakeAppInstall(bool is_silent_install);
}
#endif