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.h" | 5 #include "chrome/browser/printing/print_job.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/task_scheduler/post_task.h" |
17 #include "base/threading/sequenced_worker_pool.h" | 18 #include "base/threading/sequenced_worker_pool.h" |
18 #include "base/threading/thread_restrictions.h" | 19 #include "base/threading/thread_restrictions.h" |
19 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
20 #include "base/threading/worker_pool.h" | |
21 #include "build/build_config.h" | 21 #include "build/build_config.h" |
22 #include "chrome/browser/chrome_notification_types.h" | 22 #include "chrome/browser/chrome_notification_types.h" |
23 #include "chrome/browser/printing/print_job_worker.h" | 23 #include "chrome/browser/printing/print_job_worker.h" |
24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
26 #include "printing/printed_document.h" | 26 #include "printing/printed_document.h" |
27 #include "printing/printed_page.h" | 27 #include "printing/printed_page.h" |
28 | 28 |
29 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
30 #include "chrome/browser/printing/pdf_to_emf_converter.h" | 30 #include "chrome/browser/printing/pdf_to_emf_converter.h" |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 // Delay shutdown until the worker terminates. We want this code path | 437 // Delay shutdown until the worker terminates. We want this code path |
438 // to wait on the thread to quit before continuing. | 438 // to wait on the thread to quit before continuing. |
439 if (worker_->IsRunning()) { | 439 if (worker_->IsRunning()) { |
440 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 440 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
441 FROM_HERE, base::Bind(&PrintJob::ControlledWorkerShutdown, this), | 441 FROM_HERE, base::Bind(&PrintJob::ControlledWorkerShutdown, this), |
442 base::TimeDelta::FromMilliseconds(100)); | 442 base::TimeDelta::FromMilliseconds(100)); |
443 return; | 443 return; |
444 } | 444 } |
445 #endif | 445 #endif |
446 | 446 |
447 | |
448 // Now make sure the thread object is cleaned up. Do this on a worker | 447 // Now make sure the thread object is cleaned up. Do this on a worker |
449 // thread because it may block. | 448 // thread because it may block. |
450 base::WorkerPool::PostTaskAndReply( | 449 // TODO(fdoray): Remove MayBlock() once base::Thread::Stop() passes |
| 450 // base::ThreadRestrictions::AssertWaitAllowed(). |
| 451 base::PostTaskWithTraitsAndReply( |
451 FROM_HERE, | 452 FROM_HERE, |
| 453 base::TaskTraits() |
| 454 .MayBlock() |
| 455 .WithBaseSyncPrimitives() |
| 456 .WithPriority(base::TaskPriority::BACKGROUND) |
| 457 .WithShutdownBehavior( |
| 458 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), |
452 base::BindOnce(&PrintJobWorker::Stop, base::Unretained(worker_.get())), | 459 base::BindOnce(&PrintJobWorker::Stop, base::Unretained(worker_.get())), |
453 base::BindOnce(&PrintJob::HoldUntilStopIsCalled, this), false); | 460 base::BindOnce(&PrintJob::HoldUntilStopIsCalled, this)); |
454 | 461 |
455 is_job_pending_ = false; | 462 is_job_pending_ = false; |
456 registrar_.RemoveAll(); | 463 registrar_.RemoveAll(); |
457 UpdatePrintedDocument(nullptr); | 464 UpdatePrintedDocument(nullptr); |
458 } | 465 } |
459 | 466 |
460 void PrintJob::HoldUntilStopIsCalled() { | 467 void PrintJob::HoldUntilStopIsCalled() { |
461 } | 468 } |
462 | 469 |
463 void PrintJob::Quit() { | 470 void PrintJob::Quit() { |
464 base::MessageLoop::current()->QuitWhenIdle(); | 471 base::MessageLoop::current()->QuitWhenIdle(); |
465 } | 472 } |
466 | 473 |
467 // Takes settings_ ownership and will be deleted in the receiving thread. | 474 // Takes settings_ ownership and will be deleted in the receiving thread. |
468 JobEventDetails::JobEventDetails(Type type, | 475 JobEventDetails::JobEventDetails(Type type, |
469 int job_id, | 476 int job_id, |
470 PrintedDocument* document, | 477 PrintedDocument* document, |
471 PrintedPage* page) | 478 PrintedPage* page) |
472 : document_(document), page_(page), type_(type), job_id_(job_id) {} | 479 : document_(document), page_(page), type_(type), job_id_(job_id) {} |
473 | 480 |
474 JobEventDetails::~JobEventDetails() { | 481 JobEventDetails::~JobEventDetails() { |
475 } | 482 } |
476 | 483 |
477 PrintedDocument* JobEventDetails::document() const { return document_.get(); } | 484 PrintedDocument* JobEventDetails::document() const { return document_.get(); } |
478 | 485 |
479 PrintedPage* JobEventDetails::page() const { return page_.get(); } | 486 PrintedPage* JobEventDetails::page() const { return page_.get(); } |
480 | 487 |
481 } // namespace printing | 488 } // namespace printing |
OLD | NEW |