зеркало из https://github.com/electron/electron.git
Introduce TaskRunner::RunsTasksInCurrentSequence()
https://codereview.chromium.org/2823103003
This commit is contained in:
Родитель
f2bcdab037
Коммит
11fa935359
|
@ -31,7 +31,7 @@ bool UvTaskRunner::PostDelayedTask(const tracked_objects::Location& from_here,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool UvTaskRunner::RunsTasksOnCurrentThread() const {
|
||||
bool UvTaskRunner::RunsTasksInCurrentSequence() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ class UvTaskRunner : public base::SingleThreadTaskRunner {
|
|||
bool PostDelayedTask(const tracked_objects::Location& from_here,
|
||||
base::OnceClosure task,
|
||||
base::TimeDelta delay) override;
|
||||
bool RunsTasksOnCurrentThread() const override;
|
||||
bool RunsTasksInCurrentSequence() const override;
|
||||
bool PostNonNestableDelayedTask(
|
||||
const tracked_objects::Location& from_here,
|
||||
base::OnceClosure task,
|
||||
|
|
|
@ -35,12 +35,12 @@ bool BridgeTaskRunner::PostDelayedTask(
|
|||
from_here, std::move(task), delay);
|
||||
}
|
||||
|
||||
bool BridgeTaskRunner::RunsTasksOnCurrentThread() const {
|
||||
bool BridgeTaskRunner::RunsTasksInCurrentSequence() const {
|
||||
auto message_loop = base::MessageLoop::current();
|
||||
if (!message_loop)
|
||||
return true;
|
||||
|
||||
return message_loop->task_runner()->RunsTasksOnCurrentThread();
|
||||
return message_loop->task_runner()->RunsTasksInCurrentSequence();
|
||||
}
|
||||
|
||||
bool BridgeTaskRunner::PostNonNestableDelayedTask(
|
||||
|
|
|
@ -27,7 +27,7 @@ class BridgeTaskRunner : public base::SingleThreadTaskRunner {
|
|||
bool PostDelayedTask(const tracked_objects::Location& from_here,
|
||||
base::OnceClosure task,
|
||||
base::TimeDelta delay) override;
|
||||
bool RunsTasksOnCurrentThread() const override;
|
||||
bool RunsTasksInCurrentSequence() const override;
|
||||
bool PostNonNestableDelayedTask(
|
||||
const tracked_objects::Location& from_here,
|
||||
base::OnceClosure task,
|
||||
|
|
|
@ -62,7 +62,7 @@ PrintJob::~PrintJob() {
|
|||
DCHECK(!is_job_pending_);
|
||||
DCHECK(!is_canceling_);
|
||||
DCHECK(!worker_ || !worker_->IsRunning());
|
||||
DCHECK(RunsTasksOnCurrentThread());
|
||||
DCHECK(RunsTasksInCurrentSequence());
|
||||
}
|
||||
|
||||
void PrintJob::Initialize(PrintJobWorkerOwner* job,
|
||||
|
@ -93,7 +93,7 @@ void PrintJob::Initialize(PrintJobWorkerOwner* job,
|
|||
void PrintJob::Observe(int type,
|
||||
const content::NotificationSource& source,
|
||||
const content::NotificationDetails& details) {
|
||||
DCHECK(RunsTasksOnCurrentThread());
|
||||
DCHECK(RunsTasksInCurrentSequence());
|
||||
DCHECK_EQ(chrome::NOTIFICATION_PRINT_JOB_EVENT, type);
|
||||
|
||||
OnNotifyPrintJobEvent(*content::Details<JobEventDetails>(details).ptr());
|
||||
|
@ -122,7 +122,7 @@ int PrintJob::cookie() const {
|
|||
}
|
||||
|
||||
void PrintJob::StartPrinting() {
|
||||
DCHECK(RunsTasksOnCurrentThread());
|
||||
DCHECK(RunsTasksInCurrentSequence());
|
||||
if (!worker_->IsRunning() || is_job_pending_) {
|
||||
NOTREACHED();
|
||||
return;
|
||||
|
@ -147,7 +147,7 @@ void PrintJob::StartPrinting() {
|
|||
}
|
||||
|
||||
void PrintJob::Stop() {
|
||||
DCHECK(RunsTasksOnCurrentThread());
|
||||
DCHECK(RunsTasksInCurrentSequence());
|
||||
|
||||
if (quit_factory_.HasWeakPtrs()) {
|
||||
// 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.
|
||||
scoped_refptr<PrintJob> handle(this);
|
||||
|
||||
DCHECK(RunsTasksOnCurrentThread());
|
||||
DCHECK(RunsTasksInCurrentSequence());
|
||||
if (worker_ && worker_->IsRunning()) {
|
||||
// Call this right now so it renders the context invalid. Do not use
|
||||
// InvokeLater since it would take too much time.
|
||||
|
@ -419,7 +419,7 @@ void PrintJob::OnDocumentDone() {
|
|||
}
|
||||
|
||||
void PrintJob::ControlledWorkerShutdown() {
|
||||
DCHECK(RunsTasksOnCurrentThread());
|
||||
DCHECK(RunsTasksInCurrentSequence());
|
||||
|
||||
// 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.
|
||||
|
|
|
@ -198,7 +198,7 @@ PrintJobWorker::PrintJobWorker(int render_process_id,
|
|||
PrintJobWorkerOwner* owner)
|
||||
: owner_(owner), thread_("Printing_Worker"), weak_factory_(this) {
|
||||
// The object is created in the IO thread.
|
||||
DCHECK(owner_->RunsTasksOnCurrentThread());
|
||||
DCHECK(owner_->RunsTasksInCurrentSequence());
|
||||
|
||||
printing_context_delegate_ = base::MakeUnique<PrintingContextDelegate>(
|
||||
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
|
||||
// cancels printing or in the case of print preview, the worker is destroyed
|
||||
// on the I/O thread.
|
||||
DCHECK(owner_->RunsTasksOnCurrentThread());
|
||||
DCHECK(owner_->RunsTasksInCurrentSequence());
|
||||
Stop();
|
||||
}
|
||||
|
||||
|
@ -225,7 +225,7 @@ void PrintJobWorker::GetSettings(bool ask_user_for_settings,
|
|||
bool is_scripted,
|
||||
bool is_modifiable,
|
||||
const base::string16& device_name) {
|
||||
DCHECK(task_runner_->RunsTasksOnCurrentThread());
|
||||
DCHECK(task_runner_->RunsTasksInCurrentSequence());
|
||||
DCHECK_EQ(page_number_, PageNumber::npos());
|
||||
|
||||
// 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(
|
||||
std::unique_ptr<base::DictionaryValue> new_settings) {
|
||||
DCHECK(task_runner_->RunsTasksOnCurrentThread());
|
||||
DCHECK(task_runner_->RunsTasksInCurrentSequence());
|
||||
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::UI,
|
||||
|
@ -332,7 +332,7 @@ void PrintJobWorker::InitWithDeviceName(const base::string16& device_name) {
|
|||
}
|
||||
|
||||
void PrintJobWorker::StartPrinting(PrintedDocument* new_document) {
|
||||
DCHECK(task_runner_->RunsTasksOnCurrentThread());
|
||||
DCHECK(task_runner_->RunsTasksInCurrentSequence());
|
||||
DCHECK_EQ(page_number_, PageNumber::npos());
|
||||
DCHECK_EQ(document_.get(), new_document);
|
||||
DCHECK(document_.get());
|
||||
|
@ -361,7 +361,7 @@ void PrintJobWorker::StartPrinting(PrintedDocument* new_document) {
|
|||
}
|
||||
|
||||
void PrintJobWorker::OnDocumentChanged(PrintedDocument* new_document) {
|
||||
DCHECK(task_runner_->RunsTasksOnCurrentThread());
|
||||
DCHECK(task_runner_->RunsTasksInCurrentSequence());
|
||||
DCHECK_EQ(page_number_, PageNumber::npos());
|
||||
|
||||
if (page_number_ != PageNumber::npos())
|
||||
|
@ -375,7 +375,7 @@ void PrintJobWorker::OnNewPage() {
|
|||
return;
|
||||
|
||||
// message_loop() could return NULL when the print job is cancelled.
|
||||
DCHECK(task_runner_->RunsTasksOnCurrentThread());
|
||||
DCHECK(task_runner_->RunsTasksInCurrentSequence());
|
||||
|
||||
if (page_number_ == PageNumber::npos()) {
|
||||
// Find first page to print.
|
||||
|
@ -446,7 +446,7 @@ bool PrintJobWorker::Start() {
|
|||
}
|
||||
|
||||
void PrintJobWorker::OnDocumentDone() {
|
||||
DCHECK(task_runner_->RunsTasksOnCurrentThread());
|
||||
DCHECK(task_runner_->RunsTasksInCurrentSequence());
|
||||
DCHECK_EQ(page_number_, PageNumber::npos());
|
||||
DCHECK(document_.get());
|
||||
|
||||
|
@ -465,7 +465,7 @@ void PrintJobWorker::OnDocumentDone() {
|
|||
}
|
||||
|
||||
void PrintJobWorker::SpoolPage(PrintedPage* page) {
|
||||
DCHECK(task_runner_->RunsTasksOnCurrentThread());
|
||||
DCHECK(task_runner_->RunsTasksInCurrentSequence());
|
||||
DCHECK_NE(page_number_, PageNumber::npos());
|
||||
|
||||
// Signal everyone that the page is about to be printed.
|
||||
|
@ -503,7 +503,7 @@ void PrintJobWorker::SpoolPage(PrintedPage* page) {
|
|||
}
|
||||
|
||||
void PrintJobWorker::OnFailure() {
|
||||
DCHECK(task_runner_->RunsTasksOnCurrentThread());
|
||||
DCHECK(task_runner_->RunsTasksInCurrentSequence());
|
||||
|
||||
// We may loose our last reference by broadcasting the FAILED event.
|
||||
scoped_refptr<PrintJobWorkerOwner> handle(owner_);
|
||||
|
|
|
@ -16,8 +16,8 @@ PrintJobWorkerOwner::PrintJobWorkerOwner()
|
|||
PrintJobWorkerOwner::~PrintJobWorkerOwner() {
|
||||
}
|
||||
|
||||
bool PrintJobWorkerOwner::RunsTasksOnCurrentThread() const {
|
||||
return task_runner_->RunsTasksOnCurrentThread();
|
||||
bool PrintJobWorkerOwner::RunsTasksInCurrentSequence() const {
|
||||
return task_runner_->RunsTasksInCurrentSequence();
|
||||
}
|
||||
|
||||
bool PrintJobWorkerOwner::PostTask(const tracked_objects::Location& from_here,
|
||||
|
|
|
@ -48,7 +48,7 @@ class PrintJobWorkerOwner
|
|||
// 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
|
||||
// thread.
|
||||
bool RunsTasksOnCurrentThread() const;
|
||||
bool RunsTasksInCurrentSequence() const;
|
||||
|
||||
// Posts the given task to be run.
|
||||
bool PostTask(const tracked_objects::Location& from_here,
|
||||
|
|
|
@ -74,7 +74,7 @@ void PrinterQuery::GetSettings(GetSettingsAskParam ask_user_for_settings,
|
|||
bool is_scripted,
|
||||
bool is_modifiable,
|
||||
const base::Closure& callback) {
|
||||
DCHECK(RunsTasksOnCurrentThread());
|
||||
DCHECK(RunsTasksInCurrentSequence());
|
||||
DCHECK(!is_print_dialog_box_shown_ || !is_scripted);
|
||||
|
||||
StartWorker(callback);
|
||||
|
@ -98,7 +98,7 @@ void PrinterQuery::GetSettings(
|
|||
bool is_modifiable,
|
||||
const base::string16& device_name,
|
||||
const base::Closure& callback) {
|
||||
DCHECK(RunsTasksOnCurrentThread());
|
||||
DCHECK(RunsTasksInCurrentSequence());
|
||||
DCHECK(!is_print_dialog_box_shown_);
|
||||
StartWorker(callback);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче