From 79e149dad45cd18b763d0662d29cbaffaab47a0f Mon Sep 17 00:00:00 2001 From: Garo Bournoutian <128516918+gbournou@users.noreply.github.com> Date: Mon, 26 Jun 2023 08:09:06 -0700 Subject: [PATCH] Fix undefined argument evaluation order bug. (#705) b/288627621 --- .../cobalt_metrics_services_manager_client.cc | 14 ++++++++++---- .../cobalt_metrics_services_manager_client.h | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) 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.