|
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 |
|
8 // Timer Includes |
|
9 #include "nsITimer.h" |
|
10 |
|
11 #include "nsIDocumentViewerPrint.h" |
|
12 #include "nsPrintObject.h" |
|
13 #include "mozilla/Attributes.h" |
|
14 #include "nsThreadUtils.h" |
|
15 |
|
16 class nsPrintEngine; |
|
17 |
|
18 //--------------------------------------------------- |
|
19 //-- Page Timer Class |
|
20 //--------------------------------------------------- |
|
21 class nsPagePrintTimer MOZ_FINAL : public nsRunnable, |
|
22 public nsITimerCallback |
|
23 { |
|
24 public: |
|
25 |
|
26 NS_DECL_ISUPPORTS |
|
27 |
|
28 nsPagePrintTimer(nsPrintEngine* aPrintEngine, |
|
29 nsIDocumentViewerPrint* aDocViewerPrint, |
|
30 uint32_t aDelay) |
|
31 : mPrintEngine(aPrintEngine) |
|
32 , mDocViewerPrint(aDocViewerPrint) |
|
33 , mDelay(aDelay) |
|
34 , mFiringCount(0) |
|
35 , mPrintObj(nullptr) |
|
36 , mWatchDogCount(0) |
|
37 , mDone(false) |
|
38 { |
|
39 mDocViewerPrint->IncrementDestroyRefCount(); |
|
40 } |
|
41 ~nsPagePrintTimer(); |
|
42 |
|
43 NS_DECL_NSITIMERCALLBACK |
|
44 |
|
45 nsresult Start(nsPrintObject* aPO); |
|
46 |
|
47 NS_IMETHOD Run() MOZ_OVERRIDE; |
|
48 |
|
49 void Stop(); |
|
50 |
|
51 private: |
|
52 nsresult StartTimer(bool aUseDelay); |
|
53 nsresult StartWatchDogTimer(); |
|
54 void StopWatchDogTimer(); |
|
55 void Fail(); |
|
56 |
|
57 nsPrintEngine* mPrintEngine; |
|
58 nsCOMPtr<nsIDocumentViewerPrint> mDocViewerPrint; |
|
59 nsCOMPtr<nsITimer> mTimer; |
|
60 nsCOMPtr<nsITimer> mWatchDogTimer; |
|
61 uint32_t mDelay; |
|
62 uint32_t mFiringCount; |
|
63 nsPrintObject * mPrintObj; |
|
64 uint32_t mWatchDogCount; |
|
65 bool mDone; |
|
66 |
|
67 static const uint32_t WATCH_DOG_INTERVAL = 1000; |
|
68 static const uint32_t WATCH_DOG_MAX_COUNT = 10; |
|
69 }; |
|
70 |
|
71 |
|
72 nsresult |
|
73 NS_NewPagePrintTimer(nsPagePrintTimer **aResult); |
|
74 |
|
75 #endif /* nsPagePrintTimer_h___ */ |