| 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 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_ | 5 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_ |
| 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_ | 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/atomic_sequence_num.h" | 10 #include "base/atomic_sequence_num.h" |
| 11 #include "base/cancelable_callback.h" | 11 #include "base/cancelable_callback.h" |
| 12 #include "base/debug/task_annotator.h" | 12 #include "base/debug/task_annotator.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/pending_task.h" | 16 #include "base/pending_task.h" |
| 17 #include "base/run_loop.h" |
| 17 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
| 18 #include "base/threading/thread_checker.h" | 19 #include "base/threading/thread_checker.h" |
| 19 #include "platform/scheduler/base/enqueue_order.h" | 20 #include "platform/scheduler/base/enqueue_order.h" |
| 20 #include "platform/scheduler/base/moveable_auto_lock.h" | 21 #include "platform/scheduler/base/moveable_auto_lock.h" |
| 21 #include "platform/scheduler/base/task_queue_impl.h" | 22 #include "platform/scheduler/base/task_queue_impl.h" |
| 22 #include "platform/scheduler/base/task_queue_selector.h" | 23 #include "platform/scheduler/base/task_queue_selector.h" |
| 23 | 24 |
| 24 namespace base { | 25 namespace base { |
| 25 namespace trace_event { | 26 namespace trace_event { |
| 26 class ConvertableToTraceFormat; | 27 class ConvertableToTraceFormat; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 46 // 1. Incoming task queue. Tasks that are posted get immediately appended here. | 47 // 1. Incoming task queue. Tasks that are posted get immediately appended here. |
| 47 // When a task is appended into an empty incoming queue, the task manager | 48 // When a task is appended into an empty incoming queue, the task manager |
| 48 // work function (DoWork) is scheduled to run on the main task runner. | 49 // work function (DoWork) is scheduled to run on the main task runner. |
| 49 // | 50 // |
| 50 // 2. Work queue. If a work queue is empty when DoWork() is entered, tasks from | 51 // 2. Work queue. If a work queue is empty when DoWork() is entered, tasks from |
| 51 // the incoming task queue (if any) are moved here. The work queues are | 52 // the incoming task queue (if any) are moved here. The work queues are |
| 52 // registered with the selector as input to the scheduling decision. | 53 // registered with the selector as input to the scheduling decision. |
| 53 // | 54 // |
| 54 class BLINK_PLATFORM_EXPORT TaskQueueManager | 55 class BLINK_PLATFORM_EXPORT TaskQueueManager |
| 55 : public internal::TaskQueueSelector::Observer, | 56 : public internal::TaskQueueSelector::Observer, |
| 56 public base::MessageLoop::NestingObserver { | 57 public base::RunLoop::NestingObserver { |
| 57 public: | 58 public: |
| 58 // Create a task queue manager where |delegate| identifies the thread | 59 // Create a task queue manager where |delegate| identifies the thread |
| 59 // on which where the tasks are eventually run. Category strings must have | 60 // on which where the tasks are eventually run. Category strings must have |
| 60 // application lifetime (statics or literals). They may not include " chars. | 61 // application lifetime (statics or literals). They may not include " chars. |
| 61 TaskQueueManager(scoped_refptr<TaskQueueManagerDelegate> delegate, | 62 TaskQueueManager(scoped_refptr<TaskQueueManagerDelegate> delegate, |
| 62 const char* tracing_category, | 63 const char* tracing_category, |
| 63 const char* disabled_by_default_tracing_category, | 64 const char* disabled_by_default_tracing_category, |
| 64 const char* disabled_by_default_verbose_tracing_category); | 65 const char* disabled_by_default_verbose_tracing_category); |
| 65 ~TaskQueueManager() override; | 66 ~TaskQueueManager() override; |
| 66 | 67 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 }; | 230 }; |
| 230 | 231 |
| 231 // Unregisters a TaskQueue previously created by |NewTaskQueue()|. | 232 // Unregisters a TaskQueue previously created by |NewTaskQueue()|. |
| 232 void UnregisterTaskQueue(scoped_refptr<internal::TaskQueueImpl> task_queue); | 233 void UnregisterTaskQueue(scoped_refptr<internal::TaskQueueImpl> task_queue); |
| 233 | 234 |
| 234 // TaskQueueSelector::Observer implementation: | 235 // TaskQueueSelector::Observer implementation: |
| 235 void OnTaskQueueEnabled(internal::TaskQueueImpl* queue) override; | 236 void OnTaskQueueEnabled(internal::TaskQueueImpl* queue) override; |
| 236 void OnTriedToSelectBlockedWorkQueue( | 237 void OnTriedToSelectBlockedWorkQueue( |
| 237 internal::WorkQueue* work_queue) override; | 238 internal::WorkQueue* work_queue) override; |
| 238 | 239 |
| 239 // base::MessageLoop::NestingObserver implementation: | 240 // base::RunLoop::NestingObserver implementation: |
| 240 void OnBeginNestedMessageLoop() override; | 241 void OnBeginNestedMessageLoop() override; |
| 241 | 242 |
| 242 // Called by the task queue to register a new pending task. | 243 // Called by the task queue to register a new pending task. |
| 243 void DidQueueTask(const internal::TaskQueueImpl::Task& pending_task); | 244 void DidQueueTask(const internal::TaskQueueImpl::Task& pending_task); |
| 244 | 245 |
| 245 // Use the selector to choose a pending task and run it. | 246 // Use the selector to choose a pending task and run it. |
| 246 void DoWork(bool delayed); | 247 void DoWork(bool delayed); |
| 247 | 248 |
| 248 // Post a DoWork continuation if |next_delay| is not empty. | 249 // Post a DoWork continuation if |next_delay| is not empty. |
| 249 void PostDoWorkContinuationLocked(base::Optional<NextTaskDelay> next_delay, | 250 void PostDoWorkContinuationLocked(base::Optional<NextTaskDelay> next_delay, |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 scoped_refptr<DeletionSentinel> deletion_sentinel_; | 383 scoped_refptr<DeletionSentinel> deletion_sentinel_; |
| 383 base::WeakPtrFactory<TaskQueueManager> weak_factory_; | 384 base::WeakPtrFactory<TaskQueueManager> weak_factory_; |
| 384 | 385 |
| 385 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); | 386 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); |
| 386 }; | 387 }; |
| 387 | 388 |
| 388 } // namespace scheduler | 389 } // namespace scheduler |
| 389 } // namespace blink | 390 } // namespace blink |
| 390 | 391 |
| 391 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_MANAGER_
H_ | 392 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_MANAGER_
H_ |
| OLD | NEW |