1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
// Copyright 2019 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_UPDATER_INSTALLER_H_
#define CHROME_UPDATER_INSTALLER_H_
#include <memory>
#include <optional>
#include <string>
#include "base/files/file_path.h"
#include "base/functional/callback_forward.h"
#include "base/memory/scoped_refptr.h"
#include "base/sequence_checker.h"
#include "base/version.h"
#include "build/build_config.h"
#include "chrome/updater/persisted_data.h"
#include "chrome/updater/update_service.h"
#include "chrome/updater/updater_scope.h"
#include "components/crx_file/crx_verifier.h"
#include "components/update_client/update_client.h"
namespace base {
class TimeDelta;
}
namespace updater {
struct AppInfo {
AppInfo(const UpdaterScope scope,
const std::string& app_id,
const std::string& ap,
const std::string& lang,
const std::string& brand,
const base::Version& app_version,
const base::FilePath& ecp);
AppInfo(const AppInfo&);
AppInfo& operator=(const AppInfo&);
~AppInfo();
UpdaterScope scope;
std::string app_id;
std::string ap;
std::string lang;
std::string brand;
base::Version version;
base::FilePath ecp;
};
using InstallProgressCallback = ::update_client::CrxInstaller::ProgressCallback;
using InstallerResult = ::update_client::CrxInstaller::Result;
// Runs an app installer.
// The file `server_install_data` contains additional application-specific
// install configuration parameters extracted either from the update response or
// the app manifest.
InstallerResult RunApplicationInstaller(
const AppInfo& app_info,
const base::FilePath& installer_path,
const std::string& install_args,
std::optional<base::FilePath> server_install_data,
bool usage_stats_enabled,
base::TimeDelta timeout,
InstallProgressCallback progress_callback);
// Retrieves the value of `keyname` from `path` (a plist, on macOS). If the
// file does not exist, or the key does not exist, or the key or path are
// empty, or the platform does not support this functionality (Windows, Linux),
// `default_value` is returned.
std::string LookupString(const base::FilePath& path,
const std::string& keyname,
const std::string& default_value);
// Retrieves the installed version of the provided `app_id`. If `app_id` is not
// installed, the `default_value` is returned. `version_path` and `version_key`
// are not used on Windows.
base::Version LookupVersion(UpdaterScope scope,
const std::string& app_id,
const base::FilePath& version_path,
const std::string& version_key,
const base::Version& default_value);
// Manages the install of one application. Some of the functions of this
// class are blocking and can't be invoked on the main sequence.
//
// If the application installer completes with success, then the following
// post conditions are true: |update_client| updates persisted data in prefs,
// the CRX is installed in a versioned directory in apps/app_id/version,
// the application is considered to be registered for updates, and the
// application installed version matches the version recorded in prefs.
//
// If installing the CRX fails, or the installer fails, then prefs is not
// going to be updated. There will be some files left on the file system, which
// are going to be cleaned up next time the installer runs.
//
// Install directories not matching the |pv| version are lazy-deleted.
class Installer final : public update_client::CrxInstaller {
public:
Installer(const std::string& app_id,
const std::string& client_install_data,
const std::string& install_data_index,
const std::string& install_source,
const std::string& target_channel,
const std::string& target_version_prefix,
bool rollback_allowed,
std::optional<int> major_version_rollout_policy,
std::optional<int> minor_version_rollout_policy,
bool update_disabled,
UpdateService::PolicySameVersionUpdate policy_same_version_update,
scoped_refptr<PersistedData> persisted_data,
crx_file::VerifierFormat crx_verifier_format);
Installer(const Installer&) = delete;
Installer& operator=(const Installer&) = delete;
std::string app_id() const { return app_id_; }
// Returns a CrxComponent instance that describes the current install
// state of the app. Updates the values of |pv_| and the |fingerprint_| with
// the persisted values in prefs.
//
// Callers should only invoke this function when handling a CrxDataCallback
// callback from update_client::Install or from update_client::Update. This
// ensure that prefs has been updated with the most recent values, including
// |pv| and |fingerprint|.
void MakeCrxComponent(
base::OnceCallback<void(update_client::CrxComponent)> callback);
private:
~Installer() override;
// Overrides from update_client::CrxInstaller.
void OnUpdateError(int error) override;
void Install(const base::FilePath& unpack_path,
const std::string& public_key,
std::unique_ptr<InstallParams> install_params,
ProgressCallback progress_callback,
Callback callback) override;
std::optional<base::FilePath> GetInstalledFile(
const std::string& file) override;
bool Uninstall() override;
Result InstallHelper(const base::FilePath& unpack_path,
std::unique_ptr<InstallParams> install_params,
ProgressCallback progress_callback);
// Runs the installer code with sync primitives to allow the code to
// create processes and wait for them to exit.
void InstallWithSyncPrimitives(const base::FilePath& unpack_path,
std::unique_ptr<InstallParams> install_params,
ProgressCallback progress_callback,
Callback callback);
void MakeCrxComponentFromAppInfo(
base::OnceCallback<void(update_client::CrxComponent)> callback,
const AppInfo& app_info);
SEQUENCE_CHECKER(sequence_checker_);
UpdaterScope updater_scope_;
const std::string app_id_;
const std::string client_install_data_;
const std::string install_data_index_;
const std::string install_source_;
const bool rollback_allowed_;
const std::optional<int> major_version_rollout_policy_;
const std::optional<int> minor_version_rollout_policy_;
const std::string target_channel_;
const std::string target_version_prefix_;
const bool update_disabled_;
const UpdateService::PolicySameVersionUpdate policy_same_version_update_;
scoped_refptr<PersistedData> persisted_data_;
const crx_file::VerifierFormat crx_verifier_format_;
// AppInfo is set only after MakeCrxComponent is called, and is not updated
// when the installer succeeds.
AppInfo app_info_;
};
} // namespace updater
#endif // CHROME_UPDATER_INSTALLER_H_
|