1 // Copyright 2021 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "components/metrics/structured/structured_metrics_client.h" 6 7 #include <utility> 8 9 #include "base/no_destructor.h" 10 #include "components/metrics/structured/event.h" 11 12 namespace metrics::structured { 13 14 StructuredMetricsClient::StructuredMetricsClient() = default; 15 StructuredMetricsClient::~StructuredMetricsClient() = default; 16 17 // static Get()18StructuredMetricsClient* StructuredMetricsClient::Get() { 19 static base::NoDestructor<StructuredMetricsClient> client; 20 return client.get(); 21 } 22 Record(Event && event)23void StructuredMetricsClient::Record(Event&& event) { 24 if (delegate_ && delegate_->IsReadyToRecord()) { 25 delegate_->RecordEvent(std::move(event)); 26 } 27 } 28 SetDelegate(RecordingDelegate * delegate)29void StructuredMetricsClient::SetDelegate(RecordingDelegate* delegate) { 30 delegate_ = delegate; 31 } 32 UnsetDelegate()33void StructuredMetricsClient::UnsetDelegate() { 34 delegate_ = nullptr; 35 } 36 37 } // namespace metrics::structured 38