Chromium Code Reviews| Index: chrome/browser/chromeos/printing/cups_print_job_manager_impl.cc |
| diff --git a/chrome/browser/chromeos/printing/cups_print_job_manager_impl.cc b/chrome/browser/chromeos/printing/cups_print_job_manager_impl.cc |
| index d03c07c5d950f5c7565c337f9aa3bab9a8d1487b..e570b0c75c9adc4bc49771f7519d18230f2fa2ef 100644 |
| --- a/chrome/browser/chromeos/printing/cups_print_job_manager_impl.cc |
| +++ b/chrome/browser/chromeos/printing/cups_print_job_manager_impl.cc |
| @@ -14,10 +14,12 @@ |
| #include "base/bind.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/metrics/histogram_macros.h" |
| +#include "base/sequenced_task_runner.h" |
| #include "base/stl_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| -#include "base/threading/sequenced_task_runner_handle.h" |
| -#include "base/threading/sequenced_worker_pool.h" |
| +#include "base/task_runner_util.h" |
| +#include "base/task_scheduler/post_task.h" |
| +#include "base/threading/thread_task_runner_handle.h" |
| #include "chrome/browser/chrome_notification_types.h" |
| #include "chrome/browser/chromeos/printing/cups_print_job.h" |
| #include "chrome/browser/chromeos/printing/printers_manager.h" |
| @@ -25,7 +27,6 @@ |
| #include "chrome/browser/printing/print_job.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "content/public/browser/browser_context.h" |
| -#include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/notification_registrar.h" |
| #include "content/public/browser/notification_service.h" |
| #include "printing/backend/cups_connection.h" |
| @@ -104,6 +105,7 @@ chromeos::CupsPrintJob::State ConvertState(printing::CupsJob::JobState state) { |
| chromeos::QueryResult QueryCups(::printing::CupsConnection* connection, |
| const std::vector<std::string>& printer_ids) { |
| + base::ThreadRestrictions::AssertIOAllowed(); |
| chromeos::QueryResult result; |
| result.success = connection->GetJobs(printer_ids, &result.queues); |
| return result; |
| @@ -182,9 +184,16 @@ QueryResult::QueryResult(const QueryResult& other) = default; |
| QueryResult::~QueryResult() = default; |
| -CupsPrintJobManagerImpl::CupsPrintJobManagerImpl(Profile* profile) |
| +CupsPrintJobManagerImpl::CupsPrintJobManagerImpl( |
| + Profile* profile, |
| + scoped_refptr<base::SingleThreadTaskRunner> browser_thread_runner) |
| : CupsPrintJobManager(profile), |
| cups_connection_(GURL(), HTTP_ENCRYPT_NEVER, false), |
| + browser_thread_runner_(browser_thread_runner), |
|
gab
2017/06/20 21:04:49
std::move
skau
2017/06/24 01:03:44
It's not injected anymore.
|
| + query_runner_(base::CreateSequencedTaskRunnerWithTraits( |
| + base::TaskTraits(base::TaskPriority::BACKGROUND, |
| + base::MayBlock(), |
| + base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN))), |
| weak_ptr_factory_(this) { |
| registrar_.Add(this, chrome::NOTIFICATION_PRINT_JOB_EVENT, |
| content::NotificationService::AllSources()); |
| @@ -192,9 +201,8 @@ CupsPrintJobManagerImpl::CupsPrintJobManagerImpl(Profile* profile) |
| CupsPrintJobManagerImpl::~CupsPrintJobManagerImpl() {} |
| -// Must be run from the UI thread. |
| void CupsPrintJobManagerImpl::CancelPrintJob(CupsPrintJob* job) { |
| - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + DCHECK(browser_thread_runner_->RunsTasksInCurrentSequence()); |
| // Copy job_id and printer_id. |job| is about to be freed. |
| const int job_id = job->job_id(); |
| @@ -205,8 +213,9 @@ void CupsPrintJobManagerImpl::CancelPrintJob(CupsPrintJob* job) { |
| // Be sure to copy out all relevant fields. |job| may be destroyed after we |
| // exit this scope. |
| - content::BrowserThread::GetBlockingPool()->PostTask( |
| + base::PostTaskWithTraits( |
| FROM_HERE, |
| + base::TaskTraits(base::TaskPriority::USER_VISIBLE, base::MayBlock()), |
| base::Bind(&CupsPrintJobManagerImpl::CancelJobImpl, |
| weak_ptr_factory_.GetWeakPtr(), printer_id, job_id)); |
| } |
| @@ -244,6 +253,8 @@ bool CupsPrintJobManagerImpl::CreatePrintJob(const std::string& printer_name, |
| const std::string& title, |
| int job_id, |
| int total_page_number) { |
| + DCHECK(browser_thread_runner_->RunsTasksInCurrentSequence()); |
| + |
| auto printer = |
| PrintersManagerFactory::GetForBrowserContext(profile_)->GetPrinter( |
| printer_name); |
| @@ -284,7 +295,7 @@ void CupsPrintJobManagerImpl::ScheduleQuery(const base::TimeDelta& delay) { |
| if (!in_query_) { |
| in_query_ = true; |
| - base::SequencedTaskRunnerHandle::Get()->PostDelayedTask( |
| + browser_thread_runner_->PostDelayedTask( |
| FROM_HERE, |
| base::Bind(&CupsPrintJobManagerImpl::PostQuery, |
| weak_ptr_factory_.GetWeakPtr()), |
| @@ -293,6 +304,8 @@ void CupsPrintJobManagerImpl::ScheduleQuery(const base::TimeDelta& delay) { |
| } |
| void CupsPrintJobManagerImpl::PostQuery() { |
| + DCHECK(browser_thread_runner_->RunsTasksInCurrentSequence()); |
| + |
| // The set of active printers is expected to be small. |
| std::set<std::string> printer_ids; |
| for (const auto& entry : jobs_) { |
| @@ -300,8 +313,8 @@ void CupsPrintJobManagerImpl::PostQuery() { |
| } |
| std::vector<std::string> ids{printer_ids.begin(), printer_ids.end()}; |
| - content::BrowserThread::PostTaskAndReplyWithResult( |
| - content::BrowserThread::FILE_USER_BLOCKING, FROM_HERE, |
| + base::PostTaskAndReplyWithResult( |
| + query_runner_.get(), FROM_HERE, |
| base::Bind(&QueryCups, &cups_connection_, ids), |
| base::Bind(&CupsPrintJobManagerImpl::UpdateJobs, |
| weak_ptr_factory_.GetWeakPtr())); |
| @@ -347,6 +360,8 @@ bool CupsPrintJobManagerImpl::UpdatePrintJob( |
| // could be in |jobs| but those are ignored as we will not emit updates for them |
| // after they are completed. |
| void CupsPrintJobManagerImpl::UpdateJobs(const QueryResult& result) { |
| + DCHECK(browser_thread_runner_->RunsTasksInCurrentSequence()); |
| + |
| const std::vector<::printing::QueueStatus>& queues = result.queues; |
| // Query has completed. Allow more queries. |
| @@ -415,6 +430,8 @@ void CupsPrintJobManagerImpl::UpdateJobs(const QueryResult& result) { |
| } |
| void CupsPrintJobManagerImpl::PurgeJobs() { |
| + DCHECK(browser_thread_runner_->RunsTasksInCurrentSequence()); |
| + |
| for (const auto& entry : jobs_) { |
| // Declare all lost jobs errors. |
| RecordJobResult(LOST); |
| @@ -428,6 +445,8 @@ void CupsPrintJobManagerImpl::PurgeJobs() { |
| void CupsPrintJobManagerImpl::CancelJobImpl(const std::string& printer_id, |
| const int job_id) { |
| + base::ThreadRestrictions::AssertIOAllowed(); |
| + |
| std::unique_ptr<::printing::CupsPrinter> printer = |
| cups_connection_.GetPrinter(printer_id); |
| if (!printer) { |
| @@ -442,6 +461,8 @@ void CupsPrintJobManagerImpl::CancelJobImpl(const std::string& printer_id, |
| } |
| void CupsPrintJobManagerImpl::NotifyJobStateUpdate(CupsPrintJob* job) { |
| + DCHECK(browser_thread_runner_->RunsTasksInCurrentSequence()); |
| + |
| switch (job->state()) { |
| case State::STATE_NONE: |
| // State does not require notification. |
| @@ -475,7 +496,8 @@ void CupsPrintJobManagerImpl::NotifyJobStateUpdate(CupsPrintJob* job) { |
| // static |
| CupsPrintJobManager* CupsPrintJobManager::CreateInstance(Profile* profile) { |
| - return new CupsPrintJobManagerImpl(profile); |
| + return new CupsPrintJobManagerImpl(profile, |
| + base::ThreadTaskRunnerHandle::Get()); |
| } |
| } // namespace chromeos |