Bug 782070 - Remove NS_NewPagePrintTimer and nsPagePrintTimer::Init; r=roc
authorMs2ger <ms2ger@gmail.com>
Thu, 06 Sep 2012 09:14:49 +0200
changeset 104374 3c8361130a8119dd47ee4d595ba6424df334a438
parent 104373 0c4d6f6f82868045585e4fbc204b3f7b1e7ae3da
child 104375 6c7cf0ab0aaafc147909f5b46511fa41657fcead
push id1059
push uservporof@mozilla.com
push dateThu, 06 Sep 2012 14:43:28 +0000
treeherderfx-team@8467163cb51a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs782070
milestone18.0a1
Bug 782070 - Remove NS_NewPagePrintTimer and nsPagePrintTimer::Init; r=roc
layout/printing/nsPagePrintTimer.cpp
layout/printing/nsPagePrintTimer.h
layout/printing/nsPrintEngine.cpp
--- a/layout/printing/nsPagePrintTimer.cpp
+++ b/layout/printing/nsPagePrintTimer.cpp
@@ -5,24 +5,16 @@
 
 #include "nsPagePrintTimer.h"
 #include "nsIContentViewer.h"
 #include "nsIServiceManager.h"
 #include "nsPrintEngine.h"
 
 NS_IMPL_ISUPPORTS1(nsPagePrintTimer, nsITimerCallback)
 
-nsPagePrintTimer::nsPagePrintTimer() :
-  mPrintEngine(nullptr),
-  mDelay(0),
-  mFiringCount(0),
-  mPrintObj(nullptr)
-{
-}
-
 nsPagePrintTimer::~nsPagePrintTimer()
 {
   // "Destroy" the document viewer; this normally doesn't actually
   // destroy it because of the IncrementDestroyRefCount call below
   // XXX This is messy; the document viewer should use a single approach
   // to keep itself alive during printing
   nsCOMPtr<nsIContentViewer> cv(do_QueryInterface(mDocViewerPrint));
   if (cv) {
@@ -97,55 +89,24 @@ nsPagePrintTimer::Notify(nsITimer *timer
     if (donePrePrint) {
       NS_DispatchToMainThread(this);
     }
 
   }
   return NS_OK;
 }
 
-void 
-nsPagePrintTimer::Init(nsPrintEngine*          aPrintEngine,
-                       nsIDocumentViewerPrint* aDocViewerPrint,
-                       uint32_t                aDelay)
-{
-  mPrintEngine     = aPrintEngine;
-  mDocViewerPrint  = aDocViewerPrint;
-  mDelay           = aDelay;
-
-  mDocViewerPrint->IncrementDestroyRefCount();
-}
-
 nsresult 
 nsPagePrintTimer::Start(nsPrintObject* aPO)
 {
   mPrintObj = aPO;
   return StartTimer(false);
 }
 
 
 void  
 nsPagePrintTimer::Stop()
 {
   if (mTimer) {
     mTimer->Cancel();
     mTimer = nullptr;
   }
 }
-
-nsresult NS_NewPagePrintTimer(nsPagePrintTimer **aResult)
-{
-
-  NS_PRECONDITION(aResult, "null param");
-
-  nsPagePrintTimer* result = new nsPagePrintTimer;
-
-  if (!result) {
-    *aResult = nullptr;
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
-  NS_ADDREF(result);
-  *aResult = result;
-
-  return NS_OK;
-}
-
--- a/layout/printing/nsPagePrintTimer.h
+++ b/layout/printing/nsPagePrintTimer.h
@@ -20,25 +20,31 @@ class nsPrintEngine;
 //---------------------------------------------------
 class nsPagePrintTimer MOZ_FINAL : public nsITimerCallback,
                                    public nsRunnable
 {
 public:
 
   NS_DECL_ISUPPORTS
 
-  nsPagePrintTimer();
+  nsPagePrintTimer(nsPrintEngine* aPrintEngine,
+                   nsIDocumentViewerPrint* aDocViewerPrint,
+                   uint32_t aDelay)
+    : mPrintEngine(aPrintEngine)
+    , mDocViewerPrint(aDocViewerPrint)
+    , mDelay(aDelay)
+    , mFiringCount(0)
+    , mPrintObj(nullptr)
+  {
+    mDocViewerPrint->IncrementDestroyRefCount();
+  }
   ~nsPagePrintTimer();
 
   NS_DECL_NSITIMERCALLBACK
 
-  void Init(nsPrintEngine*          aPrintEngine,
-            nsIDocumentViewerPrint* aDocViewerPrint,
-            uint32_t                aDelay);
-
   nsresult Start(nsPrintObject* aPO);
 
   NS_IMETHOD Run();
 
   void Stop();
 
 private:
   nsresult StartTimer(bool aUseDelay);
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -3327,25 +3327,24 @@ nsPrintEngine::FinishPrintPreview()
 //-----------------------------------------------------------------
 
 
 /*=============== Timer Related Code ======================*/
 nsresult
 nsPrintEngine::StartPagePrintTimer(nsPrintObject* aPO)
 {
   if (!mPagePrintTimer) {
-    nsresult rv = NS_NewPagePrintTimer(&mPagePrintTimer);
-    NS_ENSURE_SUCCESS(rv, rv);
-
     // Get the delay time in between the printing of each page
     // this gives the user more time to press cancel
     int32_t printPageDelay = 50;
     mPrt->mPrintSettings->GetPrintPageDelay(&printPageDelay);
 
-    mPagePrintTimer->Init(this, mDocViewerPrint, printPageDelay);
+    nsRefPtr<nsPagePrintTimer> timer =
+      new nsPagePrintTimer(this, mDocViewerPrint, printPageDelay);
+    timer.forget(&mPagePrintTimer);
   }
 
   return mPagePrintTimer->Start(aPO);
 }
 
 /*=============== nsIObserver Interface ======================*/
 NS_IMETHODIMP 
 nsPrintEngine::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)