OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/printing/print_job_worker.h" | 5 #include "chrome/browser/printing/print_job_worker.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 void PrintJobWorker::OnDocumentDone() { | 366 void PrintJobWorker::OnDocumentDone() { |
367 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 367 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
368 DCHECK_EQ(page_number_, PageNumber::npos()); | 368 DCHECK_EQ(page_number_, PageNumber::npos()); |
369 DCHECK(document_.get()); | 369 DCHECK(document_.get()); |
370 | 370 |
371 if (printing_context_->DocumentDone() != PrintingContext::OK) { | 371 if (printing_context_->DocumentDone() != PrintingContext::OK) { |
372 OnFailure(); | 372 OnFailure(); |
373 return; | 373 return; |
374 } | 374 } |
375 | 375 |
376 owner_->PostTask(FROM_HERE, | 376 owner_->PostTask( |
377 base::Bind(&NotificationCallback, | 377 FROM_HERE, |
378 make_scoped_refptr(owner_), | 378 base::Bind(&NotificationCallback, base::RetainedRef(owner_), |
379 JobEventDetails::DOC_DONE, | 379 JobEventDetails::DOC_DONE, base::RetainedRef(document_), |
380 document_, | 380 base::RetainedRef<PrintedPage>(nullptr))); |
Nico
2016/03/18 21:01:01
RetainedRef<>(nullptr)? Why can't this just pass n
vmpstr
2016/03/18 22:20:23
Oh oops. I meant to go back and see if nullptr wor
| |
381 scoped_refptr<PrintedPage>())); | |
382 | 381 |
383 // Makes sure the variables are reinitialized. | 382 // Makes sure the variables are reinitialized. |
384 document_ = NULL; | 383 document_ = NULL; |
385 } | 384 } |
386 | 385 |
387 void PrintJobWorker::SpoolPage(PrintedPage* page) { | 386 void PrintJobWorker::SpoolPage(PrintedPage* page) { |
388 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 387 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
389 DCHECK_NE(page_number_, PageNumber::npos()); | 388 DCHECK_NE(page_number_, PageNumber::npos()); |
390 | 389 |
391 // Signal everyone that the page is about to be printed. | 390 // Signal everyone that the page is about to be printed. |
392 owner_->PostTask(FROM_HERE, | 391 owner_->PostTask( |
393 base::Bind(&NotificationCallback, | 392 FROM_HERE, |
394 make_scoped_refptr(owner_), | 393 base::Bind(&NotificationCallback, base::RetainedRef(owner_), |
395 JobEventDetails::NEW_PAGE, | 394 JobEventDetails::NEW_PAGE, base::RetainedRef(document_), |
396 document_, | 395 base::RetainedRef(page))); |
397 make_scoped_refptr(page))); | |
398 | 396 |
399 // Preprocess. | 397 // Preprocess. |
400 if (printing_context_->NewPage() != PrintingContext::OK) { | 398 if (printing_context_->NewPage() != PrintingContext::OK) { |
401 OnFailure(); | 399 OnFailure(); |
402 return; | 400 return; |
403 } | 401 } |
404 | 402 |
405 // Actual printing. | 403 // Actual printing. |
406 #if defined(OS_WIN) || defined(OS_MACOSX) | 404 #if defined(OS_WIN) || defined(OS_MACOSX) |
407 document_->RenderPrintedPage(*page, printing_context_->context()); | 405 document_->RenderPrintedPage(*page, printing_context_->context()); |
408 #elif defined(OS_POSIX) | 406 #elif defined(OS_POSIX) |
409 document_->RenderPrintedPage(*page, printing_context_.get()); | 407 document_->RenderPrintedPage(*page, printing_context_.get()); |
410 #endif | 408 #endif |
411 | 409 |
412 // Postprocess. | 410 // Postprocess. |
413 if (printing_context_->PageDone() != PrintingContext::OK) { | 411 if (printing_context_->PageDone() != PrintingContext::OK) { |
414 OnFailure(); | 412 OnFailure(); |
415 return; | 413 return; |
416 } | 414 } |
417 | 415 |
418 // Signal everyone that the page is printed. | 416 // Signal everyone that the page is printed. |
419 owner_->PostTask(FROM_HERE, | 417 owner_->PostTask( |
420 base::Bind(&NotificationCallback, | 418 FROM_HERE, |
421 make_scoped_refptr(owner_), | 419 base::Bind(&NotificationCallback, base::RetainedRef(owner_), |
422 JobEventDetails::PAGE_DONE, | 420 JobEventDetails::PAGE_DONE, base::RetainedRef(document_), |
423 document_, | 421 base::RetainedRef(page))); |
424 make_scoped_refptr(page))); | |
425 } | 422 } |
426 | 423 |
427 void PrintJobWorker::OnFailure() { | 424 void PrintJobWorker::OnFailure() { |
428 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 425 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
429 | 426 |
430 // We may loose our last reference by broadcasting the FAILED event. | 427 // We may loose our last reference by broadcasting the FAILED event. |
431 scoped_refptr<PrintJobWorkerOwner> handle(owner_); | 428 scoped_refptr<PrintJobWorkerOwner> handle(owner_); |
432 | 429 |
433 owner_->PostTask(FROM_HERE, | 430 owner_->PostTask( |
434 base::Bind(&NotificationCallback, | 431 FROM_HERE, |
435 make_scoped_refptr(owner_), | 432 base::Bind(&NotificationCallback, base::RetainedRef(owner_), |
436 JobEventDetails::FAILED, | 433 JobEventDetails::FAILED, base::RetainedRef(document_), |
437 document_, | 434 base::RetainedRef<PrintedPage>(nullptr))); |
Nico
2016/03/18 21:01:01
same question
| |
438 scoped_refptr<PrintedPage>())); | |
439 Cancel(); | 435 Cancel(); |
440 | 436 |
441 // Makes sure the variables are reinitialized. | 437 // Makes sure the variables are reinitialized. |
442 document_ = NULL; | 438 document_ = NULL; |
443 page_number_ = PageNumber::npos(); | 439 page_number_ = PageNumber::npos(); |
444 } | 440 } |
445 | 441 |
446 } // namespace printing | 442 } // namespace printing |
OLD | NEW |