Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Unified Diff: content/child/scheduler/task_queue_manager.cc

Issue 1072473002: Speculative patch: Make it safe to delete the TQM inside a Task (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/child/scheduler/task_queue_manager.cc
diff --git a/content/child/scheduler/task_queue_manager.cc b/content/child/scheduler/task_queue_manager.cc
index 386ebd0c955cc642f6ea09c8db56d004d33e9a41..ccf7743c402d3308e60bb08cd5a29d42bce24c2b 100644
--- a/content/child/scheduler/task_queue_manager.cc
+++ b/content/child/scheduler/task_queue_manager.cc
@@ -464,6 +464,7 @@ TaskQueueManager::TaskQueueManager(
time_source_(nullptr),
disabled_by_default_tracing_category_(
disabled_by_default_tracing_category),
+ deletion_sentinel_(new DeletionSentinel()),
weak_factory_(this) {
DCHECK(main_task_runner->RunsTasksOnCurrentThread());
TRACE_EVENT_OBJECT_CREATED_WITH_ID(disabled_by_default_tracing_category,
@@ -576,6 +577,8 @@ void TaskQueueManager::MaybePostDoWorkOnMainRunner() {
}
void TaskQueueManager::DoWork(bool posted_from_main_thread) {
+ scoped_refptr<DeletionSentinel> protect(deletion_sentinel_);
+
if (posted_from_main_thread) {
pending_dowork_count_--;
DCHECK_GE(pending_dowork_count_, 0);
@@ -598,6 +601,11 @@ void TaskQueueManager::DoWork(bool posted_from_main_thread) {
MaybePostDoWorkOnMainRunner();
ProcessTaskFromWorkQueue(queue_index, i > 0, &previous_task);
+ // Detect if the TaskQueueManager got deleted during the
Sami 2015/04/08 14:24:04 This should probably be moved to within ProcessTas
alex clarke (OOO till 29th) 2015/04/08 14:33:05 Done.
+ // ProcessTaskFromWorkQueue call.
+ if (protect->HasOneRef())
+ return;
+
if (!UpdateWorkQueues(&previous_task))
return;
}

Powered by Google App Engine
This is Rietveld 408576698