nsPagePrintTimer.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef nsPagePrintTimer_h___
  6. #define nsPagePrintTimer_h___
  7. // Timer Includes
  8. #include "nsITimer.h"
  9. #include "nsIDocumentViewerPrint.h"
  10. #include "nsPrintObject.h"
  11. #include "mozilla/Attributes.h"
  12. #include "nsThreadUtils.h"
  13. class nsPrintEngine;
  14. //---------------------------------------------------
  15. //-- Page Timer Class
  16. //---------------------------------------------------
  17. class nsPagePrintTimer final : public mozilla::Runnable,
  18. public nsITimerCallback
  19. {
  20. public:
  21. NS_DECL_ISUPPORTS_INHERITED
  22. nsPagePrintTimer(nsPrintEngine* aPrintEngine,
  23. nsIDocumentViewerPrint* aDocViewerPrint,
  24. uint32_t aDelay)
  25. : mPrintEngine(aPrintEngine)
  26. , mDocViewerPrint(aDocViewerPrint)
  27. , mDelay(aDelay)
  28. , mFiringCount(0)
  29. , mPrintObj(nullptr)
  30. , mWatchDogCount(0)
  31. , mDone(false)
  32. {
  33. mDocViewerPrint->IncrementDestroyRefCount();
  34. }
  35. NS_DECL_NSITIMERCALLBACK
  36. nsresult Start(nsPrintObject* aPO);
  37. NS_IMETHOD Run() override;
  38. void Stop();
  39. void WaitForRemotePrint();
  40. void RemotePrintFinished();
  41. void Disconnect()
  42. {
  43. mPrintEngine = nullptr;
  44. mPrintObj = nullptr;
  45. }
  46. private:
  47. ~nsPagePrintTimer();
  48. nsresult StartTimer(bool aUseDelay);
  49. nsresult StartWatchDogTimer();
  50. void StopWatchDogTimer();
  51. void Fail();
  52. nsPrintEngine* mPrintEngine;
  53. nsCOMPtr<nsIDocumentViewerPrint> mDocViewerPrint;
  54. nsCOMPtr<nsITimer> mTimer;
  55. nsCOMPtr<nsITimer> mWatchDogTimer;
  56. nsCOMPtr<nsITimer> mWaitingForRemotePrint;
  57. uint32_t mDelay;
  58. uint32_t mFiringCount;
  59. nsPrintObject * mPrintObj;
  60. uint32_t mWatchDogCount;
  61. bool mDone;
  62. static const uint32_t WATCH_DOG_INTERVAL = 1000;
  63. static const uint32_t WATCH_DOG_MAX_COUNT =
  64. #ifdef DEBUG
  65. // Debug builds are very slow (on Mac at least) and can need extra time
  66. 30
  67. #else
  68. 10
  69. #endif
  70. ;
  71. };
  72. nsresult
  73. NS_NewPagePrintTimer(nsPagePrintTimer **aResult);
  74. #endif /* nsPagePrintTimer_h___ */