Bug 1342872 - part2: Name the nsPagePrintTimer runnable and associate its nsITimers with a DocGroup r=jwatt

MozReview-Commit-ID: 3f3n0l1LgHO

--HG--
extra : rebase_source : 23abde74a90e989630e74fd17b3a1f42a2a4a0d2
This commit is contained in:
Farmer Tseng 2017-03-17 15:22:41 +08:00
parent 737c7bae80
commit e5eabed3c9
3 changed files with 23 additions and 6 deletions

View File

@ -10,6 +10,8 @@
#include "nsIServiceManager.h"
#include "nsPrintEngine.h"
using namespace mozilla;
NS_IMPL_ISUPPORTS_INHERITED(nsPagePrintTimer, mozilla::Runnable, nsITimerCallback)
nsPagePrintTimer::~nsPagePrintTimer()
@ -24,7 +26,7 @@ nsPagePrintTimer::~nsPagePrintTimer()
}
}
nsresult
nsresult
nsPagePrintTimer::StartTimer(bool aUseDelay)
{
nsresult result;
@ -41,6 +43,7 @@ nsPagePrintTimer::StartTimer(bool aUseDelay)
delay = mDelay;
}
}
mTimer->SetTarget(mDocument->EventTargetFor(TaskCategory::Other));
mTimer->InitWithCallback(this, delay, nsITimer::TYPE_ONE_SHOT);
}
return result;
@ -59,6 +62,7 @@ nsPagePrintTimer::StartWatchDogTimer()
} else {
// Instead of just doing one timer for a long period do multiple so we
// can check if the user cancelled the printing.
mWatchDogTimer->SetTarget(mDocument->EventTargetFor(TaskCategory::Other));
mWatchDogTimer->InitWithCallback(this, WATCH_DOG_INTERVAL,
nsITimer::TYPE_ONE_SHOT);
}
@ -158,7 +162,8 @@ nsPagePrintTimer::Notify(nsITimer *timer)
if (donePrePrint && !mWaitingForRemotePrint) {
StopWatchDogTimer();
NS_DispatchToMainThread(this);
// Pass nullptr here since name already was set in constructor.
mDocument->Dispatch(nullptr, TaskCategory::Other, do_AddRef(this));
} else {
// Start the watch dog if we're waiting for preprint to ensure that if any
// mozPrintCallbacks take to long we error out.
@ -188,11 +193,13 @@ nsPagePrintTimer::RemotePrintFinished()
return;
}
mWaitingForRemotePrint->SetTarget(
mDocument->EventTargetFor(mozilla::TaskCategory::Other));
mozilla::Unused <<
mWaitingForRemotePrint->InitWithCallback(this, 0, nsITimer::TYPE_ONE_SHOT);
}
nsresult
nsresult
nsPagePrintTimer::Start(nsPrintObject* aPO)
{
mPrintObj = aPO;
@ -201,7 +208,7 @@ nsPagePrintTimer::Start(nsPrintObject* aPO)
}
void
void
nsPagePrintTimer::Stop()
{
if (mTimer) {

View File

@ -14,6 +14,7 @@
#include "nsThreadUtils.h"
class nsPrintEngine;
class nsIDocument;
//---------------------------------------------------
//-- Page Timer Class
@ -27,15 +28,19 @@ public:
nsPagePrintTimer(nsPrintEngine* aPrintEngine,
nsIDocumentViewerPrint* aDocViewerPrint,
nsIDocument* aDocument,
uint32_t aDelay)
: mPrintEngine(aPrintEngine)
: Runnable("nsPagePrintTimer")
, mPrintEngine(aPrintEngine)
, mDocViewerPrint(aDocViewerPrint)
, mDocument(aDocument)
, mDelay(aDelay)
, mFiringCount(0)
, mPrintObj(nullptr)
, mWatchDogCount(0)
, mDone(false)
{
MOZ_ASSERT(aDocument);
mDocViewerPrint->IncrementDestroyRefCount();
}
@ -62,6 +67,7 @@ private:
nsPrintEngine* mPrintEngine;
nsCOMPtr<nsIDocumentViewerPrint> mDocViewerPrint;
nsCOMPtr<nsIDocument> mDocument;
nsCOMPtr<nsITimer> mTimer;
nsCOMPtr<nsITimer> mWatchDogTimer;
nsCOMPtr<nsITimer> mWaitingForRemotePrint;

View File

@ -3495,11 +3495,15 @@ nsPrintEngine::StartPagePrintTimer(const UniquePtr<nsPrintObject>& aPO)
if (!mPagePrintTimer) {
// Get the delay time in between the printing of each page
// this gives the user more time to press cancel
if (!mDocument) {
MOZ_LOG(gPrintingLog, LogLevel::Error,("Error! mDocument is NULL"));
return NS_ERROR_FAILURE;
}
int32_t printPageDelay = 50;
mPrt->mPrintSettings->GetPrintPageDelay(&printPageDelay);
RefPtr<nsPagePrintTimer> timer =
new nsPagePrintTimer(this, mDocViewerPrint, printPageDelay);
new nsPagePrintTimer(this, mDocViewerPrint, mDocument, printPageDelay);
timer.forget(&mPagePrintTimer);
nsCOMPtr<nsIPrintSession> printSession;