#include "components/metrics/structured/structured_metrics_service.h"
#include <memory>
#include "base/functional/callback_forward.h"
#include "base/memory/scoped_refptr.h"
#include "base/run_loop.h"
#include "base/task/bind_post_task.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "components/metrics/metrics_log.h"
#include "components/metrics/metrics_service_client.h"
#include "components/metrics/structured/reporting/structured_metrics_reporting_service.h"
#include "components/metrics/structured/structured_metrics_features.h"
#include "components/metrics/structured/structured_metrics_scheduler.h"
#include "third_party/metrics_proto/system_profile.pb.h"
namespace metrics::structured {
#if BUILDFLAG(IS_CHROMEOS_ASH)
StructuredMetricsService::ServiceIOHelper::ServiceIOHelper(
scoped_refptr<StructuredMetricsRecorder> recorder)
: recorder_(std::move(recorder)) {}
StructuredMetricsService::ServiceIOHelper::~ServiceIOHelper() = default;
ChromeUserMetricsExtension
StructuredMetricsService::ServiceIOHelper::ProvideEvents() {
ChromeUserMetricsExtension uma_proto;
recorder_->ProvideEventMetrics(uma_proto);
return uma_proto;
}
#endif
StructuredMetricsService::StructuredMetricsService(
MetricsServiceClient* client,
PrefService* local_state,
scoped_refptr<StructuredMetricsRecorder> recorder)
: … { … }
StructuredMetricsService::~StructuredMetricsService() { … }
void StructuredMetricsService::EnableRecording() { … }
void StructuredMetricsService::DisableRecording() { … }
void StructuredMetricsService::EnableReporting() { … }
void StructuredMetricsService::DisableReporting() { … }
void StructuredMetricsService::Flush(
metrics::MetricsLogsEventManager::CreateReason reason) { … }
void StructuredMetricsService::Purge() { … }
base::TimeDelta StructuredMetricsService::GetUploadTimeInterval() { … }
void StructuredMetricsService::RotateLogsAndSend() { … }
void StructuredMetricsService::CreateLogs(
metrics::MetricsLogsEventManager::CreateReason reason,
bool notify_scheduler) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
void StructuredMetricsService::BuildAndStoreLog(
metrics::MetricsLogsEventManager::CreateReason reason,
bool notify_scheduler) {
ChromeUserMetricsExtension uma_proto;
InitializeUmaProto(uma_proto);
io_helper_.AsyncCall(&ServiceIOHelper::ProvideEvents)
.Then(base::BindOnce(&StructuredMetricsService::StoreLogAndStartUpload,
weak_factory_.GetWeakPtr(), reason,
notify_scheduler));
}
#endif
void StructuredMetricsService::BuildAndStoreLogSync(
metrics::MetricsLogsEventManager::CreateReason reason,
bool notify_scheduler) { … }
void StructuredMetricsService::StoreLogAndStartUpload(
metrics::MetricsLogsEventManager::CreateReason reason,
bool notify_scheduler,
ChromeUserMetricsExtension uma_proto) { … }
void StructuredMetricsService::Initialize() { … }
void StructuredMetricsService::InitializeUmaProto(
ChromeUserMetricsExtension& uma_proto) { … }
void StructuredMetricsService::RegisterPrefs(PrefRegistrySimple* registry) { … }
void StructuredMetricsService::SetRecorderForTest(
scoped_refptr<StructuredMetricsRecorder> recorder) { … }
MetricsServiceClient* StructuredMetricsService::GetMetricsServiceClient()
const { … }
void StructuredMetricsService::ManualUpload() { … }
void StructuredMetricsService::MaybeStartUpload() { … }
void StructuredMetricsService::SetCreateLogsCallbackInTests(
base::OnceClosure callback) { … }
void StructuredMetricsService::OnFlushed(const FlushedKey& key) { … }
void StructuredMetricsService::OnDeleted(const FlushedKey& key,
DeleteReason reason) { … }
std::string StructuredMetricsService::SerializeLog(
const ChromeUserMetricsExtension& uma_proto) { … }
UnsentLogStore::UnsentLogStoreLimits
StructuredMetricsService::GetLogStoreLimits() { … }
}