#ifndef CHROME_BROWSER_COMPONENT_UPDATER_RECOVERY_IMPROVED_COMPONENT_INSTALLER_H_
#define CHROME_BROWSER_COMPONENT_UPDATER_RECOVERY_IMPROVED_COMPONENT_INSTALLER_H_
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
#include "base/files/file_path.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/sequence_checker.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/task_traits.h"
#include "base/types/expected.h"
#include "base/values.h"
#include "components/component_updater/component_installer.h"
#include "components/crx_file/crx_verifier.h"
#include "components/update_client/unpacker.h"
#include "components/update_client/update_client.h"
namespace base {
class CommandLine;
class Process;
}
class PrefService;
namespace component_updater {
class RecoveryComponentActionHandler : public update_client::ActionHandler {
public:
static scoped_refptr<update_client::ActionHandler> MakeActionHandler();
RecoveryComponentActionHandler(const RecoveryComponentActionHandler&) =
delete;
RecoveryComponentActionHandler& operator=(
const RecoveryComponentActionHandler&) = delete;
void Handle(const base::FilePath& action,
const std::string& session_id,
Callback callback) override;
protected:
static constexpr base::TaskTraits kThreadPoolTaskTraits = {
base::MayBlock(), base::TaskPriority::BEST_EFFORT,
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN};
static constexpr base::TaskTraits kThreadPoolTaskTraitsRunCommand = {
base::MayBlock(), base::WithBaseSyncPrimitives(),
base::TaskPriority::BEST_EFFORT,
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN};
RecoveryComponentActionHandler(
const std::vector<uint8_t>& key_hash = {std::begin(kKeyHash),
std::end(kKeyHash)},
crx_file::VerifierFormat verifier_format =
crx_file::VerifierFormat::CRX3_WITH_PUBLISHER_PROOF);
~RecoveryComponentActionHandler() override;
base::FilePath crx_path() const { return crx_path_; }
std::string session_id() const { return session_id_; }
scoped_refptr<base::SequencedTaskRunner> main_task_runner() {
return main_task_runner_;
}
private:
static constexpr uint8_t kKeyHash[] = {
0x5f, 0x94, 0xe0, 0x3c, 0x64, 0x30, 0x9f, 0xbc, 0xfe, 0x00, 0x9a,
0x27, 0x3e, 0x52, 0xbf, 0xa5, 0x84, 0xb9, 0xb3, 0x75, 0x07, 0x29,
0xde, 0xfa, 0x32, 0x76, 0xd9, 0x93, 0xb5, 0xa3, 0xce, 0x02};
virtual base::CommandLine MakeCommandLine(
const base::FilePath& unpack_path) const = 0;
virtual void PrepareFiles(const base::FilePath& unpack_path) const = 0;
virtual void Elevate(Callback callback) = 0;
void Unpack();
void UnpackComplete(const update_client::Unpacker::Result& result);
void RunCommand(const base::CommandLine& cmdline);
void WaitForCommand(base::expected<base::Process, int> process_or_error);
SEQUENCE_CHECKER(sequence_checker_);
scoped_refptr<base::SequencedTaskRunner> main_task_runner_ =
base::SequencedTaskRunner::GetCurrentDefault();
const std::vector<uint8_t> key_hash_;
const crx_file::VerifierFormat verifier_format_;
base::FilePath crx_path_;
std::string session_id_;
Callback callback_;
base::FilePath unpack_path_;
};
class ComponentUpdateService;
class RecoveryImprovedInstallerPolicy : public ComponentInstallerPolicy {
public:
explicit RecoveryImprovedInstallerPolicy(PrefService* prefs)
: prefs_(prefs) {}
RecoveryImprovedInstallerPolicy(const RecoveryImprovedInstallerPolicy&) =
delete;
RecoveryImprovedInstallerPolicy& operator=(
const RecoveryImprovedInstallerPolicy&) = delete;
private:
friend class RecoveryImprovedInstallerTest;
bool SupportsGroupPolicyEnabledComponentUpdates() const override;
bool RequiresNetworkEncryption() const override;
update_client::CrxInstaller::Result OnCustomInstall(
const base::Value::Dict& manifest,
const base::FilePath& install_dir) override;
void OnCustomUninstall() override;
bool VerifyInstallation(const base::Value::Dict& manifest,
const base::FilePath& install_dir) const override;
void ComponentReady(const base::Version& version,
const base::FilePath& install_dir,
base::Value::Dict manifest) override;
base::FilePath GetRelativeInstallDir() const override;
void GetHash(std::vector<uint8_t>* hash) const override;
std::string GetName() const override;
update_client::InstallerAttributes GetInstallerAttributes() const override;
raw_ptr<PrefService> prefs_;
};
void RegisterRecoveryImprovedComponent(ComponentUpdateService* cus,
PrefService* prefs);
}
#endif