Bug 1348738 - (Part 1) Refactor nsRepeatService's InitWithCallback calls into a common helper function. r?dholbert draft
authorKuoE0 <kuoe0.tw@gmail.com>
Wed, 29 Mar 2017 15:40:04 +0800
changeset 555983 564ded2cb66cccbcb08c9fe95d7438d42b3b6431
parent 555982 599d6de4062828530baf5827c0eb37d3e01fac62
child 555984 68d8c631fc02082cc64fdee4df48c89c9b75ad07
child 556051 c0a56ea4ddcba190d7f5e80d1de3f46ad07bf723
child 556267 24647ced947fd8b065c072c198cbc7e36b8c8d78
push id52390
push userbmo:kuoe0@mozilla.com
push dateWed, 05 Apr 2017 06:40:09 +0000
reviewersdholbert
bugs1348738
milestone55.0a1
Bug 1348738 - (Part 1) Refactor nsRepeatService's InitWithCallback calls into a common helper function. r?dholbert MozReview-Commit-ID: 2uJNeSsrjSW
layout/xul/nsRepeatService.cpp
layout/xul/nsRepeatService.h
--- a/layout/xul/nsRepeatService.cpp
+++ b/layout/xul/nsRepeatService.cpp
@@ -48,17 +48,17 @@ void nsRepeatService::Start(Callback aCa
   NS_PRECONDITION(aCallback != nullptr, "null ptr");
 
   mCallback = aCallback;
   mCallbackData = aCallbackData;
   nsresult rv;
   mRepeatTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
 
   if (NS_SUCCEEDED(rv))  {
-    mRepeatTimer->InitWithCallback(this, aInitialDelay, nsITimer::TYPE_ONE_SHOT);
+    InitTimerCallback(aInitialDelay);
   }
 }
 
 void nsRepeatService::Stop(Callback aCallback, void* aCallbackData)
 {
   if (mCallback != aCallback || mCallbackData != aCallbackData)
     return;
 
@@ -73,15 +73,21 @@ void nsRepeatService::Stop(Callback aCal
 
 NS_IMETHODIMP nsRepeatService::Notify(nsITimer *timer)
 {
   // do callback
   if (mCallback)
     mCallback(mCallbackData);
 
   // start timer again.
-  if (mRepeatTimer) {
-    mRepeatTimer->InitWithCallback(this, REPEAT_DELAY, nsITimer::TYPE_ONE_SHOT);
-  }
+  InitTimerCallback(REPEAT_DELAY);
   return NS_OK;
 }
 
+void
+nsRepeatService::InitTimerCallback(uint32_t aInitialDelay)
+{
+  if (mRepeatTimer) {
+    mRepeatTimer->InitWithCallback(this, aInitialDelay, nsITimer::TYPE_ONE_SHOT);
+  }
+}
+
 NS_IMPL_ISUPPORTS(nsRepeatService, nsITimerCallback)
--- a/layout/xul/nsRepeatService.h
+++ b/layout/xul/nsRepeatService.h
@@ -45,15 +45,18 @@ public:
 
   NS_DECL_ISUPPORTS
 
 protected:
   nsRepeatService();
   virtual ~nsRepeatService();
 
 private:
+  // helper function to initialize callback function to mRepeatTimer
+  void InitTimerCallback(uint32_t aInitialDelay);
+
   Callback           mCallback;
   void*              mCallbackData;
   nsCOMPtr<nsITimer> mRepeatTimer;
 
 }; // class nsRepeatService
 
 #endif