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
|
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/variations/variations_safe_seed_store_local_state.h"
#include "base/version_info/channel.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/variations/pref_names.h"
#include "components/variations/seed_reader_writer.h"
namespace variations {
namespace {
// The name of the seed file that stores the safe seed data.
const base::FilePath::CharType kSafeSeedFilename[] =
FILE_PATH_LITERAL("VariationsSafeSeedV1");
} // namespace
VariationsSafeSeedStoreLocalState::VariationsSafeSeedStoreLocalState(
PrefService* local_state,
const base::FilePath& seed_file_dir,
version_info::Channel channel,
const EntropyProviders* entropy_providers)
: local_state_(local_state),
seed_reader_writer_(std::make_unique<SeedReaderWriter>(
local_state,
seed_file_dir,
kSafeSeedFilename,
kSafeSeedFieldsPrefs,
channel,
entropy_providers)) {}
VariationsSafeSeedStoreLocalState::~VariationsSafeSeedStoreLocalState() =
default;
base::Time VariationsSafeSeedStoreLocalState::GetFetchTime() const {
return seed_reader_writer_->GetSeedData().client_fetch_time;
}
void VariationsSafeSeedStoreLocalState::SetFetchTime(
const base::Time& fetch_time) {
seed_reader_writer_->SetFetchTime(fetch_time);
}
int VariationsSafeSeedStoreLocalState::GetMilestone() const {
return seed_reader_writer_->GetSeedData().milestone;
}
base::Time VariationsSafeSeedStoreLocalState::GetTimeForStudyDateChecks()
const {
return seed_reader_writer_->GetSeedData().seed_date;
}
StoredSeed VariationsSafeSeedStoreLocalState::GetCompressedSeed() const {
return seed_reader_writer_->GetSeedData();
}
StoreSeedResult VariationsSafeSeedStoreLocalState::SetCompressedSeed(
ValidatedSeedInfo seed_info) {
return seed_reader_writer_->StoreValidatedSeedInfo(seed_info);
}
std::string VariationsSafeSeedStoreLocalState::GetLocale() const {
return local_state_->GetString(prefs::kVariationsSafeSeedLocale);
}
void VariationsSafeSeedStoreLocalState::SetLocale(const std::string& locale) {
local_state_->SetString(prefs::kVariationsSafeSeedLocale, locale);
}
std::string VariationsSafeSeedStoreLocalState::GetPermanentConsistencyCountry()
const {
return seed_reader_writer_->GetSeedData().permanent_country_code;
}
std::string VariationsSafeSeedStoreLocalState::GetSessionConsistencyCountry()
const {
return seed_reader_writer_->GetSeedData().session_country_code;
}
SeedReaderWriter*
VariationsSafeSeedStoreLocalState::GetSeedReaderWriterForTesting() {
return seed_reader_writer_.get();
}
void VariationsSafeSeedStoreLocalState::SetSeedReaderWriterForTesting(
std::unique_ptr<SeedReaderWriter> seed_reader_writer) {
seed_reader_writer_ = std::move(seed_reader_writer);
}
void VariationsSafeSeedStoreLocalState::ClearState() {
// Seed and other related information is cleared by the SeedReaderWriter.
seed_reader_writer_->ClearSeedInfo();
seed_reader_writer_->ClearSessionCountry();
seed_reader_writer_->ClearPermanentConsistencyCountryAndVersion();
local_state_->ClearPref(prefs::kVariationsSafeSeedLocale);
}
LoadSeedResult VariationsSafeSeedStoreLocalState::ReadSeedData(
std::string* seed_data,
std::string* base64_seed_signature) {
return seed_reader_writer_->ReadSeedData(seed_data, base64_seed_signature);
}
void VariationsSafeSeedStoreLocalState::ReadSeedData(
SeedReaderWriter::ReadSeedDataCallback done_callback) {
seed_reader_writer_->ReadSeedData(std::move(done_callback));
}
// static
void VariationsSafeSeedStoreLocalState::RegisterPrefs(
PrefRegistrySimple* registry) {
registry->RegisterStringPref(prefs::kVariationsSafeCompressedSeed,
std::string());
registry->RegisterTimePref(prefs::kVariationsSafeSeedDate, base::Time());
registry->RegisterTimePref(prefs::kVariationsSafeSeedFetchTime, base::Time());
registry->RegisterStringPref(prefs::kVariationsSafeSeedLocale, std::string());
registry->RegisterIntegerPref(prefs::kVariationsSafeSeedMilestone, 0);
registry->RegisterStringPref(
prefs::kVariationsSafeSeedPermanentConsistencyCountry, std::string());
registry->RegisterStringPref(
prefs::kVariationsSafeSeedSessionConsistencyCountry, std::string());
registry->RegisterStringPref(prefs::kVariationsSafeSeedSignature,
std::string());
}
} // namespace variations
|