#include "components/segmentation_platform/internal/database/signal_database_impl.h"
#include <cstdint>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/check_op.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback_forward.h"
#include "base/memory/weak_ptr.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/clock.h"
#include "base/time/time.h"
#include "base/trace_event/typed_macros.h"
#include "components/leveldb_proto/public/proto_database.h"
#include "components/segmentation_platform/internal/database/signal_database.h"
#include "components/segmentation_platform/internal/database/signal_key.h"
#include "components/segmentation_platform/internal/metadata/metadata_utils.h"
#include "components/segmentation_platform/internal/proto/signal.pb.h"
#include "components/segmentation_platform/internal/stats.h"
#include "components/segmentation_platform/public/features.h"
namespace segmentation_platform {
namespace {
BASE_FEATURE(…);
bool FilterKeyBasedOnRange(proto::SignalType signal_type,
uint64_t name_hash,
base::Time end_time,
base::Time start_time,
const std::string& signal_key) { … }
leveldb_proto::Enums::KeyIteratorAction GetSamplesIteratorController(
const SignalKey& start_key,
base::Time end_time,
const std::string& key_bytes) { … }
}
SignalDatabaseImpl::SignalDatabaseImpl(
std::unique_ptr<SignalProtoDb> database,
base::Clock* clock,
scoped_refptr<base::SequencedTaskRunner> task_runner)
: … { … }
SignalDatabaseImpl::~SignalDatabaseImpl() = default;
void SignalDatabaseImpl::Initialize(SuccessCallback callback) { … }
void SignalDatabaseImpl::WriteSample(proto::SignalType signal_type,
uint64_t name_hash,
std::optional<int32_t> value,
SuccessCallback callback) { … }
void SignalDatabaseImpl::GetSamples(proto::SignalType signal_type,
uint64_t name_hash,
base::Time start_time,
base::Time end_time,
EntriesCallback callback) { … }
VisitSample;
void IterateOverAllSamples(
base::Time start_time,
base::Time end_time,
bool success,
std::unique_ptr<std::map<std::string, proto::SignalData>> entries,
scoped_refptr<base::SequencedTaskRunner> task_runner,
VisitSample visit_sample) { … }
void SignalDatabaseImpl::OnGetSamples(
EntriesCallback callback,
base::Time start_time,
base::Time end_time,
bool success,
std::unique_ptr<std::map<std::string, proto::SignalData>> entries) { … }
const std::vector<SignalDatabase::DbEntry>*
SignalDatabaseImpl::GetAllSamples() { … }
void SignalDatabaseImpl::OnGetAllSamples(
SuccessCallback callback,
bool success,
std::unique_ptr<std::map<std::string, proto::SignalData>> entries) { … }
void SignalDatabaseImpl::DeleteSamples(proto::SignalType signal_type,
uint64_t name_hash,
base::Time end_time,
SuccessCallback callback) { … }
void SignalDatabaseImpl::OnGetSamplesForDeletion(
SuccessCallback callback,
bool success,
std::unique_ptr<std::map<std::string, proto::SignalData>> entries) { … }
void SignalDatabaseImpl::CompactSamplesForDay(proto::SignalType signal_type,
uint64_t name_hash,
base::Time day_end_time,
SuccessCallback callback) { … }
void SignalDatabaseImpl::OnGetSamplesForCompaction(
SuccessCallback callback,
std::string compact_key,
bool success,
std::unique_ptr<std::map<std::string, proto::SignalData>> entries) { … }
void SignalDatabaseImpl::OnDatabaseInitialized(
SuccessCallback callback,
leveldb_proto::Enums::InitStatus status) { … }
void SignalDatabaseImpl::CleanupStaleCachedEntries(
base::Time current_timestamp) { … }
}