#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/ukm/ukm_recorder_impl.h"
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "base/component_export.h"
#include "base/containers/contains.h"
#include "base/containers/span.h"
#include "base/feature_list.h"
#include "base/logging.h"
#include "base/metrics/crc32.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/metrics_hashes.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/time/time.h"
#include "base/trace_event/typed_macros.h"
#include "components/ukm/scheme_constants.h"
#include "components/ukm/ukm_recorder_observer.h"
#include "components/variations/variations_associated_data.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_decode.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_recorder_impl_utils.h"
#include "services/metrics/public/cpp/ukm_source.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "services/metrics/public/mojom/ukm_interface.mojom.h"
#include "third_party/metrics_proto/ukm/entry.pb.h"
#include "third_party/metrics_proto/ukm/report.pb.h"
#include "third_party/metrics_proto/ukm/source.pb.h"
#include "third_party/metrics_proto/ukm/web_features.pb.h"
#include "ukm_consent_state.h"
#include "ukm_recorder_impl.h"
#include "url/gurl.h"
namespace ukm {
BASE_FEATURE(…);
namespace {
bool IsAllowlistedSourceId(SourceId source_id) { … }
bool HasSupportedScheme(const GURL& url) { … }
void RecordDroppedSource(DroppedDataReason reason) { … }
void RecordDroppedSource(bool already_recorded_another_reason,
DroppedDataReason reason) { … }
void StoreEntryProto(const mojom::UkmEntry& in, Entry* out) { … }
void StoreWebDXFeaturesProto(SourceId source_id,
const BitSet& in,
HighLevelWebFeatures* out) { … }
GURL SanitizeURL(const GURL& url) { … }
void AppendAllowlistedUrls(
const std::map<SourceId, std::unique_ptr<UkmSource>>& sources,
std::unordered_set<std::string>* urls) { … }
bool HasComprehensiveDecodeMap(int64_t event_hash) { … }
bool HasUnknownMetrics(const builders::DecodeMap& decode_map,
const mojom::UkmEntry& entry) { … }
std::string WebDXFeaturesToStringForDebug(const std::set<int32_t>& features) { … }
}
UkmRecorderImpl::UkmRecorderImpl()
: … { … }
UkmRecorderImpl::~UkmRecorderImpl() = default;
UkmRecorderImpl::Recordings::Recordings() = default;
UkmRecorderImpl::Recordings& UkmRecorderImpl::Recordings::operator=(
Recordings&&) = default;
UkmRecorderImpl::Recordings::~Recordings() = default;
void UkmRecorderImpl::Recordings::Reset() { … }
void UkmRecorderImpl::Recordings::SourceCounts::Reset() { … }
void UkmRecorderImpl::UpdateRecording(ukm::UkmConsentState state) { … }
void UkmRecorderImpl::EnableRecording() { … }
void UkmRecorderImpl::DisableRecording() { … }
void UkmRecorderImpl::SetSamplingForTesting(int rate) { … }
void UkmRecorderImpl::SetWebDXFeaturesSamplingForTesting(int rate) { … }
bool UkmRecorderImpl::ShouldDropEntryForTesting(mojom::UkmEntry* entry) { … }
bool UkmRecorderImpl::IsSamplingConfigured() const { … }
void UkmRecorderImpl::Purge() { … }
void UkmRecorderImpl::PurgeRecordingsWithUrlScheme(
const std::string& url_scheme) { … }
void UkmRecorderImpl::PurgeRecordingsWithSourceIdType(
ukm::SourceIdType source_id_type) { … }
void UkmRecorderImpl::PurgeRecordingsWithMsbbSources() { … }
void UkmRecorderImpl::PurgeDataBySourceIds(
const std::unordered_set<SourceId>& source_ids) { … }
void UkmRecorderImpl::MarkSourceForDeletion(SourceId source_id) { … }
void UkmRecorderImpl::SetIsWebstoreExtensionCallback(
const IsWebstoreExtensionCallback& callback) { … }
void UkmRecorderImpl::SetEntryFilter(
std::unique_ptr<UkmEntryFilter> entry_filter) { … }
void UkmRecorderImpl::AddUkmRecorderObserver(
const base::flat_set<uint64_t>& event_hashes,
UkmRecorderObserver* observer) { … }
void UkmRecorderImpl::RemoveUkmRecorderObserver(UkmRecorderObserver* observer) { … }
void UkmRecorderImpl::OnUkmAllowedStateChanged(UkmConsentState state) { … }
void UkmRecorderImpl::StoreRecordingsInReport(Report* report) { … }
int UkmRecorderImpl::PruneData(std::set<SourceId>& source_ids_seen) { … }
bool UkmRecorderImpl::ShouldDropEntry(mojom::UkmEntry* entry) { … }
bool UkmRecorderImpl::ApplyEntryFilter(mojom::UkmEntry* entry) { … }
int UkmRecorderImpl::PruneOldSources(size_t max_kept_sources,
const std::set<SourceId>& pruning_set) { … }
void UkmRecorderImpl::UpdateSourceURL(SourceId source_id,
const GURL& unsanitized_url) { … }
void UkmRecorderImpl::UpdateAppURL(SourceId source_id,
const GURL& url,
const AppType app_type) { … }
void UkmRecorderImpl::RecordNavigation(
SourceId source_id,
const UkmSource::NavigationData& unsanitized_navigation_data) { … }
UkmConsentType UkmRecorderImpl::GetConsentType(SourceIdType type) { … }
UkmRecorderImpl::EventAggregate::EventAggregate() = default;
UkmRecorderImpl::EventAggregate::~EventAggregate() = default;
void UkmRecorderImpl::EventAggregate::FillProto(
Aggregate* proto_aggregate) const { … }
void UkmRecorderImpl::MaybeMarkForDeletion(SourceId source_id) { … }
bool UkmRecorderImpl::ShouldDropExtensionUrl(
const GURL& sanitized_extension_url,
bool has_recorded_reason) const { … }
bool UkmRecorderImpl::ShouldRecordUrl(SourceId source_id,
const GURL& sanitized_url) const { … }
void UkmRecorderImpl::RecordSource(std::unique_ptr<UkmSource> source) { … }
void UkmRecorderImpl::AddEntry(mojom::UkmEntryPtr entry) { … }
void UkmRecorderImpl::RecordWebDXFeatures(SourceId source_id,
const std::set<int32_t>& features,
size_t max_feature_value) { … }
void UkmRecorderImpl::LoadExperimentSamplingInfo() { … }
void UkmRecorderImpl::LoadExperimentSamplingParams(
const std::map<std::string, std::string>& params) { … }
bool UkmRecorderImpl::IsSampledIn(int64_t source_id, uint64_t event_id) { … }
bool UkmRecorderImpl::IsSampledIn(int64_t source_id,
uint64_t event_id,
int sampling_rate) { … }
void UkmRecorderImpl::InitDecodeMap() { … }
void UkmRecorderImpl::NotifyObserversWithNewEntry(
const mojom::UkmEntry& entry) { … }
template <typename Method, typename... Params>
void UkmRecorderImpl::NotifyAllObservers(Method m, const Params&... params) { … }
std::set<uint64_t> UkmRecorderImpl::GetObservedEventHashes() { … }
}