Use injected clock in Fuchsia Capturer

Bug: webrtc:42223992
Tested: Compiled Chromium for Fuschia
Change-Id: Iec12779f1188965dacfcf9ee212c785f6a6a6964
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/465662
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Auto-Submit: Evan Shrubsole <eshr@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#47534}
diff --git a/modules/desktop_capture/screen_capturer_fuchsia.cc b/modules/desktop_capture/screen_capturer_fuchsia.cc
index 9555109..3d89121 100644
--- a/modules/desktop_capture/screen_capturer_fuchsia.cc
+++ b/modules/desktop_capture/screen_capturer_fuchsia.cc
@@ -21,6 +21,8 @@
 #include <string>
 #include <utility>
 
+#include "api/units/time_delta.h"
+#include "api/units/timestamp.h"
 #include "modules/desktop_capture/blank_detector_desktop_capturer_wrapper.h"
 #include "modules/desktop_capture/desktop_capture_options.h"
 #include "modules/desktop_capture/desktop_capture_types.h"
@@ -31,7 +33,6 @@
 #include "rtc_base/checks.h"
 #include "rtc_base/logging.h"
 #include "rtc_base/numerics/divide_round.h"
-#include "rtc_base/time_utils.h"
 
 namespace webrtc {
 
@@ -58,12 +59,15 @@
     const DesktopCaptureOptions& options) {
   RTC_LOG(LS_INFO) << "DesktopCapturer::CreateRawScreenCapturer creates "
                       "DesktopCapturer of type ScreenCapturerFuchsia";
-  std::unique_ptr<ScreenCapturerFuchsia> capturer(new ScreenCapturerFuchsia());
+  std::unique_ptr<ScreenCapturerFuchsia> capturer(
+      new ScreenCapturerFuchsia(options));
   return capturer;
 }
 
-ScreenCapturerFuchsia::ScreenCapturerFuchsia()
-    : component_context_(sys::ComponentContext::Create()) {}
+ScreenCapturerFuchsia::ScreenCapturerFuchsia(
+    const DesktopCaptureOptions& options)
+    : component_context_(sys::ComponentContext::Create()),
+      clock_(options.clock()) {}
 
 ScreenCapturerFuchsia::~ScreenCapturerFuchsia() {
   // unmap virtual memory mapped pointers
@@ -95,7 +99,7 @@
     return;
   }
 
-  int64_t capture_start_time_nanos = TimeNanos();
+  Timestamp capture_start_time = clock_.CurrentTime();
 
   zx::event event;
   zx::event dup;
@@ -150,8 +154,7 @@
                       << release_result.err();
   }
 
-  int capture_time_ms =
-      (TimeNanos() - capture_start_time_nanos) / kNumNanosecsPerMillisec;
+  int capture_time_ms = (clock_.CurrentTime() - capture_start_time).ms();
   frame->set_capture_time_ms(capture_time_ms);
   callback_->OnCaptureResult(Result::SUCCESS, std::move(frame));
 }
diff --git a/modules/desktop_capture/screen_capturer_fuchsia.h b/modules/desktop_capture/screen_capturer_fuchsia.h
index 614da82..25f4fe7 100644
--- a/modules/desktop_capture/screen_capturer_fuchsia.h
+++ b/modules/desktop_capture/screen_capturer_fuchsia.h
@@ -21,12 +21,13 @@
 #include "modules/desktop_capture/desktop_capture_options.h"
 #include "modules/desktop_capture/desktop_capturer.h"
 #include "modules/desktop_capture/desktop_frame.h"
+#include "system_wrappers/include/clock.h"
 
 namespace webrtc {
 
 class ScreenCapturerFuchsia final : public DesktopCapturer {
  public:
-  ScreenCapturerFuchsia();
+  explicit ScreenCapturerFuchsia(const DesktopCaptureOptions& options);
   ~ScreenCapturerFuchsia() override;
 
   // DesktopCapturer interface.
@@ -56,6 +57,7 @@
   // Dimensions of the screen we are capturing
   uint32_t width_;
   uint32_t height_;
+  Clock& clock_;
 };
 
 }  // namespace webrtc