Bug 1183786 - Part 1: Refactor timer setup code into a helper function. r=dholbert
authorEric Rahm <erahm@mozilla.com>
Thu, 30 Jul 2015 14:24:51 -0700
changeset 287675 d4d1a87bd2c0935a59c15c6679bf39d21c3cad54
parent 287674 ec4b62affc04cc329c12585fd00b0f3e17596124
child 287676 3ee7019afe884b9b486559abb6c43561ea266851
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1183786
milestone42.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 1183786 - Part 1: Refactor timer setup code into a helper function. r=dholbert
layout/base/nsPresContext.cpp
layout/base/nsPresContext.h
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -921,26 +921,25 @@ nsPresContext::PreferenceChanged(const c
   }
   if (StringBeginsWith(prefName, NS_LITERAL_CSTRING("gfx.font_rendering."))) {
     // Changes to font_rendering prefs need to trigger a reflow
     mPrefChangePendingNeedsReflow = true;
   }
   // we use a zero-delay timer to coalesce multiple pref updates
   if (!mPrefChangedTimer)
   {
-    mPrefChangedTimer = do_CreateInstance("@mozilla.org/timer;1");
-    if (!mPrefChangedTimer)
-      return;
     // We will end up calling InvalidatePreferenceSheets one from each pres
     // context, but all it's doing is clearing its cached sheet pointers,
     // so it won't be wastefully recreating the sheet multiple times.
     // The first pres context that has its mPrefChangedTimer called will
     // be the one to cause the reconstruction of the pref style sheet.
     nsLayoutStylesheetCache::InvalidatePreferenceSheets();
-    mPrefChangedTimer->InitWithFuncCallback(nsPresContext::PrefChangedUpdateTimerCallback, (void*)this, 0, nsITimer::TYPE_ONE_SHOT);
+    if (!InitTimer(mPrefChangedTimer, nsPresContext::PrefChangedUpdateTimerCallback, 0)) {
+      return;
+    }
   }
   if (prefName.EqualsLiteral("nglayout.debug.paint_flashing") ||
       prefName.EqualsLiteral("nglayout.debug.paint_flashing_chrome")) {
     mPaintFlashingInitialized = false;
     return;
   }
 }
 
@@ -2526,16 +2525,31 @@ nsPresContext::NotifyDidPaintForSubtree(
 }
 
 bool
 nsPresContext::HasCachedStyleData()
 {
   return mShell && mShell->StyleSet()->HasCachedStyleData();
 }
 
+bool
+nsPresContext::InitTimer(nsCOMPtr<nsITimer>& aTimer,
+                         nsTimerCallbackFunc aCallback,
+                         uint32_t aDelay)
+{
+  aTimer = do_CreateInstance("@mozilla.org/timer;1");
+  if (!aTimer) {
+    return false;
+  }
+
+  nsresult rv = aTimer->InitWithFuncCallback(aCallback, this, aDelay,
+                                             nsITimer::TYPE_ONE_SHOT);
+  return NS_SUCCEEDED(rv);
+}
+
 static bool sGotInterruptEnv = false;
 enum InterruptMode {
   ModeRandom,
   ModeCounter,
   ModeEvent
 };
 // Controlled by the GECKO_REFLOW_INTERRUPT_MODE env var; allowed values are
 // "random" (except on Windows) or "counter".  If neither is used, the mode is
@@ -2915,23 +2929,19 @@ nsRootPresContext::InitApplyPluginGeomet
 
   // We'll apply the plugin geometry updates during the next compositing paint in this
   // presContext (either from nsPresShell::WillPaintWindow or from
   // nsPresShell::DidPaintWindow, depending on the platform).  But paints might
   // get optimized away if the old plugin geometry covers the invalid region,
   // so set a backup timer to do this too.  We want to make sure this
   // won't fire before our normal paint notifications, if those would
   // update the geometry, so set it for double the refresh driver interval.
-  mApplyPluginGeometryTimer = do_CreateInstance("@mozilla.org/timer;1");
-  if (mApplyPluginGeometryTimer) {
-    mApplyPluginGeometryTimer->
-      InitWithFuncCallback(ApplyPluginGeometryUpdatesCallback, this,
-                           nsRefreshDriver::DefaultInterval() * 2,
-                           nsITimer::TYPE_ONE_SHOT);
-  }
+  InitTimer(mApplyPluginGeometryTimer,
+            ApplyPluginGeometryUpdatesCallback,
+            nsRefreshDriver::DefaultInterval() * 2);
 }
 
 void
 nsRootPresContext::CancelApplyPluginGeometryTimer()
 {
   if (mApplyPluginGeometryTimer) {
     mApplyPluginGeometryTimer->Cancel();
     mApplyPluginGeometryTimer = nullptr;
@@ -3091,21 +3101,18 @@ NotifyDidPaintForSubtreeCallback(nsITime
       nsIPresShell::PAINT_LAYERS | nsIPresShell::PAINT_COMPOSITE);
 }
 
 void
 nsRootPresContext::EnsureEventualDidPaintEvent()
 {
   if (mNotifyDidPaintTimer)
     return;
-  mNotifyDidPaintTimer = do_CreateInstance("@mozilla.org/timer;1");
-  if (!mNotifyDidPaintTimer)
-    return;
-  mNotifyDidPaintTimer->InitWithFuncCallback(NotifyDidPaintForSubtreeCallback,
-                                             (void*)this, 100, nsITimer::TYPE_ONE_SHOT);
+
+  InitTimer(mNotifyDidPaintTimer, NotifyDidPaintForSubtreeCallback, 100);
 }
 
 void
 nsRootPresContext::AddWillPaintObserver(nsIRunnable* aRunnable)
 {
   if (!mWillPaintFallbackEvent.IsPending()) {
     mWillPaintFallbackEvent = new RunWillPaintObservers(this);
     NS_DispatchToMainThread(mWillPaintFallbackEvent.get());
--- a/layout/base/nsPresContext.h
+++ b/layout/base/nsPresContext.h
@@ -1188,16 +1188,20 @@ protected:
 
   bool HavePendingInputEvent();
 
   // Can't be inline because we can't include nsStyleSet.h.
   bool HasCachedStyleData();
 
   bool IsChromeSlow() const;
 
+  bool InitTimer(nsCOMPtr<nsITimer>& aTimer,
+                 nsTimerCallbackFunc aCallback,
+                 uint32_t aDelay);
+
   // IMPORTANT: The ownership implicit in the following member variables
   // has been explicitly checked.  If you add any members to this class,
   // please make the ownership explicit (pinkerton, scc).
 
   nsPresContextType     mType;
   // the nsPresShell owns a strong reference to the nsPresContext, and is responsible
   // for nulling this pointer before it is destroyed
   nsIPresShell* MOZ_NON_OWNING_REF mShell;         // [WEAK]