OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/scheduler/base/task_queue_manager.h" | 5 #include "components/scheduler/base/task_queue_manager.h" |
6 | 6 |
7 #include <queue> | 7 #include <queue> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 | 211 |
212 // Only run a single task per batch in nested run loops so that we can | 212 // Only run a single task per batch in nested run loops so that we can |
213 // properly exit the nested loop when someone calls RunLoop::Quit(). | 213 // properly exit the nested loop when someone calls RunLoop::Quit(). |
214 if (delegate_->IsNested()) | 214 if (delegate_->IsNested()) |
215 break; | 215 break; |
216 } | 216 } |
217 | 217 |
218 // TODO(alexclarke): Consider refactoring the above loop to terminate only | 218 // TODO(alexclarke): Consider refactoring the above loop to terminate only |
219 // when there's no more work left to be done, rather than posting a | 219 // when there's no more work left to be done, rather than posting a |
220 // continuation task. | 220 // continuation task. |
221 if (!selector_.EnabledWorkQueuesEmpty() || TryAdvanceTimeDomains()) { | 221 if (!selector_.EnabledWorkQueuesEmpty() || TryAdvanceTimeDomains()) |
222 MaybeScheduleImmediateWork(FROM_HERE); | 222 MaybeScheduleImmediateWork(FROM_HERE); |
223 } else { | |
224 // Tell the task runner we have no more work. | |
225 delegate_->OnNoMoreImmediateWork(); | |
226 } | |
227 } | 223 } |
228 | 224 |
229 bool TaskQueueManager::TryAdvanceTimeDomains() { | 225 bool TaskQueueManager::TryAdvanceTimeDomains() { |
230 bool can_advance = false; | 226 bool can_advance = false; |
231 for (TimeDomain* time_domain : time_domains_) { | 227 for (TimeDomain* time_domain : time_domains_) { |
232 can_advance |= time_domain->MaybeAdvanceTime(); | 228 can_advance |= time_domain->MaybeAdvanceTime(); |
233 } | 229 } |
234 return can_advance; | 230 return can_advance; |
235 } | 231 } |
236 | 232 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 | 269 |
274 TRACE_TASK_EXECUTION("TaskQueueManager::ProcessTaskFromWorkQueue", | 270 TRACE_TASK_EXECUTION("TaskQueueManager::ProcessTaskFromWorkQueue", |
275 pending_task); | 271 pending_task); |
276 if (queue->GetShouldNotifyObservers()) { | 272 if (queue->GetShouldNotifyObservers()) { |
277 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver, task_observers_, | 273 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver, task_observers_, |
278 WillProcessTask(pending_task)); | 274 WillProcessTask(pending_task)); |
279 queue->NotifyWillProcessTask(pending_task); | 275 queue->NotifyWillProcessTask(pending_task); |
280 } | 276 } |
281 TRACE_EVENT1(tracing_category_, | 277 TRACE_EVENT1(tracing_category_, |
282 "TaskQueueManager::RunTask", "queue", queue->GetName()); | 278 "TaskQueueManager::RunTask", "queue", queue->GetName()); |
279 scoped_refptr<internal::TaskQueueImpl> prev_executing_task_queue = | |
Sami
2016/02/01 17:05:39
Let's go back to the raw pointer and add a comment
alex clarke (OOO till 29th)
2016/02/01 17:50:09
Done.
| |
280 currently_executing_task_queue_; | |
281 currently_executing_task_queue_ = queue; | |
283 task_annotator_.RunTask("TaskQueueManager::PostTask", pending_task); | 282 task_annotator_.RunTask("TaskQueueManager::PostTask", pending_task); |
283 currently_executing_task_queue_ = prev_executing_task_queue; | |
284 | 284 |
285 // Detect if the TaskQueueManager just got deleted. If this happens we must | 285 // Detect if the TaskQueueManager just got deleted. If this happens we must |
Sami
2016/02/01 17:05:39
Move to line 283.
alex clarke (OOO till 29th)
2016/02/01 17:50:09
Done.
| |
286 // not access any member variables after this point. | 286 // not access any member variables after this point. |
287 if (protect->HasOneRef()) | 287 if (protect->HasOneRef()) |
288 return ProcessTaskResult::TASK_QUEUE_MANAGER_DELETED; | 288 return ProcessTaskResult::TASK_QUEUE_MANAGER_DELETED; |
289 | 289 |
290 if (queue->GetShouldNotifyObservers()) { | 290 if (queue->GetShouldNotifyObservers()) { |
291 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver, task_observers_, | 291 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver, task_observers_, |
292 DidProcessTask(pending_task)); | 292 DidProcessTask(pending_task)); |
293 queue->NotifyDidProcessTask(pending_task); | 293 queue->NotifyDidProcessTask(pending_task); |
294 } | 294 } |
295 | 295 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 internal::WorkQueue* work_queue) { | 399 internal::WorkQueue* work_queue) { |
400 DCHECK(main_thread_checker_.CalledOnValidThread()); | 400 DCHECK(main_thread_checker_.CalledOnValidThread()); |
401 DCHECK(!work_queue->Empty()); | 401 DCHECK(!work_queue->Empty()); |
402 if (observer_) { | 402 if (observer_) { |
403 observer_->OnTriedToExecuteBlockedTask(*work_queue->task_queue(), | 403 observer_->OnTriedToExecuteBlockedTask(*work_queue->task_queue(), |
404 *work_queue->GetFrontTask()); | 404 *work_queue->GetFrontTask()); |
405 } | 405 } |
406 } | 406 } |
407 | 407 |
408 } // namespace scheduler | 408 } // namespace scheduler |
OLD | NEW |