Bug 1287712 - TimeDurationAccumulator includes running timer in reports - r?cpearce draft
authorGerald Squelart <gsquelart@mozilla.com>
Tue, 19 Jul 2016 17:46:38 +1000
changeset 389424 d6a59f7cb818b753f98df5467d551ccb368e51cf
parent 389281 feaaf1af1065257b9178faca8b67eed9657b4a17
child 525750 4dc5808653836f36aa41d802ad8bf6d721349be0
push id23400
push usergsquelart@mozilla.com
push dateTue, 19 Jul 2016 08:12:01 +0000
reviewerscpearce
bugs1287712
milestone50.0a1
Bug 1287712 - TimeDurationAccumulator includes running timer in reports - r?cpearce If the timer is currently running, add started time segment until now to Total(), and add 1 to Count(). This ensures correct values are returned without having to Pause(). MozReview-Commit-ID: JSBvL93GtkE
dom/html/HTMLMediaElement.h
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -1573,44 +1573,57 @@ protected:
     // tree before.
     ELEMENT_NOT_INTREE_HAD_INTREE
   };
 
   ElementInTreeState mElementInTreeState;
 
 public:
   // Helper class to measure times for MSE telemetry stats
-  class TimeDurationAccumulator {
+  class TimeDurationAccumulator
+  {
   public:
     TimeDurationAccumulator()
       : mCount(0)
+    {}
+    void Start()
     {
-    }
-    void Start() {
       if (IsStarted()) {
         return;
       }
       mStartTime = TimeStamp::Now();
     }
-    void Pause() {
+    void Pause()
+    {
       if (!IsStarted()) {
         return;
       }
       mSum += (TimeStamp::Now() - mStartTime);
       mCount++;
       mStartTime = TimeStamp();
     }
-    bool IsStarted() const {
+    bool IsStarted() const
+    {
       return !mStartTime.IsNull();
     }
-    double Total() const {
-      return mSum.ToSeconds();
+    double Total() const
+    {
+      if (!IsStarted()) {
+        return mSum.ToSeconds();
+      }
+      // Add current running time until now, but keep it running.
+      return (mSum + (TimeStamp::Now() - mStartTime)).ToSeconds();
     }
-    uint32_t Count() const {
-      return mCount;
+    uint32_t Count() const
+    {
+      if (!IsStarted()) {
+        return mCount;
+      }
+      // Count current run in this report, without increasing the stored count.
+      return mCount + 1;
     }
   private:
     TimeStamp mStartTime;
     TimeDuration mSum;
     uint32_t mCount;
   };
 private:
   // Total time a video has spent playing.