Add UMA histograms to track usage of fullscreen detection

Bug: chromium:1348011
Change-Id: I3219e74c49ff77e00b2224c8cf82f78d1e0fd9cf
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/291708
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Johannes Kron <kron@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39254}
diff --git a/modules/desktop_capture/cropping_window_capturer_win.cc b/modules/desktop_capture/cropping_window_capturer_win.cc
index 64d9219..5d99cb6 100644
--- a/modules/desktop_capture/cropping_window_capturer_win.cc
+++ b/modules/desktop_capture/cropping_window_capturer_win.cc
@@ -153,6 +153,9 @@
   bool enumerate_current_process_windows_;
 
   rtc::scoped_refptr<FullScreenWindowDetector> full_screen_window_detector_;
+
+  // Used to make sure that we only log the usage of fullscreen detection once.
+  mutable bool fullscreen_usage_logged_ = false;
 };
 
 void CroppingWindowCapturerWin::CaptureFrame() {
@@ -307,6 +310,10 @@
       full_screen_window_detector_
           ? full_screen_window_detector_->FindFullScreenWindow(selected_source)
           : 0;
+  if (full_screen_source != selected_source && !fullscreen_usage_logged_) {
+    fullscreen_usage_logged_ = true;
+    LogDesktopCapturerFullscreenDetectorUsage();
+  }
   return full_screen_source ? full_screen_source : selected_source;
 }
 
diff --git a/modules/desktop_capture/desktop_capturer.cc b/modules/desktop_capture/desktop_capturer.cc
index dc24b38..c6a8dec 100644
--- a/modules/desktop_capture/desktop_capturer.cc
+++ b/modules/desktop_capture/desktop_capturer.cc
@@ -19,6 +19,7 @@
 #include "modules/desktop_capture/cropping_window_capturer.h"
 #include "modules/desktop_capture/desktop_capture_options.h"
 #include "modules/desktop_capture/desktop_capturer_differ_wrapper.h"
+#include "system_wrappers/include/metrics.h"
 
 #if defined(RTC_ENABLE_WIN_WGC)
 #include "modules/desktop_capture/win/wgc_capturer_win.h"
@@ -27,6 +28,10 @@
 
 namespace webrtc {
 
+void LogDesktopCapturerFullscreenDetectorUsage() {
+  RTC_HISTOGRAM_BOOLEAN("WebRTC.Screenshare.DesktopCapturerUsage", true);
+}
+
 DesktopCapturer::~DesktopCapturer() = default;
 
 DelegatedSourceListController*
diff --git a/modules/desktop_capture/desktop_capturer.h b/modules/desktop_capture/desktop_capturer.h
index 04991f2..fd884f1 100644
--- a/modules/desktop_capture/desktop_capturer.h
+++ b/modules/desktop_capture/desktop_capturer.h
@@ -32,6 +32,8 @@
 
 namespace webrtc {
 
+void RTC_EXPORT LogDesktopCapturerFullscreenDetectorUsage();
+
 class DesktopCaptureOptions;
 class DesktopFrame;
 
diff --git a/modules/desktop_capture/window_capturer_mac.mm b/modules/desktop_capture/window_capturer_mac.mm
index f0b413b..f99b4a7 100644
--- a/modules/desktop_capture/window_capturer_mac.mm
+++ b/modules/desktop_capture/window_capturer_mac.mm
@@ -73,6 +73,9 @@
   const rtc::scoped_refptr<DesktopConfigurationMonitor> configuration_monitor_;
 
   WindowFinderMac window_finder_;
+
+  // Used to make sure that we only log the usage of fullscreen detection once.
+  bool fullscreen_usage_logged_ = false;
 };
 
 WindowCapturerMac::WindowCapturerMac(
@@ -178,7 +181,14 @@
 
     CGWindowID full_screen_window = full_screen_window_detector_->FindFullScreenWindow(window_id_);
 
-    if (full_screen_window != kCGNullWindowID) on_screen_window = full_screen_window;
+    if (full_screen_window != kCGNullWindowID) {
+      // If this is the first time this happens, report to UMA that the feature is active.
+      if (!fullscreen_usage_logged_) {
+        LogDesktopCapturerFullscreenDetectorUsage();
+        fullscreen_usage_logged_ = true;
+      }
+      on_screen_window = full_screen_window;
+    }
   }
 
   std::unique_ptr<DesktopFrame> frame = DesktopFrameCGImage::CreateForWindow(on_screen_window);