OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/task_scheduler/task_tracker.h" | 5 #include "base/task_scheduler/task_tracker.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/debug/task_annotator.h" | 8 #include "base/debug/task_annotator.h" |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 // than |kMaxBlockShutdownTasksPostedDuringShutdown| BLOCK_SHUTDOWN tasks were | 51 // than |kMaxBlockShutdownTasksPostedDuringShutdown| BLOCK_SHUTDOWN tasks were |
52 // posted during shutdown. Otherwise, the histogram has already been recorded | 52 // posted during shutdown. Otherwise, the histogram has already been recorded |
53 // in BeforePostTask(). | 53 // in BeforePostTask(). |
54 if (num_block_shutdown_tasks_posted_during_shutdown_ < | 54 if (num_block_shutdown_tasks_posted_during_shutdown_ < |
55 kMaxBlockShutdownTasksPostedDuringShutdown) { | 55 kMaxBlockShutdownTasksPostedDuringShutdown) { |
56 RecordNumBlockShutdownTasksPostedDuringShutdown( | 56 RecordNumBlockShutdownTasksPostedDuringShutdown( |
57 num_block_shutdown_tasks_posted_during_shutdown_); | 57 num_block_shutdown_tasks_posted_during_shutdown_); |
58 } | 58 } |
59 } | 59 } |
60 | 60 |
61 void TaskTracker::PostTask( | 61 bool TaskTracker::WillPostTask(const Task* task) { |
62 const Callback<void(std::unique_ptr<Task>)>& post_task_callback, | |
63 std::unique_ptr<Task> task) { | |
64 DCHECK(!post_task_callback.is_null()); | |
65 DCHECK(task); | 62 DCHECK(task); |
66 | 63 |
67 if (!BeforePostTask(task->traits.shutdown_behavior())) | 64 if (!BeforePostTask(task->traits.shutdown_behavior())) |
68 return; | 65 return false; |
69 | 66 |
70 debug::TaskAnnotator task_annotator; | 67 debug::TaskAnnotator task_annotator; |
71 task_annotator.DidQueueTask(kQueueFunctionName, *task); | 68 task_annotator.DidQueueTask(kQueueFunctionName, *task); |
72 | 69 |
73 post_task_callback.Run(std::move(task)); | 70 return true; |
74 } | 71 } |
75 | 72 |
76 void TaskTracker::RunTask(const Task* task) { | 73 void TaskTracker::RunTask(const Task* task) { |
77 DCHECK(task); | 74 DCHECK(task); |
78 | 75 |
79 const TaskShutdownBehavior shutdown_behavior = | 76 const TaskShutdownBehavior shutdown_behavior = |
80 task->traits.shutdown_behavior(); | 77 task->traits.shutdown_behavior(); |
81 if (!BeforeRunTask(shutdown_behavior)) | 78 if (!BeforeRunTask(shutdown_behavior)) |
82 return; | 79 return; |
83 | 80 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 AutoSchedulerLock auto_lock(lock_); | 171 AutoSchedulerLock auto_lock(lock_); |
175 DCHECK_GT(num_tasks_blocking_shutdown_, 0U); | 172 DCHECK_GT(num_tasks_blocking_shutdown_, 0U); |
176 --num_tasks_blocking_shutdown_; | 173 --num_tasks_blocking_shutdown_; |
177 if (num_tasks_blocking_shutdown_ == 0 && shutdown_cv_) | 174 if (num_tasks_blocking_shutdown_ == 0 && shutdown_cv_) |
178 shutdown_cv_->Signal(); | 175 shutdown_cv_->Signal(); |
179 } | 176 } |
180 } | 177 } |
181 | 178 |
182 } // namespace internal | 179 } // namespace internal |
183 } // namespace base | 180 } // namespace base |
OLD | NEW |