diff --git a/cobalt/media_capture/media_devices.cc b/cobalt/media_capture/media_devices.cc index 7a75b18e63d3..3c671f3609f2 100644 --- a/cobalt/media_capture/media_devices.cc +++ b/cobalt/media_capture/media_devices.cc @@ -18,6 +18,7 @@ #include #include +#include "base/metrics/histogram_functions.h" #include "base/threading/thread_task_runner_handle.h" #include "cobalt/base/polymorphic_downcast.h" #include "cobalt/media_capture/media_device_info.h" @@ -66,6 +67,11 @@ std::unique_ptr CreateMicrophone( return mic; } +void LogMicCreationSucceededHistogramItem(bool mic_creation_succeeded) { + base::UmaHistogramBoolean("Cobalt.MediaDevices.MicCreationSucceeded", + mic_creation_succeeded); +} + } // namespace. MediaDevices::MediaDevices(script::EnvironmentSettings* settings, @@ -169,6 +175,9 @@ void MediaDevices::OnMicrophoneError( speech::MicrophoneManager::MicrophoneError error, std::string message) { DLOG(INFO) << "MediaDevices::OnMicrophoneError " << message; + // Log failed mic creation in UMA histogram + LogMicCreationSucceededHistogramItem(false); + // No special error handling logic besides logging the message above, so just // delegate to the OnMicrophoneStopped() functionality. OnMicrophoneStopped(); @@ -195,6 +204,9 @@ void MediaDevices::OnMicrophoneStopped() { } void MediaDevices::OnMicrophoneSuccess() { + // Log successful mic creation in UMA histogram + LogMicCreationSucceededHistogramItem(true); + if (javascript_message_loop_->task_runner() != base::ThreadTaskRunnerHandle::Get()) { javascript_message_loop_->task_runner()->PostTask( diff --git a/tools/metrics/histograms/metadata/cobalt/histograms.xml b/tools/metrics/histograms/metadata/cobalt/histograms.xml index 6c4fd71d4597..171ee7d5f2b4 100644 --- a/tools/metrics/histograms/metadata/cobalt/histograms.xml +++ b/tools/metrics/histograms/metadata/cobalt/histograms.xml @@ -151,6 +151,19 @@ Always run the pretty print utility on this file after editing: + + + + loganmann@google.com + yt-magma-eng@google.com + cobalt-team@google.com + + A boolean representing the success or failure of an attempted mic creation + event via mediaDevices.getUserMedia(). + + +