Delete Timing class, timing.h, and update all users.

BUG=webrtc:6324

Review-Url: https://codereview.webrtc.org/2290203002
Cr-Original-Commit-Position: refs/heads/master@{#14203}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: cdf37a929336e2ca1e0bcdd5e858ffc75b2b317e
diff --git a/api/statscollector.cc b/api/statscollector.cc
index ffe2415..d21fc30 100644
--- a/api/statscollector.cc
+++ b/api/statscollector.cc
@@ -17,7 +17,6 @@
 #include "webrtc/api/peerconnection.h"
 #include "webrtc/base/base64.h"
 #include "webrtc/base/checks.h"
-#include "webrtc/base/timing.h"
 #include "webrtc/pc/channel.h"
 
 namespace webrtc {
@@ -375,8 +374,10 @@
   RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent());
 }
 
+// Wallclock time in ms.
 double StatsCollector::GetTimeNow() {
-  return rtc::Timing::WallTimeNow() * rtc::kNumMillisecsPerSec;
+  return rtc::TimeUTCMicros() /
+         static_cast<double>(rtc::kNumMicrosecsPerMillisec);
 }
 
 // Adds a MediaStream with tracks that can be used as a |selector| in a call
diff --git a/base/BUILD.gn b/base/BUILD.gn
index 2b1be29..59cdf4c 100644
--- a/base/BUILD.gn
+++ b/base/BUILD.gn
@@ -420,8 +420,6 @@
     "taskrunner.h",
     "thread.cc",
     "thread.h",
-    "timing.cc",
-    "timing.h",
     "urlencode.cc",
     "urlencode.h",
     "worker.cc",
@@ -715,7 +713,6 @@
       "fakesslidentity.h",
       "faketaskrunner.h",
       "gunit.h",
-      "test/faketiming.h",
       "testbase64.h",
       "testechoserver.h",
       "testutils.h",
diff --git a/base/base.gyp b/base/base.gyp
index ed8cd59..9fe2c6c 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -363,8 +363,6 @@
         'taskrunner.h',
         'thread.cc',
         'thread.h',
-        'timing.cc',
-        'timing.h',
         'urlencode.cc',
         'urlencode.h',
         'worker.cc',
diff --git a/base/base_tests.gyp b/base/base_tests.gyp
index 6940a66..e1d5bc0 100644
--- a/base/base_tests.gyp
+++ b/base/base_tests.gyp
@@ -21,7 +21,6 @@
         'fakesslidentity.h',
         'faketaskrunner.h',
         'gunit.h',
-        'test/faketiming.h',
         'testbase64.h',
         'testechoserver.h',
         'testutils.h',
diff --git a/base/test/faketiming.h b/base/test/faketiming.h
deleted file mode 100644
index 388a535..0000000
--- a/base/test/faketiming.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- *  Copyright 2016 The WebRTC project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#ifndef WEBRTC_BASE_TEST_FAKETIMING_H_
-#define WEBRTC_BASE_TEST_FAKETIMING_H_
-
-#include "webrtc/base/timing.h"
-#include "webrtc/base/timeutils.h"
-
-namespace rtc {
-
-class FakeTiming : public Timing {
- public:
-  // Starts at Jan 1, 1983 (UTC).
-  FakeTiming() : now_(410227200.0) {}
-  double TimerNow() override { return now_; }
-  void AdvanceTimeSecs(double seconds) { now_ += seconds; }
-  void AdvanceTimeMillisecs(double ms) { now_ += (ms / kNumMillisecsPerSec); }
-
- private:
-  double now_;
-};
-
-}  // namespace rtc
-
-#endif  // WEBRTC_BASE_TEST_FAKETIMING_H_
diff --git a/base/timeutils.cc b/base/timeutils.cc
index 1be368e..658d079 100644
--- a/base/timeutils.cc
+++ b/base/timeutils.cc
@@ -23,6 +23,7 @@
 #endif
 #include <windows.h>
 #include <mmsystem.h>
+#include <sys/timeb.h>
 #endif
 
 #include "webrtc/base/checks.h"
@@ -185,4 +186,21 @@
             (year - 1970) * 365 + day) * 24 + hour) * 60 + min) * 60 + sec;
 }
 
+int64_t TimeUTCMicros() {
+#if defined(WEBRTC_POSIX)
+  struct timeval time;
+  gettimeofday(&time, NULL);
+  // Convert from second (1.0) and microsecond (1e-6).
+  return (static_cast<int64_t>(time.tv_sec) * rtc::kNumMicrosecsPerSec +
+          time.tv_usec);
+
+#elif defined(WEBRTC_WIN)
+  struct _timeb time;
+  _ftime(&time);
+  // Convert from second (1.0) and milliseconds (1e-3).
+  return (static_cast<int64_t>(time.time) * rtc::kNumMicrosecsPerSec +
+          static_cast<int64_t>(time.millitm) * rtc::kNumMicrosecsPerMillisec);
+#endif
+}
+
 } // namespace rtc
diff --git a/base/timeutils.h b/base/timeutils.h
index 25ef521..cc6deb4 100644
--- a/base/timeutils.h
+++ b/base/timeutils.h
@@ -108,6 +108,18 @@
 // is still 32 bits on many systems.
 int64_t TmToSeconds(const std::tm& tm);
 
+// Return the number of microseconds since January 1, 1970, UTC.
+// Useful mainly when producing logs to be correlated with other
+// devices, and when the devices in question all have properly
+// synchronized clocks.
+//
+// Note that this function obeys the system's idea about what the time
+// is. It is not guaranteed to be monotonic; it will jump in case the
+// system time is changed, e.g., by some other process calling
+// settimeofday. Always use rtc::TimeMicros(), not this function, for
+// measuring time intervals and timeouts.
+int64_t TimeUTCMicros();
+
 }  // namespace rtc
 
 #endif  // WEBRTC_BASE_TIMEUTILS_H_
diff --git a/base/timing.cc b/base/timing.cc
deleted file mode 100644
index 7fdcf6e..0000000
--- a/base/timing.cc
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- *  Copyright 2008 The WebRTC Project Authors. All rights reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#include "webrtc/base/timing.h"
-#include "webrtc/base/timeutils.h"
-
-#if defined(WEBRTC_POSIX)
-#include <errno.h>
-#include <math.h>
-#include <sys/time.h>
-#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
-#include <mach/mach.h>
-#include <mach/clock.h>
-#endif
-#elif defined(WEBRTC_WIN)
-#include <sys/timeb.h>
-#endif
-
-namespace rtc {
-
-Timing::Timing() {}
-
-Timing::~Timing() {}
-
-// static
-double Timing::WallTimeNow() {
-#if defined(WEBRTC_POSIX)
-  struct timeval time;
-  gettimeofday(&time, NULL);
-  // Convert from second (1.0) and microsecond (1e-6).
-  return (static_cast<double>(time.tv_sec) +
-          static_cast<double>(time.tv_usec) * 1.0e-6);
-
-#elif defined(WEBRTC_WIN)
-  struct _timeb time;
-  _ftime(&time);
-  // Convert from second (1.0) and milliseconds (1e-3).
-  return (static_cast<double>(time.time) +
-          static_cast<double>(time.millitm) * 1.0e-3);
-#endif
-}
-
-double Timing::TimerNow() {
-  return (static_cast<double>(TimeNanos()) / kNumNanosecsPerSec);
-}
-
-}  // namespace rtc
diff --git a/base/timing.h b/base/timing.h
deleted file mode 100644
index a73c57d..0000000
--- a/base/timing.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- *  Copyright 2008 The WebRTC Project Authors. All rights reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#ifndef WEBRTC_BASE_TIMING_H_
-#define WEBRTC_BASE_TIMING_H_
-
-namespace rtc {
-
-// TODO(deadbeef): Remove this and use ClockInterface instead.
-class Timing {
- public:
-  Timing();
-  virtual ~Timing();
-
-  // WallTimeNow() returns the current wall-clock time in seconds,
-  // within 10 milliseconds resolution.
-  // WallTimeNow is static and does not require a timer_handle_ on Windows.
-  static double WallTimeNow();
-
-  // TimerNow() is like WallTimeNow(), but is monotonically
-  // increasing.  It returns seconds in resolution of 10 microseconds
-  // or better.  Although timer and wall-clock time have the same
-  // timing unit, they do not necessarily correlate because wall-clock
-  // time may be adjusted backwards, hence not monotonic.
-  // Made virtual so we can make a fake one.
-  // TODO(tommi): The only place we use this (virtual) is in
-  // rtpdata_engine_unittest.cc.  See if it doesn't make more sense to change
-  // that contract or test than to modify this generic class.
-  virtual double TimerNow();
-};
-
-}  // namespace rtc
-
-#endif // WEBRTC_BASE_TIMING_H_
diff --git a/media/base/rtpdataengine.cc b/media/base/rtpdataengine.cc
index 4b6647c..99aa3b1 100644
--- a/media/base/rtpdataengine.cc
+++ b/media/base/rtpdataengine.cc
@@ -14,7 +14,6 @@
 #include "webrtc/base/helpers.h"
 #include "webrtc/base/logging.h"
 #include "webrtc/base/ratelimiter.h"
-#include "webrtc/base/timing.h"
 #include "webrtc/media/base/codec.h"
 #include "webrtc/media/base/mediaconstants.h"
 #include "webrtc/media/base/rtputils.h"
@@ -37,7 +36,6 @@
 RtpDataEngine::RtpDataEngine() {
   data_codecs_.push_back(
       DataCodec(kGoogleRtpDataCodecId, kGoogleRtpDataCodecName));
-  SetTiming(new rtc::Timing());
 }
 
 DataMediaChannel* RtpDataEngine::CreateChannel(
@@ -45,7 +43,7 @@
   if (data_channel_type != DCT_RTP) {
     return NULL;
   }
-  return new RtpDataMediaChannel(timing_.get());
+  return new RtpDataMediaChannel();
 }
 
 bool FindCodecByName(const std::vector<DataCodec>& codecs,
@@ -60,18 +58,13 @@
   return false;
 }
 
-RtpDataMediaChannel::RtpDataMediaChannel(rtc::Timing* timing) {
-  Construct(timing);
-}
-
 RtpDataMediaChannel::RtpDataMediaChannel() {
-  Construct(NULL);
+  Construct();
 }
 
-void RtpDataMediaChannel::Construct(rtc::Timing* timing) {
+void RtpDataMediaChannel::Construct() {
   sending_ = false;
   receiving_ = false;
-  timing_ = timing;
   send_limiter_.reset(new rtc::RateLimiter(kDataMaxBandwidth / 8, 1.0));
 }
 
@@ -313,7 +306,8 @@
     return false;
   }
 
-  double now = timing_->TimerNow();
+  double now =
+      rtc::TimeMicros() / static_cast<double>(rtc::kNumMicrosecsPerSec);
 
   if (!send_limiter_->CanUse(packet_len, now)) {
     LOG(LS_VERBOSE) << "Dropped data packet of len=" << packet_len
diff --git a/media/base/rtpdataengine.h b/media/base/rtpdataengine.h
index 0181e65..98f90be 100644
--- a/media/base/rtpdataengine.h
+++ b/media/base/rtpdataengine.h
@@ -15,7 +15,6 @@
 #include <string>
 #include <vector>
 
-#include "webrtc/base/timing.h"
 #include "webrtc/media/base/mediachannel.h"
 #include "webrtc/media/base/mediaconstants.h"
 #include "webrtc/media/base/mediaengine.h"
@@ -34,14 +33,8 @@
     return data_codecs_;
   }
 
-  // Mostly for testing with a fake clock.  Ownership is passed in.
-  void SetTiming(rtc::Timing* timing) {
-    timing_.reset(timing);
-  }
-
  private:
   std::vector<DataCodec> data_codecs_;
-  std::unique_ptr<rtc::Timing> timing_;
 };
 
 // Keep track of sequence number and timestamp of an RTP stream.  The
@@ -68,17 +61,9 @@
 
 class RtpDataMediaChannel : public DataMediaChannel {
  public:
-  // Timing* Used for the RtpClock
-  explicit RtpDataMediaChannel(rtc::Timing* timing);
-  // Sets Timing == NULL, so you'll need to call set_timer() before
-  // using it.  This is needed by FakeMediaEngine.
   RtpDataMediaChannel();
   virtual ~RtpDataMediaChannel();
 
-  void set_timing(rtc::Timing* timing) {
-    timing_ = timing;
-  }
-
   virtual bool SetSendParameters(const DataSendParameters& params);
   virtual bool SetRecvParameters(const DataRecvParameters& params);
   virtual bool AddSendStream(const StreamParams& sp);
@@ -104,14 +89,13 @@
     SendDataResult* result);
 
  private:
-  void Construct(rtc::Timing* timing);
+  void Construct();
   bool SetMaxSendBandwidth(int bps);
   bool SetSendCodecs(const std::vector<DataCodec>& codecs);
   bool SetRecvCodecs(const std::vector<DataCodec>& codecs);
 
   bool sending_;
   bool receiving_;
-  rtc::Timing* timing_;
   std::vector<DataCodec> send_codecs_;
   std::vector<DataCodec> recv_codecs_;
   std::vector<StreamParams> send_streams_;
diff --git a/media/base/rtpdataengine_unittest.cc b/media/base/rtpdataengine_unittest.cc
index b5cfd32..35daee5 100644
--- a/media/base/rtpdataengine_unittest.cc
+++ b/media/base/rtpdataengine_unittest.cc
@@ -15,28 +15,11 @@
 #include "webrtc/base/gunit.h"
 #include "webrtc/base/helpers.h"
 #include "webrtc/base/ssladapter.h"
-#include "webrtc/base/timing.h"
 #include "webrtc/media/base/fakenetworkinterface.h"
 #include "webrtc/media/base/mediaconstants.h"
 #include "webrtc/media/base/rtpdataengine.h"
 #include "webrtc/media/base/rtputils.h"
 
-class FakeTiming : public rtc::Timing {
- public:
-  FakeTiming() : now_(0.0) {}
-
-  virtual double TimerNow() {
-    return now_;
-  }
-
-  void set_now(double now) {
-    now_ = now;
-  }
-
- private:
-  double now_;
-};
-
 class FakeDataReceiver : public sigslot::has_slots<> {
  public:
   FakeDataReceiver() : has_received_data_(false) {}
@@ -69,18 +52,16 @@
   virtual void SetUp() {
     // Seed needed for each test to satisfy expectations.
     iface_.reset(new cricket::FakeNetworkInterface());
-    timing_ = new FakeTiming();
-    dme_.reset(CreateEngine(timing_));
+    dme_.reset(CreateEngine());
     receiver_.reset(new FakeDataReceiver());
   }
 
   void SetNow(double now) {
-    timing_->set_now(now);
+    clock_.SetTimeNanos(now * rtc::kNumNanosecsPerSec);
   }
 
-  cricket::RtpDataEngine* CreateEngine(FakeTiming* timing) {
+  cricket::RtpDataEngine* CreateEngine() {
     cricket::RtpDataEngine* dme = new cricket::RtpDataEngine();
-    dme->SetTiming(timing);
     return dme;
   }
 
@@ -143,8 +124,7 @@
 
  private:
   std::unique_ptr<cricket::RtpDataEngine> dme_;
-  // Timing passed into dme_.  Owned by dme_;
-  FakeTiming* timing_;
+  rtc::ScopedFakeClock clock_;
   std::unique_ptr<cricket::FakeNetworkInterface> iface_;
   std::unique_ptr<FakeDataReceiver> receiver_;
 };
@@ -290,69 +270,6 @@
   EXPECT_EQ(header0.timestamp + 180000, header1.timestamp);
 }
 
-TEST_F(RtpDataMediaChannelTest, SendDataMultipleClocks) {
-  // Timings owned by RtpDataEngines.
-  FakeTiming* timing1 = new FakeTiming();
-  std::unique_ptr<cricket::RtpDataEngine> dme1(CreateEngine(timing1));
-  std::unique_ptr<cricket::RtpDataMediaChannel> dmc1(
-      CreateChannel(dme1.get()));
-  FakeTiming* timing2 = new FakeTiming();
-  std::unique_ptr<cricket::RtpDataEngine> dme2(CreateEngine(timing2));
-  std::unique_ptr<cricket::RtpDataMediaChannel> dmc2(
-      CreateChannel(dme2.get()));
-
-  ASSERT_TRUE(dmc1->SetSend(true));
-  ASSERT_TRUE(dmc2->SetSend(true));
-
-  cricket::StreamParams stream1;
-  stream1.add_ssrc(41);
-  ASSERT_TRUE(dmc1->AddSendStream(stream1));
-  cricket::StreamParams stream2;
-  stream2.add_ssrc(42);
-  ASSERT_TRUE(dmc2->AddSendStream(stream2));
-
-  cricket::DataCodec codec;
-  codec.id = 103;
-  codec.name = cricket::kGoogleRtpDataCodecName;
-  cricket::DataSendParameters parameters;
-  parameters.codecs.push_back(codec);
-  ASSERT_TRUE(dmc1->SetSendParameters(parameters));
-  ASSERT_TRUE(dmc2->SetSendParameters(parameters));
-
-  cricket::SendDataParams params1;
-  params1.ssrc = 41;
-  cricket::SendDataParams params2;
-  params2.ssrc = 42;
-
-  unsigned char data[] = "foo";
-  rtc::CopyOnWriteBuffer payload(data, 3);
-  cricket::SendDataResult result;
-
-  EXPECT_TRUE(dmc1->SendData(params1, payload, &result));
-  EXPECT_TRUE(dmc2->SendData(params2, payload, &result));
-
-  // Should bump timestamp by 90000 because the clock rate is 90khz.
-  timing1->set_now(1);
-  // Should bump timestamp by 180000 because the clock rate is 90khz.
-  timing2->set_now(2);
-
-  EXPECT_TRUE(dmc1->SendData(params1, payload, &result));
-  EXPECT_TRUE(dmc2->SendData(params2, payload, &result));
-
-  ASSERT_TRUE(HasSentData(3));
-  cricket::RtpHeader header1a = GetSentDataHeader(0);
-  cricket::RtpHeader header2a = GetSentDataHeader(1);
-  cricket::RtpHeader header1b = GetSentDataHeader(2);
-  cricket::RtpHeader header2b = GetSentDataHeader(3);
-
-  EXPECT_EQ(static_cast<uint16_t>(header1a.seq_num + 1),
-            static_cast<uint16_t>(header1b.seq_num));
-  EXPECT_EQ(header1a.timestamp + 90000, header1b.timestamp);
-  EXPECT_EQ(static_cast<uint16_t>(header2a.seq_num + 1),
-            static_cast<uint16_t>(header2b.seq_num));
-  EXPECT_EQ(header2a.timestamp + 180000, header2b.timestamp);
-}
-
 TEST_F(RtpDataMediaChannelTest, SendDataRate) {
   std::unique_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel());
 
diff --git a/stats/rtcstatscollector.cc b/stats/rtcstatscollector.cc
index 1cdafd6..3ff4155 100644
--- a/stats/rtcstatscollector.cc
+++ b/stats/rtcstatscollector.cc
@@ -16,7 +16,6 @@
 
 #include "webrtc/api/peerconnection.h"
 #include "webrtc/base/checks.h"
-#include "webrtc/base/timing.h"
 
 namespace webrtc {
 
@@ -63,8 +62,7 @@
     // "Now" using a system clock, relative to the UNIX epoch (Jan 1, 1970,
     // UTC), in microseconds. The system clock could be modified and is not
     // necessarily monotonically increasing.
-    int64_t timestamp_us = static_cast<int64_t>(
-        rtc::Timing::WallTimeNow() * rtc::kNumMicrosecsPerSec);
+    int64_t timestamp_us = rtc::TimeUTCMicros();
 
     num_pending_partial_reports_ = 3;
     partial_report_timestamp_us_ = cache_now_us;
diff --git a/stats/rtcstatscollector_unittest.cc b/stats/rtcstatscollector_unittest.cc
index 1ead77b..f3d232f 100644
--- a/stats/rtcstatscollector_unittest.cc
+++ b/stats/rtcstatscollector_unittest.cc
@@ -27,7 +27,6 @@
 #include "webrtc/base/thread_checker.h"
 #include "webrtc/base/timedelta.h"
 #include "webrtc/base/timeutils.h"
-#include "webrtc/base/timing.h"
 #include "webrtc/media/base/fakemediaengine.h"
 
 using testing::Return;
@@ -314,11 +313,9 @@
 }
 
 TEST_F(RTCStatsCollectorTest, CollectRTCPeerConnectionStats) {
-  int64_t before = static_cast<int64_t>(
-      rtc::Timing::WallTimeNow() * rtc::kNumMicrosecsPerSec);
+  int64_t before = rtc::TimeUTCMicros();
   rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport();
-  int64_t after = static_cast<int64_t>(
-      rtc::Timing::WallTimeNow() * rtc::kNumMicrosecsPerSec);
+  int64_t after = rtc::TimeUTCMicros();
   EXPECT_EQ(report->GetStatsOfType<RTCPeerConnectionStats>().size(),
             static_cast<size_t>(1)) << "Expecting 1 RTCPeerConnectionStats.";
   const RTCStats* stats = report->Get("RTCPeerConnection");