Bug 1325467 - Part 1: Add Timeout::mIsTracking; r=bkelly
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 21 Dec 2016 22:34:52 -0500
changeset 374756 00c84bfb500599f5a427a51f52145d0cde8cb204
parent 374755 1214fccec674373d756441d7cc9375e636586306
child 374757 ae1b2492b2fce313ad59d594d4e3cc3d41aad879
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1325467
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1325467 - Part 1: Add Timeout::mIsTracking; r=bkelly
dom/base/Timeout.cpp
dom/base/Timeout.h
dom/base/TimeoutManager.cpp
--- a/dom/base/Timeout.cpp
+++ b/dom/base/Timeout.cpp
@@ -13,16 +13,17 @@
 
 namespace mozilla {
 namespace dom {
 
 Timeout::Timeout()
   : mCleared(false),
     mRunning(false),
     mIsInterval(false),
+    mIsTracking(false),
     mReason(Reason::eTimeoutOrInterval),
     mTimeoutId(0),
     mInterval(0),
     mFiringDepth(0),
     mNestingLevel(0),
     mPopupState(openAllowed)
 {
   MOZ_COUNT_CTOR(Timeout);
--- a/dom/base/Timeout.h
+++ b/dom/base/Timeout.h
@@ -68,16 +68,19 @@ public:
   bool mCleared;
 
   // True if this is one of the timeouts that are currently running
   bool mRunning;
 
   // True if this is a repeating/interval timer
   bool mIsInterval;
 
+  // True if this is a timeout coming from a tracking script
+  bool mIsTracking;
+
   Reason mReason;
 
   // Returned as value of setTimeout()
   uint32_t mTimeoutId;
 
   // Interval in milliseconds
   uint32_t mInterval;
 
--- a/dom/base/TimeoutManager.cpp
+++ b/dom/base/TimeoutManager.cpp
@@ -162,16 +162,37 @@ TimeoutManager::SetTimeout(nsITimeoutHan
   }
 
   RefPtr<Timeout> timeout = new Timeout();
   timeout->mIsInterval = aIsInterval;
   timeout->mInterval = interval;
   timeout->mScriptHandler = aHandler;
   timeout->mReason = aReason;
 
+  switch (gTimeoutBucketingStrategy) {
+  default:
+  case TRACKING_SEPARATE_TIMEOUT_BUCKETING_STRATEGY: {
+    const char* filename = nullptr;
+    uint32_t dummyLine = 0, dummyColumn = 0;
+    aHandler->GetLocation(&filename, &dummyLine, &dummyColumn);
+    timeout->mIsTracking = doc->IsScriptTracking(nsDependentCString(filename));
+    break;
+  }
+  case ALL_NORMAL_TIMEOUT_BUCKETING_STRATEGY:
+    // timeout->mIsTracking is already false!
+    MOZ_DIAGNOSTIC_ASSERT(!timeout->mIsTracking);
+    break;
+  case ALTERNATE_TIMEOUT_BUCKETING_STRATEGY:
+    timeout->mIsTracking = (mTimeoutIdCounter % 2) == 0;
+    break;
+  case RANDOM_TIMEOUT_BUCKETING_STRATEGY:
+    timeout->mIsTracking = (rand() % 2) == 0;
+    break;
+  }
+
   // Now clamp the actual interval we will use for the timer based on
   uint32_t nestingLevel = sNestingLevel + 1;
   uint32_t realInterval = interval;
   if (aIsInterval || nestingLevel >= DOM_CLAMP_TIMEOUT_NESTING_LEVEL ||
       mBackPressureDelayMS > 0 || mWindow.IsBackgroundInternal()) {
     // Don't allow timeouts less than DOMMinTimeoutValue() from
     // now...
     realInterval = std::max(realInterval, uint32_t(DOMMinTimeoutValue()));
@@ -224,40 +245,19 @@ TimeoutManager::SetTimeout(nsITimeoutHan
     // This is checking |interval|, not realInterval, on purpose,
     // because our lower bound for |realInterval| could be pretty high
     // in some cases.
     if (interval <= delay) {
       timeout->mPopupState = mWindow.GetPopupControlState();
     }
   }
 
-  bool isTracking = false;
-  switch (gTimeoutBucketingStrategy) {
-  default:
-  case TRACKING_SEPARATE_TIMEOUT_BUCKETING_STRATEGY: {
-    const char* filename = nullptr;
-    uint32_t dummyLine = 0, dummyColumn = 0;
-    aHandler->GetLocation(&filename, &dummyLine, &dummyColumn);
-    isTracking = doc->IsScriptTracking(nsDependentCString(filename));
-    break;
-  }
-  case ALL_NORMAL_TIMEOUT_BUCKETING_STRATEGY:
-    // isTracking is already false!
-    break;
-  case ALTERNATE_TIMEOUT_BUCKETING_STRATEGY:
-    isTracking = (mTimeoutIdCounter % 2) == 0;
-    break;
-  case RANDOM_TIMEOUT_BUCKETING_STRATEGY:
-    isTracking = (rand() % 2) == 0;
-    break;
-  }
-
   Timeouts::SortBy sort(mWindow.IsFrozen() ? Timeouts::SortBy::TimeRemaining
                                            : Timeouts::SortBy::TimeWhen);
-  if (isTracking) {
+  if (timeout->mIsTracking) {
     mTrackingTimeouts.Insert(timeout, sort);
   } else {
     mNormalTimeouts.Insert(timeout, sort);
   }
 
   timeout->mTimeoutId = GetTimeoutId(aReason);
   *aReturn = timeout->mTimeoutId;