#include "components/ukm/ukm_service.h"
#include <memory>
#include <string>
#include <unordered_set>
#include <utility>
#include "base/feature_list.h"
#include "base/functional/bind.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/rand_util.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/metrics/log_decoder.h"
#include "components/metrics/metrics_log.h"
#include "components/metrics/metrics_service_client.h"
#include "components/metrics/ukm_demographic_metrics_provider.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/ukm/scheme_constants.h"
#include "components/ukm/ukm_pref_names.h"
#include "components/ukm/ukm_recorder_impl.h"
#include "components/ukm/ukm_rotation_scheduler.h"
#include "services/metrics/public/cpp/delegating_ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_recorder_client_interface_registry.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "third_party/metrics_proto/ukm/report.pb.h"
#include "third_party/metrics_proto/ukm/web_features.pb.h"
#include "third_party/metrics_proto/user_demographics.pb.h"
namespace ukm {
namespace {
uint64_t GenerateAndStoreClientId(PrefService* pref_service) { … }
uint64_t LoadOrGenerateAndStoreClientId(PrefService* pref_service,
uint64_t external_client_id) { … }
int32_t LoadAndIncrementSessionId(PrefService* pref_service) { … }
metrics::UkmLogSourceType GetLogSourceTypeFromSources(
const google::protobuf::RepeatedPtrField<Source>& sources) { … }
template <typename Predicate, typename ReadElements, typename WriteElements>
void FilterReportElements(Predicate predicate,
const ReadElements& elements,
WriteElements* mutable_elements) { … }
template <typename Predicate>
void PurgeDataFromUnsentLogStore(metrics::UnsentLogStore* ukm_log_store,
Predicate source_purging_condition,
const std::string& current_version) { … }
}
BASE_FEATURE(…);
bool UkmService::LogCanBeParsed(const std::string& serialized_data) { … }
std::string UkmService::SerializeReportProtoToString(Report* report) { … }
UkmService::UkmService(PrefService* pref_service,
metrics::MetricsServiceClient* client,
std::unique_ptr<metrics::UkmDemographicMetricsProvider>
demographics_provider,
uint64_t external_client_id)
: … { … }
UkmService::~UkmService() { … }
void UkmService::Initialize() { … }
void UkmService::EnableReporting() { … }
void UkmService::DisableReporting() { … }
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS)
void UkmService::OnAppEnterForeground() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DVLOG(DebuggingLogLevel::Medium) << "UkmService::OnAppEnterForeground";
reporting_service_.SetIsInForegound(true);
if (!initialize_started_) {
return;
}
scheduler_->Start();
}
void UkmService::OnAppEnterBackground() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DVLOG(DebuggingLogLevel::Medium) << "UkmService::OnAppEnterBackground";
reporting_service_.SetIsInForegound(false);
if (!initialize_started_) {
return;
}
scheduler_->Stop();
metrics_providers_.OnAppEnterBackground();
Flush(metrics::MetricsLogsEventManager::CreateReason::kBackgrounded);
}
#endif
void UkmService::Flush(metrics::MetricsLogsEventManager::CreateReason reason) { … }
void UkmService::Purge() { … }
void UkmService::PurgeExtensionsData() { … }
void UkmService::PurgeAppsData() { … }
void UkmService::PurgeMsbbData() { … }
void UkmService::ResetClientState(ResetReason reason) { … }
void UkmService::OnClonedInstallDetected() { … }
void UkmService::RegisterMetricsProvider(
std::unique_ptr<metrics::MetricsProvider> provider) { … }
void UkmService::RegisterEventFilter(std::unique_ptr<UkmEntryFilter> filter) { … }
void UkmService::RegisterPrefs(PrefRegistrySimple* registry) { … }
void UkmService::OnRecorderParametersChanged() { … }
void UkmService::OnRecorderParametersChangedImpl() { … }
void UkmService::StartInitTask() { … }
void UkmService::FinishedInitTask() { … }
void UkmService::RotateLog() { … }
void UkmService::AddSyncedUserNoiseBirthYearAndGenderToReport(Report* report) { … }
void UkmService::BuildAndStoreLog(
metrics::MetricsLogsEventManager::CreateReason reason) { … }
void UkmService::SetInitializationCompleteCallbackForTesting(
base::OnceClosure callback) { … }
}