diff --git a/cobalt/browser/metrics/cobalt_metrics_services_manager_client.cc b/cobalt/browser/metrics/cobalt_metrics_services_manager_client.cc index 27e6f26e37f7..224490ceb2aa 100644 --- a/cobalt/browser/metrics/cobalt_metrics_services_manager_client.cc +++ b/cobalt/browser/metrics/cobalt_metrics_services_manager_client.cc @@ -35,8 +35,9 @@ namespace metrics { std::unique_ptr<::metrics::MetricsServiceClient> CobaltMetricsServicesManagerClient::CreateMetricsServiceClient() { - return std::make_unique(GetMetricsStateManager(), - local_state_.get()); + InitializeMetricsStateManagerAndLocalState(); + return std::make_unique( + metrics_state_manager_.get(), local_state_.get()); } std::unique_ptr @@ -79,8 +80,8 @@ CobaltMetricsServicesManagerClient::GetMetricsStateManagerForTesting() { return GetMetricsStateManager(); } -::metrics::MetricsStateManager* -CobaltMetricsServicesManagerClient::GetMetricsStateManager() { +void CobaltMetricsServicesManagerClient:: + InitializeMetricsStateManagerAndLocalState() { if (!metrics_state_manager_) { PrefServiceFactory pref_service_factory; pref_service_factory.set_user_prefs( @@ -98,6 +99,11 @@ CobaltMetricsServicesManagerClient::GetMetricsStateManager() { base::BindRepeating(&StoreMetricsClientInfo), base::BindRepeating(&LoadMetricsClientInfo)); } +} + +::metrics::MetricsStateManager* +CobaltMetricsServicesManagerClient::GetMetricsStateManager() { + InitializeMetricsStateManagerAndLocalState(); return metrics_state_manager_.get(); } diff --git a/cobalt/browser/metrics/cobalt_metrics_services_manager_client.h b/cobalt/browser/metrics/cobalt_metrics_services_manager_client.h index b421fb6cd8cd..01a2ae73fc15 100644 --- a/cobalt/browser/metrics/cobalt_metrics_services_manager_client.h +++ b/cobalt/browser/metrics/cobalt_metrics_services_manager_client.h @@ -75,6 +75,8 @@ class CobaltMetricsServicesManagerClient ::metrics::MetricsStateManager* GetMetricsStateManagerForTesting(); private: + void InitializeMetricsStateManagerAndLocalState(); + ::metrics::MetricsStateManager* GetMetricsStateManager(); // MetricsStateManager which is passed as a parameter to service constructors.