#include "chrome/updater/persisted_data.h"
#include <optional>
#include <string>
#include <vector>
#include "base/base64.h"
#include "base/check.h"
#include "base/check_op.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/sequence_checker.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/values.h"
#include "base/version.h"
#include "build/build_config.h"
#include "chrome/updater/registration_data.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/update_client/activity_data_service.h"
#include "components/update_client/persisted_data.h"
#include "components/update_client/update_client_errors.h"
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#include "base/win/registry.h"
#include "chrome/updater/util/win_util.h"
#include "chrome/updater/win/win_constants.h"
#endif
namespace {
constexpr char kVersionPath[] = …;
constexpr char kVersionKey[] = …;
constexpr char kECP[] = …;
constexpr char kBC[] = …;
constexpr char kBP[] = …;
constexpr char kAP[] = …;
constexpr char kAPPath[] = …;
constexpr char kAPKey[] = …;
constexpr char kHadApps[] = …;
constexpr char kUsageStatsEnabledKey[] = …;
constexpr char kEulaRequired[] = …;
constexpr char kLastChecked[] = …;
constexpr char kLastStarted[] = …;
constexpr char kLastOSVersion[] = …;
}
namespace updater {
PersistedData::PersistedData(
UpdaterScope scope,
PrefService* pref_service,
std::unique_ptr<update_client::ActivityDataService> activity_service)
: … { … }
PersistedData::~PersistedData() { … }
base::Version PersistedData::GetProductVersion(const std::string& id) const { … }
void PersistedData::SetProductVersion(const std::string& id,
const base::Version& pv) { … }
base::Version PersistedData::GetMaxPreviousProductVersion(
const std::string& id) const { … }
void PersistedData::SetMaxPreviousProductVersion(
const std::string& id,
const base::Version& max_version) { … }
base::FilePath PersistedData::GetProductVersionPath(
const std::string& id) const { … }
void PersistedData::SetProductVersionPath(const std::string& id,
const base::FilePath& path) { … }
std::string PersistedData::GetProductVersionKey(const std::string& id) const { … }
void PersistedData::SetProductVersionKey(const std::string& id,
const std::string& key) { … }
std::string PersistedData::GetFingerprint(const std::string& id) const { … }
void PersistedData::SetFingerprint(const std::string& id,
const std::string& fingerprint) { … }
base::FilePath PersistedData::GetExistenceCheckerPath(
const std::string& id) const { … }
void PersistedData::SetExistenceCheckerPath(const std::string& id,
const base::FilePath& ecp) { … }
std::string PersistedData::GetBrandCode(const std::string& id) { … }
void PersistedData::SetBrandCode(const std::string& id, const std::string& bc) { … }
base::FilePath PersistedData::GetBrandPath(const std::string& id) const { … }
void PersistedData::SetBrandPath(const std::string& id,
const base::FilePath& bp) { … }
std::string PersistedData::GetAP(const std::string& id) { … }
void PersistedData::SetAP(const std::string& id, const std::string& ap) { … }
base::FilePath PersistedData::GetAPPath(const std::string& id) const { … }
void PersistedData::SetAPPath(const std::string& id,
const base::FilePath& path) { … }
std::string PersistedData::GetAPKey(const std::string& id) const { … }
void PersistedData::SetAPKey(const std::string& id, const std::string& key) { … }
int PersistedData::GetDateLastActive(const std::string& id) const { … }
int PersistedData::GetDaysSinceLastActive(const std::string& id) const { … }
void PersistedData::SetDateLastActive(const std::string& id, int dla) { … }
int PersistedData::GetDateLastRollCall(const std::string& id) const { … }
int PersistedData::GetDaysSinceLastRollCall(const std::string& id) const { … }
void PersistedData::SetDateLastRollCall(const std::string& id, int dlrc) { … }
std::string PersistedData::GetCohort(const std::string& id) const { … }
void PersistedData::SetCohort(const std::string& id,
const std::string& cohort) { … }
std::string PersistedData::GetCohortName(const std::string& id) const { … }
void PersistedData::SetCohortName(const std::string& id,
const std::string& cohort_name) { … }
std::string PersistedData::GetCohortHint(const std::string& id) const { … }
void PersistedData::SetCohortHint(const std::string& id,
const std::string& cohort_hint) { … }
std::string PersistedData::GetPingFreshness(const std::string& id) const { … }
void PersistedData::SetDateLastData(const std::vector<std::string>& ids,
int datenum,
base::OnceClosure callback) { … }
int PersistedData::GetInstallDate(const std::string& id) const { … }
void PersistedData::SetInstallDate(const std::string& id, int install_date) { … }
void PersistedData::GetActiveBits(
const std::vector<std::string>& ids,
base::OnceCallback<void(const std::set<std::string>&)> callback) const { … }
base::Time PersistedData::GetThrottleUpdatesUntil() const { … }
void PersistedData::SetLastUpdateCheckError(
const update_client::CategorizedError& error) { … }
void PersistedData::SetThrottleUpdatesUntil(const base::Time& time) { … }
void PersistedData::RegisterApp(const RegistrationRequest& rq) { … }
bool PersistedData::RemoveApp(const std::string& id) { … }
std::vector<std::string> PersistedData::GetAppIds() const { … }
const base::Value::Dict* PersistedData::GetAppKey(const std::string& id) const { … }
std::string PersistedData::GetString(const std::string& id,
const std::string& key) const { … }
base::Value::Dict* PersistedData::GetOrCreateAppKey(const std::string& id,
base::Value::Dict& root) { … }
std::optional<int> PersistedData::GetInteger(const std::string& id,
const std::string& key) const { … }
void PersistedData::SetInteger(const std::string& id,
const std::string& key,
int value) { … }
void PersistedData::SetString(const std::string& id,
const std::string& key,
const std::string& value) { … }
bool PersistedData::GetHadApps() const { … }
void PersistedData::SetHadApps() { … }
bool PersistedData::GetUsageStatsEnabled() const { … }
void PersistedData::SetUsageStatsEnabled(bool usage_stats_enabled) { … }
bool PersistedData::GetEulaRequired() const { … }
void PersistedData::SetEulaRequired(bool eula_required) { … }
base::Time PersistedData::GetLastChecked() const { … }
void PersistedData::SetLastChecked(const base::Time& time) { … }
base::Time PersistedData::GetLastStarted() const { … }
void PersistedData::SetLastStarted(const base::Time& time) { … }
#if BUILDFLAG(IS_WIN)
std::optional<OSVERSIONINFOEX> PersistedData::GetLastOSVersion() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const std::string encoded_os_version =
pref_service_->GetString(kLastOSVersion);
if (encoded_os_version.empty()) {
return std::nullopt;
}
const std::optional<std::vector<uint8_t>> decoded_os_version =
base::Base64Decode(encoded_os_version);
if (!decoded_os_version ||
decoded_os_version->size() != sizeof(OSVERSIONINFOEX)) {
return std::nullopt;
}
return *reinterpret_cast<const OSVERSIONINFOEX*>(decoded_os_version->data());
}
void PersistedData::SetLastOSVersion() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!pref_service_) {
return;
}
std::optional<OSVERSIONINFOEX> os_version = GetOSVersion();
if (!os_version) {
return;
}
std::string encoded_os_version =
base::Base64Encode(base::byte_span_from_ref(os_version.value()));
return pref_service_->SetString(kLastOSVersion, encoded_os_version);
}
#endif
void RegisterPersistedDataPrefs(scoped_refptr<PrefRegistrySimple> registry) { … }
}