Bug 1183786 - Part 3: Make nsPresContext helper-function return already_AddRefed instead of bool+outparam. r=tn
authorDaniel Holbert <dholbert@cs.stanford.edu>
Mon, 03 Aug 2015 17:13:07 -0700
changeset 287677 db090fd8b881f2ecc5a194e3a42d6c2f7880f03c
parent 287676 3ee7019afe884b9b486559abb6c43561ea266851
child 287678 5f4299f601f356bae060a5c661b316f3ada13c80
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)
reviewerstn
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 3: Make nsPresContext helper-function return already_AddRefed instead of bool+outparam. r=tn
layout/base/nsPresContext.cpp
layout/base/nsPresContext.h
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -927,17 +927,18 @@ nsPresContext::PreferenceChanged(const c
   if (!mPrefChangedTimer)
   {
     // 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();
-    if (!InitTimer(mPrefChangedTimer, nsPresContext::PrefChangedUpdateTimerCallback, 0)) {
+    mPrefChangedTimer = CreateTimer(PrefChangedUpdateTimerCallback, 0);
+    if (!mPrefChangedTimer) {
       return;
     }
   }
   if (prefName.EqualsLiteral("nglayout.debug.paint_flashing") ||
       prefName.EqualsLiteral("nglayout.debug.paint_flashing_chrome")) {
     mPaintFlashingInitialized = false;
     return;
   }
@@ -1575,17 +1576,17 @@ void
 nsPresContext::SetContainer(nsIDocShell* aDocShell)
 {
   if (aDocShell) {
     NS_ASSERTION(!(!!mContainer && mNeedsPrefUpdate),
                  "Should only need pref update if mContainer is null.");
     mContainer = static_cast<nsDocShell*>(aDocShell);
     if (mNeedsPrefUpdate) {
       if (!mPrefChangedTimer) {
-        InitTimer(mPrefChangedTimer, nsPresContext::PrefChangedUpdateTimerCallback, 0);
+        mPrefChangedTimer = CreateTimer(PrefChangedUpdateTimerCallback, 0);
       }
       mNeedsPrefUpdate = false;
     }
   } else {
     mContainer = WeakPtr<nsDocShell>();
   }
   UpdateIsChrome();
   if (mContainer) {
@@ -2539,29 +2540,30 @@ nsPresContext::NotifyDidPaintForSubtree(
 }
 
 bool
 nsPresContext::HasCachedStyleData()
 {
   return mShell && mShell->StyleSet()->HasCachedStyleData();
 }
 
-bool
-nsPresContext::InitTimer(nsCOMPtr<nsITimer>& aTimer,
-                         nsTimerCallbackFunc aCallback,
-                         uint32_t aDelay)
+already_AddRefed<nsITimer>
+nsPresContext::CreateTimer(nsTimerCallbackFunc aCallback,
+                           uint32_t aDelay)
 {
-  aTimer = do_CreateInstance("@mozilla.org/timer;1");
-  if (!aTimer) {
-    return false;
+  nsCOMPtr<nsITimer> timer = do_CreateInstance("@mozilla.org/timer;1");
+  if (timer) {
+    nsresult rv = timer->InitWithFuncCallback(aCallback, this, aDelay,
+                                              nsITimer::TYPE_ONE_SHOT);
+    if (NS_SUCCEEDED(rv)) {
+      return timer.forget();
+    }
   }
 
-  nsresult rv = aTimer->InitWithFuncCallback(aCallback, this, aDelay,
-                                             nsITimer::TYPE_ONE_SHOT);
-  return NS_SUCCEEDED(rv);
+  return nullptr;
 }
 
 static bool sGotInterruptEnv = false;
 enum InterruptMode {
   ModeRandom,
   ModeCounter,
   ModeEvent
 };
@@ -2943,19 +2945,18 @@ 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.
-  InitTimer(mApplyPluginGeometryTimer,
-            ApplyPluginGeometryUpdatesCallback,
-            nsRefreshDriver::DefaultInterval() * 2);
+  mApplyPluginGeometryTimer = CreateTimer(ApplyPluginGeometryUpdatesCallback,
+                                          nsRefreshDriver::DefaultInterval() * 2);
 }
 
 void
 nsRootPresContext::CancelApplyPluginGeometryTimer()
 {
   if (mApplyPluginGeometryTimer) {
     mApplyPluginGeometryTimer->Cancel();
     mApplyPluginGeometryTimer = nullptr;
@@ -3116,17 +3117,17 @@ NotifyDidPaintForSubtreeCallback(nsITime
 }
 
 void
 nsRootPresContext::EnsureEventualDidPaintEvent()
 {
   if (mNotifyDidPaintTimer)
     return;
 
-  InitTimer(mNotifyDidPaintTimer, NotifyDidPaintForSubtreeCallback, 100);
+  mNotifyDidPaintTimer = CreateTimer(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,19 +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);
+  // Creates a one-shot timer with the given aCallback & aDelay.
+  // Returns a refcounted pointer to the timer (or nullptr on failure).
+  already_AddRefed<nsITimer> CreateTimer(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