chromium/components/ukm/ukm_service.cc

// Copyright 2017 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/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 {

// Generates a new client id and stores it in prefs.
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) {}

// Remove elements satisfying the predicate by moving them to the end of the
// list then truncate.
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) {}

}  // namespace

// static
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_ is false, UKM has not yet been started, so bail. The
  // scheduler will instead be started via EnableReporting().
  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();

  // Give providers a chance to persist ukm data as part of being backgrounded.
  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) {}

// static
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) {}

}  // namespace ukm