Introduce TaskRunner::RunsTasksInCurrentSequence()

https://codereview.chromium.org/2823103003
This commit is contained in:
Aleksei Kuzmin 2017-08-08 00:14:35 +03:00 committed by Cheng Zhao
parent f2bcdab037
commit 11fa935359
9 changed files with 26 additions and 26 deletions

View file

@ -31,7 +31,7 @@ bool UvTaskRunner::PostDelayedTask(const tracked_objects::Location& from_here,
return true; return true;
} }
bool UvTaskRunner::RunsTasksOnCurrentThread() const { bool UvTaskRunner::RunsTasksInCurrentSequence() const {
return true; return true;
} }

View file

@ -23,7 +23,7 @@ class UvTaskRunner : public base::SingleThreadTaskRunner {
bool PostDelayedTask(const tracked_objects::Location& from_here, bool PostDelayedTask(const tracked_objects::Location& from_here,
base::OnceClosure task, base::OnceClosure task,
base::TimeDelta delay) override; base::TimeDelta delay) override;
bool RunsTasksOnCurrentThread() const override; bool RunsTasksInCurrentSequence() const override;
bool PostNonNestableDelayedTask( bool PostNonNestableDelayedTask(
const tracked_objects::Location& from_here, const tracked_objects::Location& from_here,
base::OnceClosure task, base::OnceClosure task,

View file

@ -35,12 +35,12 @@ bool BridgeTaskRunner::PostDelayedTask(
from_here, std::move(task), delay); from_here, std::move(task), delay);
} }
bool BridgeTaskRunner::RunsTasksOnCurrentThread() const { bool BridgeTaskRunner::RunsTasksInCurrentSequence() const {
auto message_loop = base::MessageLoop::current(); auto message_loop = base::MessageLoop::current();
if (!message_loop) if (!message_loop)
return true; return true;
return message_loop->task_runner()->RunsTasksOnCurrentThread(); return message_loop->task_runner()->RunsTasksInCurrentSequence();
} }
bool BridgeTaskRunner::PostNonNestableDelayedTask( bool BridgeTaskRunner::PostNonNestableDelayedTask(

View file

@ -27,7 +27,7 @@ class BridgeTaskRunner : public base::SingleThreadTaskRunner {
bool PostDelayedTask(const tracked_objects::Location& from_here, bool PostDelayedTask(const tracked_objects::Location& from_here,
base::OnceClosure task, base::OnceClosure task,
base::TimeDelta delay) override; base::TimeDelta delay) override;
bool RunsTasksOnCurrentThread() const override; bool RunsTasksInCurrentSequence() const override;
bool PostNonNestableDelayedTask( bool PostNonNestableDelayedTask(
const tracked_objects::Location& from_here, const tracked_objects::Location& from_here,
base::OnceClosure task, base::OnceClosure task,

View file

@ -62,7 +62,7 @@ PrintJob::~PrintJob() {
DCHECK(!is_job_pending_); DCHECK(!is_job_pending_);
DCHECK(!is_canceling_); DCHECK(!is_canceling_);
DCHECK(!worker_ || !worker_->IsRunning()); DCHECK(!worker_ || !worker_->IsRunning());
DCHECK(RunsTasksOnCurrentThread()); DCHECK(RunsTasksInCurrentSequence());
} }
void PrintJob::Initialize(PrintJobWorkerOwner* job, void PrintJob::Initialize(PrintJobWorkerOwner* job,
@ -93,7 +93,7 @@ void PrintJob::Initialize(PrintJobWorkerOwner* job,
void PrintJob::Observe(int type, void PrintJob::Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
DCHECK(RunsTasksOnCurrentThread()); DCHECK(RunsTasksInCurrentSequence());
DCHECK_EQ(chrome::NOTIFICATION_PRINT_JOB_EVENT, type); DCHECK_EQ(chrome::NOTIFICATION_PRINT_JOB_EVENT, type);
OnNotifyPrintJobEvent(*content::Details<JobEventDetails>(details).ptr()); OnNotifyPrintJobEvent(*content::Details<JobEventDetails>(details).ptr());
@ -122,7 +122,7 @@ int PrintJob::cookie() const {
} }
void PrintJob::StartPrinting() { void PrintJob::StartPrinting() {
DCHECK(RunsTasksOnCurrentThread()); DCHECK(RunsTasksInCurrentSequence());
if (!worker_->IsRunning() || is_job_pending_) { if (!worker_->IsRunning() || is_job_pending_) {
NOTREACHED(); NOTREACHED();
return; return;
@ -147,7 +147,7 @@ void PrintJob::StartPrinting() {
} }
void PrintJob::Stop() { void PrintJob::Stop() {
DCHECK(RunsTasksOnCurrentThread()); DCHECK(RunsTasksInCurrentSequence());
if (quit_factory_.HasWeakPtrs()) { if (quit_factory_.HasWeakPtrs()) {
// In case we're running a nested message loop to wait for a job to finish, // In case we're running a nested message loop to wait for a job to finish,
@ -176,7 +176,7 @@ void PrintJob::Cancel() {
// Be sure to live long enough. // Be sure to live long enough.
scoped_refptr<PrintJob> handle(this); scoped_refptr<PrintJob> handle(this);
DCHECK(RunsTasksOnCurrentThread()); DCHECK(RunsTasksInCurrentSequence());
if (worker_ && worker_->IsRunning()) { if (worker_ && worker_->IsRunning()) {
// Call this right now so it renders the context invalid. Do not use // Call this right now so it renders the context invalid. Do not use
// InvokeLater since it would take too much time. // InvokeLater since it would take too much time.
@ -419,7 +419,7 @@ void PrintJob::OnDocumentDone() {
} }
void PrintJob::ControlledWorkerShutdown() { void PrintJob::ControlledWorkerShutdown() {
DCHECK(RunsTasksOnCurrentThread()); DCHECK(RunsTasksInCurrentSequence());
// The deadlock this code works around is specific to window messaging on // The deadlock this code works around is specific to window messaging on
// Windows, so we aren't likely to need it on any other platforms. // Windows, so we aren't likely to need it on any other platforms.

View file

@ -198,7 +198,7 @@ PrintJobWorker::PrintJobWorker(int render_process_id,
PrintJobWorkerOwner* owner) PrintJobWorkerOwner* owner)
: owner_(owner), thread_("Printing_Worker"), weak_factory_(this) { : owner_(owner), thread_("Printing_Worker"), weak_factory_(this) {
// The object is created in the IO thread. // The object is created in the IO thread.
DCHECK(owner_->RunsTasksOnCurrentThread()); DCHECK(owner_->RunsTasksInCurrentSequence());
printing_context_delegate_ = base::MakeUnique<PrintingContextDelegate>( printing_context_delegate_ = base::MakeUnique<PrintingContextDelegate>(
render_process_id, render_frame_id); render_process_id, render_frame_id);
@ -209,7 +209,7 @@ PrintJobWorker::~PrintJobWorker() {
// The object is normally deleted in the UI thread, but when the user // The object is normally deleted in the UI thread, but when the user
// cancels printing or in the case of print preview, the worker is destroyed // cancels printing or in the case of print preview, the worker is destroyed
// on the I/O thread. // on the I/O thread.
DCHECK(owner_->RunsTasksOnCurrentThread()); DCHECK(owner_->RunsTasksInCurrentSequence());
Stop(); Stop();
} }
@ -225,7 +225,7 @@ void PrintJobWorker::GetSettings(bool ask_user_for_settings,
bool is_scripted, bool is_scripted,
bool is_modifiable, bool is_modifiable,
const base::string16& device_name) { const base::string16& device_name) {
DCHECK(task_runner_->RunsTasksOnCurrentThread()); DCHECK(task_runner_->RunsTasksInCurrentSequence());
DCHECK_EQ(page_number_, PageNumber::npos()); DCHECK_EQ(page_number_, PageNumber::npos());
// Recursive task processing is needed for the dialog in case it needs to be // Recursive task processing is needed for the dialog in case it needs to be
@ -266,7 +266,7 @@ void PrintJobWorker::GetSettings(bool ask_user_for_settings,
void PrintJobWorker::SetSettings( void PrintJobWorker::SetSettings(
std::unique_ptr<base::DictionaryValue> new_settings) { std::unique_ptr<base::DictionaryValue> new_settings) {
DCHECK(task_runner_->RunsTasksOnCurrentThread()); DCHECK(task_runner_->RunsTasksInCurrentSequence());
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, BrowserThread::UI,
@ -332,7 +332,7 @@ void PrintJobWorker::InitWithDeviceName(const base::string16& device_name) {
} }
void PrintJobWorker::StartPrinting(PrintedDocument* new_document) { void PrintJobWorker::StartPrinting(PrintedDocument* new_document) {
DCHECK(task_runner_->RunsTasksOnCurrentThread()); DCHECK(task_runner_->RunsTasksInCurrentSequence());
DCHECK_EQ(page_number_, PageNumber::npos()); DCHECK_EQ(page_number_, PageNumber::npos());
DCHECK_EQ(document_.get(), new_document); DCHECK_EQ(document_.get(), new_document);
DCHECK(document_.get()); DCHECK(document_.get());
@ -361,7 +361,7 @@ void PrintJobWorker::StartPrinting(PrintedDocument* new_document) {
} }
void PrintJobWorker::OnDocumentChanged(PrintedDocument* new_document) { void PrintJobWorker::OnDocumentChanged(PrintedDocument* new_document) {
DCHECK(task_runner_->RunsTasksOnCurrentThread()); DCHECK(task_runner_->RunsTasksInCurrentSequence());
DCHECK_EQ(page_number_, PageNumber::npos()); DCHECK_EQ(page_number_, PageNumber::npos());
if (page_number_ != PageNumber::npos()) if (page_number_ != PageNumber::npos())
@ -375,7 +375,7 @@ void PrintJobWorker::OnNewPage() {
return; return;
// message_loop() could return NULL when the print job is cancelled. // message_loop() could return NULL when the print job is cancelled.
DCHECK(task_runner_->RunsTasksOnCurrentThread()); DCHECK(task_runner_->RunsTasksInCurrentSequence());
if (page_number_ == PageNumber::npos()) { if (page_number_ == PageNumber::npos()) {
// Find first page to print. // Find first page to print.
@ -446,7 +446,7 @@ bool PrintJobWorker::Start() {
} }
void PrintJobWorker::OnDocumentDone() { void PrintJobWorker::OnDocumentDone() {
DCHECK(task_runner_->RunsTasksOnCurrentThread()); DCHECK(task_runner_->RunsTasksInCurrentSequence());
DCHECK_EQ(page_number_, PageNumber::npos()); DCHECK_EQ(page_number_, PageNumber::npos());
DCHECK(document_.get()); DCHECK(document_.get());
@ -465,7 +465,7 @@ void PrintJobWorker::OnDocumentDone() {
} }
void PrintJobWorker::SpoolPage(PrintedPage* page) { void PrintJobWorker::SpoolPage(PrintedPage* page) {
DCHECK(task_runner_->RunsTasksOnCurrentThread()); DCHECK(task_runner_->RunsTasksInCurrentSequence());
DCHECK_NE(page_number_, PageNumber::npos()); DCHECK_NE(page_number_, PageNumber::npos());
// Signal everyone that the page is about to be printed. // Signal everyone that the page is about to be printed.
@ -503,7 +503,7 @@ void PrintJobWorker::SpoolPage(PrintedPage* page) {
} }
void PrintJobWorker::OnFailure() { void PrintJobWorker::OnFailure() {
DCHECK(task_runner_->RunsTasksOnCurrentThread()); DCHECK(task_runner_->RunsTasksInCurrentSequence());
// We may loose our last reference by broadcasting the FAILED event. // We may loose our last reference by broadcasting the FAILED event.
scoped_refptr<PrintJobWorkerOwner> handle(owner_); scoped_refptr<PrintJobWorkerOwner> handle(owner_);

View file

@ -16,8 +16,8 @@ PrintJobWorkerOwner::PrintJobWorkerOwner()
PrintJobWorkerOwner::~PrintJobWorkerOwner() { PrintJobWorkerOwner::~PrintJobWorkerOwner() {
} }
bool PrintJobWorkerOwner::RunsTasksOnCurrentThread() const { bool PrintJobWorkerOwner::RunsTasksInCurrentSequence() const {
return task_runner_->RunsTasksOnCurrentThread(); return task_runner_->RunsTasksInCurrentSequence();
} }
bool PrintJobWorkerOwner::PostTask(const tracked_objects::Location& from_here, bool PrintJobWorkerOwner::PostTask(const tracked_objects::Location& from_here,

View file

@ -48,7 +48,7 @@ class PrintJobWorkerOwner
// Returns true if the current thread is a thread on which a task // Returns true if the current thread is a thread on which a task
// may be run, and false if no task will be run on the current // may be run, and false if no task will be run on the current
// thread. // thread.
bool RunsTasksOnCurrentThread() const; bool RunsTasksInCurrentSequence() const;
// Posts the given task to be run. // Posts the given task to be run.
bool PostTask(const tracked_objects::Location& from_here, bool PostTask(const tracked_objects::Location& from_here,

View file

@ -74,7 +74,7 @@ void PrinterQuery::GetSettings(GetSettingsAskParam ask_user_for_settings,
bool is_scripted, bool is_scripted,
bool is_modifiable, bool is_modifiable,
const base::Closure& callback) { const base::Closure& callback) {
DCHECK(RunsTasksOnCurrentThread()); DCHECK(RunsTasksInCurrentSequence());
DCHECK(!is_print_dialog_box_shown_ || !is_scripted); DCHECK(!is_print_dialog_box_shown_ || !is_scripted);
StartWorker(callback); StartWorker(callback);
@ -98,7 +98,7 @@ void PrinterQuery::GetSettings(
bool is_modifiable, bool is_modifiable,
const base::string16& device_name, const base::string16& device_name,
const base::Closure& callback) { const base::Closure& callback) {
DCHECK(RunsTasksOnCurrentThread()); DCHECK(RunsTasksInCurrentSequence());
DCHECK(!is_print_dialog_box_shown_); DCHECK(!is_print_dialog_box_shown_);
StartWorker(callback); StartWorker(callback);