michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #ifndef nsPagePrintTimer_h___ michael@0: #define nsPagePrintTimer_h___ michael@0: michael@0: // Timer Includes michael@0: #include "nsITimer.h" michael@0: michael@0: #include "nsIDocumentViewerPrint.h" michael@0: #include "nsPrintObject.h" michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsThreadUtils.h" michael@0: michael@0: class nsPrintEngine; michael@0: michael@0: //--------------------------------------------------- michael@0: //-- Page Timer Class michael@0: //--------------------------------------------------- michael@0: class nsPagePrintTimer MOZ_FINAL : public nsRunnable, michael@0: public nsITimerCallback michael@0: { michael@0: public: michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: nsPagePrintTimer(nsPrintEngine* aPrintEngine, michael@0: nsIDocumentViewerPrint* aDocViewerPrint, michael@0: uint32_t aDelay) michael@0: : mPrintEngine(aPrintEngine) michael@0: , mDocViewerPrint(aDocViewerPrint) michael@0: , mDelay(aDelay) michael@0: , mFiringCount(0) michael@0: , mPrintObj(nullptr) michael@0: , mWatchDogCount(0) michael@0: , mDone(false) michael@0: { michael@0: mDocViewerPrint->IncrementDestroyRefCount(); michael@0: } michael@0: ~nsPagePrintTimer(); michael@0: michael@0: NS_DECL_NSITIMERCALLBACK michael@0: michael@0: nsresult Start(nsPrintObject* aPO); michael@0: michael@0: NS_IMETHOD Run() MOZ_OVERRIDE; michael@0: michael@0: void Stop(); michael@0: michael@0: private: michael@0: nsresult StartTimer(bool aUseDelay); michael@0: nsresult StartWatchDogTimer(); michael@0: void StopWatchDogTimer(); michael@0: void Fail(); michael@0: michael@0: nsPrintEngine* mPrintEngine; michael@0: nsCOMPtr mDocViewerPrint; michael@0: nsCOMPtr mTimer; michael@0: nsCOMPtr mWatchDogTimer; michael@0: uint32_t mDelay; michael@0: uint32_t mFiringCount; michael@0: nsPrintObject * mPrintObj; michael@0: uint32_t mWatchDogCount; michael@0: bool mDone; michael@0: michael@0: static const uint32_t WATCH_DOG_INTERVAL = 1000; michael@0: static const uint32_t WATCH_DOG_MAX_COUNT = 10; michael@0: }; michael@0: michael@0: michael@0: nsresult michael@0: NS_NewPagePrintTimer(nsPagePrintTimer **aResult); michael@0: michael@0: #endif /* nsPagePrintTimer_h___ */