#include "components/origin_trials/browser/leveldb_persistence_provider.h"
#include <memory>
#include <utility>
#include <vector>
#include "base/containers/flat_map.h"
#include "base/containers/flat_set.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_util.h"
#include "base/synchronization/lock.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "components/leveldb_proto/public/proto_database_provider.h"
#include "components/leveldb_proto/public/shared_proto_database_client_list.h"
#include "components/origin_trials/common/persisted_trial_token.h"
#include "components/origin_trials/proto/db_trial_token.pb.h"
#include "components/origin_trials/proto/proto_util.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/schemeful_site.h"
#include "third_party/blink/public/common/origin_trials/trial_token_validator.h"
#include "url/origin.h"
namespace origin_trials {
namespace {
bool HasFirstPartyPartition(
const url::Origin token_origin_host,
const google::protobuf::RepeatedPtrField<std::string>& partition_sites) { … }
const base::FilePath::StringPieceType kPersistentTrialTokenDbPath = …);
std::unique_ptr<LevelDbPersistenceProvider::DbLoadResult> BuildMapFromDb(
std::unique_ptr<std::vector<origin_trials_pb::TrialTokenDbEntries>>
entries) { … }
}
LevelDbPersistenceProvider::LevelDbPersistenceProvider(
const base::FilePath& profile_dir,
leveldb_proto::ProtoDatabaseProvider* db_provider)
: … { … }
LevelDbPersistenceProvider::LevelDbPersistenceProvider(
std::unique_ptr<
leveldb_proto::ProtoDatabase<origin_trials_pb::TrialTokenDbEntries>>
database)
: … { … }
std::unique_ptr<LevelDbPersistenceProvider>
LevelDbPersistenceProvider::CreateForTesting(
std::unique_ptr<
leveldb_proto::ProtoDatabase<origin_trials_pb::TrialTokenDbEntries>>
db) { … }
LevelDbPersistenceProvider::~LevelDbPersistenceProvider() = default;
void LevelDbPersistenceProvider::OnDbInitialized(
leveldb_proto::Enums::InitStatus status) { … }
void LevelDbPersistenceProvider::OnDbLoad(
bool success,
std::unique_ptr<std::vector<origin_trials_pb::TrialTokenDbEntries>>
entries) { … }
void LevelDbPersistenceProvider::OnMapBuild(
std::unique_ptr<DbLoadResult> result) { … }
void LevelDbPersistenceProvider::MergeCacheIntoLoadResult(
DbLoadResult& result) { … }
void LevelDbPersistenceProvider::UpdateSiteToOriginsMap(
const url::Origin& origin,
bool insert) { … }
base::flat_set<PersistedTrialToken>
LevelDbPersistenceProvider::GetPersistentTrialTokens(
const url::Origin& origin) { … }
SiteOriginTrialTokens
LevelDbPersistenceProvider::GetPotentialPersistentTrialTokens(
const url::Origin& origin) { … }
void LevelDbPersistenceProvider::SavePersistentTrialTokens(
const url::Origin& origin,
const base::flat_set<PersistedTrialToken>& tokens) { … }
void LevelDbPersistenceProvider::ClearPersistedTokens() { … }
LevelDbPersistenceProvider::DbLoadResult::DbLoadResult(
std::unique_ptr<OriginTrialMap> new_origin_trial_map,
std::unique_ptr<ProtoKeyVector> keys_to_delete,
std::unique_ptr<OriginTrialMap> entries_to_update,
std::unique_ptr<SiteOriginsMap> new_site_origins_map)
: … { … }
LevelDbPersistenceProvider::DbLoadResult::~DbLoadResult() = default;
}