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 <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_); | 83 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_); |
84 return rfh ? content::WebContents::FromRenderFrameHost(rfh) : nullptr; | 84 return rfh ? content::WebContents::FromRenderFrameHost(rfh) : nullptr; |
85 } | 85 } |
86 | 86 |
87 std::string PrintingContextDelegate::GetAppLocale() { | 87 std::string PrintingContextDelegate::GetAppLocale() { |
88 return g_browser_process->GetApplicationLocale(); | 88 return g_browser_process->GetApplicationLocale(); |
89 } | 89 } |
90 | 90 |
91 void NotificationCallback(PrintJobWorkerOwner* print_job, | 91 void NotificationCallback(PrintJobWorkerOwner* print_job, |
92 JobEventDetails::Type detail_type, | 92 JobEventDetails::Type detail_type, |
| 93 int job_id, |
93 PrintedDocument* document, | 94 PrintedDocument* document, |
94 PrintedPage* page) { | 95 PrintedPage* page) { |
95 JobEventDetails* details = new JobEventDetails(detail_type, document, page); | 96 JobEventDetails* details = |
| 97 new JobEventDetails(detail_type, job_id, document, page); |
96 content::NotificationService::current()->Notify( | 98 content::NotificationService::current()->Notify( |
97 chrome::NOTIFICATION_PRINT_JOB_EVENT, | 99 chrome::NOTIFICATION_PRINT_JOB_EVENT, |
98 // We know that is is a PrintJob object in this circumstance. | 100 // We know that is is a PrintJob object in this circumstance. |
99 content::Source<PrintJob>(static_cast<PrintJob*>(print_job)), | 101 content::Source<PrintJob>(static_cast<PrintJob*>(print_job)), |
100 content::Details<JobEventDetails>(details)); | 102 content::Details<JobEventDetails>(details)); |
101 } | 103 } |
102 | 104 |
103 void PostOnOwnerThread(const scoped_refptr<PrintJobWorkerOwner>& owner, | 105 void PostOnOwnerThread(const scoped_refptr<PrintJobWorkerOwner>& owner, |
104 const PrintingContext::PrintSettingsCallback& callback, | 106 const PrintingContext::PrintSettingsCallback& callback, |
105 PrintingContext::Result result) { | 107 PrintingContext::Result result) { |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 bool result = thread_.Start(); | 365 bool result = thread_.Start(); |
364 task_runner_ = thread_.task_runner(); | 366 task_runner_ = thread_.task_runner(); |
365 return result; | 367 return result; |
366 } | 368 } |
367 | 369 |
368 void PrintJobWorker::OnDocumentDone() { | 370 void PrintJobWorker::OnDocumentDone() { |
369 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 371 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
370 DCHECK_EQ(page_number_, PageNumber::npos()); | 372 DCHECK_EQ(page_number_, PageNumber::npos()); |
371 DCHECK(document_.get()); | 373 DCHECK(document_.get()); |
372 | 374 |
| 375 int job_id = printing_context_->job_id(); |
373 if (printing_context_->DocumentDone() != PrintingContext::OK) { | 376 if (printing_context_->DocumentDone() != PrintingContext::OK) { |
374 OnFailure(); | 377 OnFailure(); |
375 return; | 378 return; |
376 } | 379 } |
377 | 380 |
378 owner_->PostTask(FROM_HERE, | 381 owner_->PostTask(FROM_HERE, |
379 base::Bind(&NotificationCallback, base::RetainedRef(owner_), | 382 base::Bind(&NotificationCallback, base::RetainedRef(owner_), |
380 JobEventDetails::DOC_DONE, | 383 JobEventDetails::DOC_DONE, job_id, |
381 base::RetainedRef(document_), nullptr)); | 384 base::RetainedRef(document_), nullptr)); |
382 | 385 |
383 // Makes sure the variables are reinitialized. | 386 // Makes sure the variables are reinitialized. |
384 document_ = NULL; | 387 document_ = NULL; |
385 } | 388 } |
386 | 389 |
387 void PrintJobWorker::SpoolPage(PrintedPage* page) { | 390 void PrintJobWorker::SpoolPage(PrintedPage* page) { |
388 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 391 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
389 DCHECK_NE(page_number_, PageNumber::npos()); | 392 DCHECK_NE(page_number_, PageNumber::npos()); |
390 | 393 |
391 // Signal everyone that the page is about to be printed. | 394 // Signal everyone that the page is about to be printed. |
392 owner_->PostTask( | 395 owner_->PostTask( |
393 FROM_HERE, | 396 FROM_HERE, |
394 base::Bind(&NotificationCallback, base::RetainedRef(owner_), | 397 base::Bind(&NotificationCallback, base::RetainedRef(owner_), |
395 JobEventDetails::NEW_PAGE, base::RetainedRef(document_), | 398 JobEventDetails::NEW_PAGE, printing_context_->job_id(), |
396 base::RetainedRef(page))); | 399 base::RetainedRef(document_), base::RetainedRef(page))); |
397 | 400 |
398 // Preprocess. | 401 // Preprocess. |
399 if (printing_context_->NewPage() != PrintingContext::OK) { | 402 if (printing_context_->NewPage() != PrintingContext::OK) { |
400 OnFailure(); | 403 OnFailure(); |
401 return; | 404 return; |
402 } | 405 } |
403 | 406 |
404 // Actual printing. | 407 // Actual printing. |
405 #if defined(OS_WIN) || defined(OS_MACOSX) | 408 #if defined(OS_WIN) || defined(OS_MACOSX) |
406 document_->RenderPrintedPage(*page, printing_context_->context()); | 409 document_->RenderPrintedPage(*page, printing_context_->context()); |
407 #elif defined(OS_POSIX) | 410 #elif defined(OS_POSIX) |
408 document_->RenderPrintedPage(*page, printing_context_.get()); | 411 document_->RenderPrintedPage(*page, printing_context_.get()); |
409 #endif | 412 #endif |
410 | 413 |
411 // Postprocess. | 414 // Postprocess. |
412 if (printing_context_->PageDone() != PrintingContext::OK) { | 415 if (printing_context_->PageDone() != PrintingContext::OK) { |
413 OnFailure(); | 416 OnFailure(); |
414 return; | 417 return; |
415 } | 418 } |
416 | 419 |
417 // Signal everyone that the page is printed. | 420 // Signal everyone that the page is printed. |
418 owner_->PostTask( | 421 owner_->PostTask( |
419 FROM_HERE, | 422 FROM_HERE, |
420 base::Bind(&NotificationCallback, base::RetainedRef(owner_), | 423 base::Bind(&NotificationCallback, base::RetainedRef(owner_), |
421 JobEventDetails::PAGE_DONE, base::RetainedRef(document_), | 424 JobEventDetails::PAGE_DONE, printing_context_->job_id(), |
422 base::RetainedRef(page))); | 425 base::RetainedRef(document_), base::RetainedRef(page))); |
423 } | 426 } |
424 | 427 |
425 void PrintJobWorker::OnFailure() { | 428 void PrintJobWorker::OnFailure() { |
426 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 429 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
427 | 430 |
428 // We may loose our last reference by broadcasting the FAILED event. | 431 // We may loose our last reference by broadcasting the FAILED event. |
429 scoped_refptr<PrintJobWorkerOwner> handle(owner_); | 432 scoped_refptr<PrintJobWorkerOwner> handle(owner_); |
430 | 433 |
431 owner_->PostTask(FROM_HERE, | 434 owner_->PostTask(FROM_HERE, |
432 base::Bind(&NotificationCallback, base::RetainedRef(owner_), | 435 base::Bind(&NotificationCallback, base::RetainedRef(owner_), |
433 JobEventDetails::FAILED, | 436 JobEventDetails::FAILED, 0, |
434 base::RetainedRef(document_), nullptr)); | 437 base::RetainedRef(document_), nullptr)); |
435 Cancel(); | 438 Cancel(); |
436 | 439 |
437 // Makes sure the variables are reinitialized. | 440 // Makes sure the variables are reinitialized. |
438 document_ = NULL; | 441 document_ = NULL; |
439 page_number_ = PageNumber::npos(); | 442 page_number_ = PageNumber::npos(); |
440 } | 443 } |
441 | 444 |
442 } // namespace printing | 445 } // namespace printing |
OLD | NEW |