| 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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(FROM_HERE, |
| 377 base::Bind(&NotificationCallback, | 377 base::Bind(&NotificationCallback, base::RetainedRef(owner_), |
| 378 make_scoped_refptr(owner_), | |
| 379 JobEventDetails::DOC_DONE, | 378 JobEventDetails::DOC_DONE, |
| 380 document_, | 379 base::RetainedRef(document_), nullptr)); |
| 381 scoped_refptr<PrintedPage>())); | |
| 382 | 380 |
| 383 // Makes sure the variables are reinitialized. | 381 // Makes sure the variables are reinitialized. |
| 384 document_ = NULL; | 382 document_ = NULL; |
| 385 } | 383 } |
| 386 | 384 |
| 387 void PrintJobWorker::SpoolPage(PrintedPage* page) { | 385 void PrintJobWorker::SpoolPage(PrintedPage* page) { |
| 388 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 386 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 389 DCHECK_NE(page_number_, PageNumber::npos()); | 387 DCHECK_NE(page_number_, PageNumber::npos()); |
| 390 | 388 |
| 391 // Signal everyone that the page is about to be printed. | 389 // Signal everyone that the page is about to be printed. |
| 392 owner_->PostTask(FROM_HERE, | 390 owner_->PostTask( |
| 393 base::Bind(&NotificationCallback, | 391 FROM_HERE, |
| 394 make_scoped_refptr(owner_), | 392 base::Bind(&NotificationCallback, base::RetainedRef(owner_), |
| 395 JobEventDetails::NEW_PAGE, | 393 JobEventDetails::NEW_PAGE, base::RetainedRef(document_), |
| 396 document_, | 394 base::RetainedRef(page))); |
| 397 make_scoped_refptr(page))); | |
| 398 | 395 |
| 399 // Preprocess. | 396 // Preprocess. |
| 400 if (printing_context_->NewPage() != PrintingContext::OK) { | 397 if (printing_context_->NewPage() != PrintingContext::OK) { |
| 401 OnFailure(); | 398 OnFailure(); |
| 402 return; | 399 return; |
| 403 } | 400 } |
| 404 | 401 |
| 405 // Actual printing. | 402 // Actual printing. |
| 406 #if defined(OS_WIN) || defined(OS_MACOSX) | 403 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 407 document_->RenderPrintedPage(*page, printing_context_->context()); | 404 document_->RenderPrintedPage(*page, printing_context_->context()); |
| 408 #elif defined(OS_POSIX) | 405 #elif defined(OS_POSIX) |
| 409 document_->RenderPrintedPage(*page, printing_context_.get()); | 406 document_->RenderPrintedPage(*page, printing_context_.get()); |
| 410 #endif | 407 #endif |
| 411 | 408 |
| 412 // Postprocess. | 409 // Postprocess. |
| 413 if (printing_context_->PageDone() != PrintingContext::OK) { | 410 if (printing_context_->PageDone() != PrintingContext::OK) { |
| 414 OnFailure(); | 411 OnFailure(); |
| 415 return; | 412 return; |
| 416 } | 413 } |
| 417 | 414 |
| 418 // Signal everyone that the page is printed. | 415 // Signal everyone that the page is printed. |
| 419 owner_->PostTask(FROM_HERE, | 416 owner_->PostTask( |
| 420 base::Bind(&NotificationCallback, | 417 FROM_HERE, |
| 421 make_scoped_refptr(owner_), | 418 base::Bind(&NotificationCallback, base::RetainedRef(owner_), |
| 422 JobEventDetails::PAGE_DONE, | 419 JobEventDetails::PAGE_DONE, base::RetainedRef(document_), |
| 423 document_, | 420 base::RetainedRef(page))); |
| 424 make_scoped_refptr(page))); | |
| 425 } | 421 } |
| 426 | 422 |
| 427 void PrintJobWorker::OnFailure() { | 423 void PrintJobWorker::OnFailure() { |
| 428 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 424 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 429 | 425 |
| 430 // We may loose our last reference by broadcasting the FAILED event. | 426 // We may loose our last reference by broadcasting the FAILED event. |
| 431 scoped_refptr<PrintJobWorkerOwner> handle(owner_); | 427 scoped_refptr<PrintJobWorkerOwner> handle(owner_); |
| 432 | 428 |
| 433 owner_->PostTask(FROM_HERE, | 429 owner_->PostTask(FROM_HERE, |
| 434 base::Bind(&NotificationCallback, | 430 base::Bind(&NotificationCallback, base::RetainedRef(owner_), |
| 435 make_scoped_refptr(owner_), | |
| 436 JobEventDetails::FAILED, | 431 JobEventDetails::FAILED, |
| 437 document_, | 432 base::RetainedRef(document_), nullptr)); |
| 438 scoped_refptr<PrintedPage>())); | |
| 439 Cancel(); | 433 Cancel(); |
| 440 | 434 |
| 441 // Makes sure the variables are reinitialized. | 435 // Makes sure the variables are reinitialized. |
| 442 document_ = NULL; | 436 document_ = NULL; |
| 443 page_number_ = PageNumber::npos(); | 437 page_number_ = PageNumber::npos(); |
| 444 } | 438 } |
| 445 | 439 |
| 446 } // namespace printing | 440 } // namespace printing |
| OLD | NEW |