#include "chrome/updater/cleanup_task.h"
#include <optional>
#include "base/check_op.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/logging.h"
#include "base/memory/scoped_refptr.h"
#include "base/process/launch.h"
#include "base/process/process.h"
#include "base/sequence_checker.h"
#include "base/task/thread_pool.h"
#include "base/time/time.h"
#include "base/version.h"
#include "chrome/updater/app/app_uninstall.h"
#include "chrome/updater/configurator.h"
#include "chrome/updater/updater_version.h"
#include "chrome/updater/util/util.h"
#if BUILDFLAG(IS_WIN)
#include <string>
#include <vector>
#include "base/strings/sys_string_conversions.h"
#include "base/win/registry.h"
#include "chrome/updater/persisted_data.h"
#include "chrome/updater/util/win_util.h"
#include "chrome/updater/win/win_constants.h"
#endif
namespace updater {
namespace {
constexpr int kMilestoneDeletionThreshold = …;
#if BUILDFLAG(IS_WIN)
void RepairAppBrandCode(UpdaterScope scope,
scoped_refptr<PersistedData> persisted_data) {
const HKEY root = UpdaterScopeToHKeyRoot(scope);
struct AppBrand {
std::string app_id;
std::string brand;
};
const std::vector<AppBrand> app_brands = [persisted_data] {
std::vector<AppBrand> app_brands;
for (const std::string& app_id : persisted_data->GetAppIds()) {
const std::string brand = persisted_data->GetBrandCode(app_id);
if (brand.empty()) {
continue;
}
app_brands.emplace_back(app_id, brand);
}
return app_brands;
}();
for (const auto& [app_id, brand] : app_brands) {
const std::wstring brand_prefs = base::SysUTF8ToWide(brand);
if (brand_prefs.empty()) {
continue;
}
base::win::RegKey key;
if (key.Open(root, GetAppClientStateKey(app_id).c_str(),
Wow6432(KEY_READ | KEY_WRITE)) != ERROR_SUCCESS) {
continue;
}
std::wstring brand_registry;
key.ReadValue(kRegValueBrandCode, &brand_registry);
if (!brand_registry.empty()) {
continue;
}
VLOG(1) << __func__ << ": missing " << brand_prefs << " for " << app_id;
const LONG res = key.WriteValue(kRegValueBrandCode, brand_prefs.c_str());
VLOG(1) << __func__ << [&res] {
return res != ERROR_SUCCESS ? ": not repaired " : ": repaired ";
}() << res;
}
}
#endif
void CleanupGoogleUpdate(UpdaterScope scope) { … }
void CleanupOldUpdaterVersions(UpdaterScope scope) { … }
}
CleanupTask::CleanupTask(UpdaterScope scope, scoped_refptr<Configurator> config)
: … { … }
CleanupTask::~CleanupTask() = default;
void CleanupTask::Run(base::OnceClosure callback) { … }
}