summaryrefslogtreecommitdiffstats
path: root/chrome/browser/printing/print_job.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/printing/print_job.cc')
-rw-r--r--chrome/browser/printing/print_job.cc34
1 files changed, 26 insertions, 8 deletions
diff --git a/chrome/browser/printing/print_job.cc b/chrome/browser/printing/print_job.cc
index bf5b80d..b374b685 100644
--- a/chrome/browser/printing/print_job.cc
+++ b/chrome/browser/printing/print_job.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/printing/print_job.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/message_loop.h"
#include "base/threading/thread_restrictions.h"
#include "base/timer.h"
@@ -15,6 +17,16 @@
using base::TimeDelta;
+namespace {
+
+// Helper function to ensure |owner| is valid until at least |callback| returns.
+void HoldRefCallback(const scoped_refptr<printing::PrintJobWorkerOwner>& owner,
+ const base::Closure& callback) {
+ callback.Run();
+}
+
+} // namespace
+
namespace printing {
PrintJob::PrintJob()
@@ -116,8 +128,11 @@ void PrintJob::StartPrinting() {
return;
// Real work is done in PrintJobWorker::StartPrinting().
- worker_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- worker_.get(), &PrintJobWorker::StartPrinting, document_));
+ worker_->message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&HoldRefCallback, make_scoped_refptr(this),
+ base::Bind(&PrintJobWorker::StartPrinting,
+ base::Unretained(worker_.get()), document_)));
// Set the flag right now.
is_job_pending_ = true;
@@ -223,8 +238,11 @@ void PrintJob::UpdatePrintedDocument(PrintedDocument* new_document) {
if (worker_.get() && worker_->message_loop()) {
DCHECK(!is_job_pending_);
// Sync the document with the worker.
- worker_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- worker_.get(), &PrintJobWorker::OnDocumentChanged, document_));
+ worker_->message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&HoldRefCallback, make_scoped_refptr(this),
+ base::Bind(&PrintJobWorker::OnDocumentChanged,
+ base::Unretained(worker_.get()), document_)));
}
}
@@ -252,8 +270,8 @@ void PrintJob::OnNotifyPrintJobEvent(const JobEventDetails& event_details) {
}
case JobEventDetails::DOC_DONE: {
// This will call Stop() and broadcast a JOB_DONE message.
- MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &PrintJob::OnDocumentDone));
+ MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&PrintJob::OnDocumentDone, this));
break;
}
default: {
@@ -304,7 +322,7 @@ void PrintJob::ControlledWorkerShutdown() {
MSG msg;
HANDLE thread_handle = worker_->thread_handle();
for (; thread_handle;) {
- // Note that we don't do any kind of message priorization since we don't
+ // Note that we don't do any kind of message prioritization since we don't
// execute any pending task or timer.
DWORD result = MsgWaitForMultipleObjects(1, &thread_handle,
FALSE, INFINITE, QS_ALLINPUT);
@@ -318,7 +336,7 @@ void PrintJob::ControlledWorkerShutdown() {
// The thread quit.
break;
} else {
- // An error occured. Assume the thread quit.
+ // An error occurred. Assume the thread quit.
NOTREACHED();
break;
}