| 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 "content/renderer/scheduler/task_queue_manager.h" | 5 #include "content/renderer/scheduler/task_queue_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "content/renderer/scheduler/task_queue_selector.h" | 9 #include "content/renderer/scheduler/task_queue_selector.h" |
| 10 | 10 |
| 11 namespace content { | 11 namespace content { |
| 12 namespace internal { | 12 namespace internal { |
| 13 | 13 |
| 14 class TaskQueue : public base::SingleThreadTaskRunner { | 14 class TaskQueue : public base::SingleThreadTaskRunner { |
| 15 public: | 15 public: |
| 16 TaskQueue(TaskQueueManager* task_queue_manager); | 16 TaskQueue(TaskQueueManager* task_queue_manager); |
| 17 | 17 |
| 18 // base::SingleThreadTaskRunner implementation. | 18 // base::SingleThreadTaskRunner implementation. |
| 19 virtual bool RunsTasksOnCurrentThread() const override; | 19 bool RunsTasksOnCurrentThread() const override; |
| 20 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, | 20 bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 21 const base::Closure& task, | 21 const base::Closure& task, |
| 22 base::TimeDelta delay) override; | 22 base::TimeDelta delay) override; |
| 23 virtual bool PostNonNestableDelayedTask( | 23 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, |
| 24 const tracked_objects::Location& from_here, | 24 const base::Closure& task, |
| 25 const base::Closure& task, | 25 base::TimeDelta delay) override; |
| 26 base::TimeDelta delay) override; | |
| 27 | 26 |
| 28 // Adds a task at the end of the incoming task queue and schedules a call to | 27 // Adds a task at the end of the incoming task queue and schedules a call to |
| 29 // TaskQueueManager::DoWork() if the incoming queue was empty and automatic | 28 // TaskQueueManager::DoWork() if the incoming queue was empty and automatic |
| 30 // pumping is enabled. Can be called on an arbitrary thread. | 29 // pumping is enabled. Can be called on an arbitrary thread. |
| 31 void EnqueueTask(const base::PendingTask& pending_task); | 30 void EnqueueTask(const base::PendingTask& pending_task); |
| 32 | 31 |
| 33 bool IsQueueEmpty() const; | 32 bool IsQueueEmpty() const; |
| 34 | 33 |
| 35 void SetAutoPump(bool auto_pump); | 34 void SetAutoPump(bool auto_pump); |
| 36 void PumpQueue(); | 35 void PumpQueue(); |
| 37 | 36 |
| 38 bool UpdateWorkQueue(); | 37 bool UpdateWorkQueue(); |
| 39 base::PendingTask TakeTaskFromWorkQueue(); | 38 base::PendingTask TakeTaskFromWorkQueue(); |
| 40 | 39 |
| 41 void WillDeleteTaskQueueManager(); | 40 void WillDeleteTaskQueueManager(); |
| 42 | 41 |
| 43 base::TaskQueue& work_queue() { return work_queue_; } | 42 base::TaskQueue& work_queue() { return work_queue_; } |
| 44 | 43 |
| 45 private: | 44 private: |
| 46 virtual ~TaskQueue(); | 45 ~TaskQueue() override; |
| 47 | 46 |
| 48 void PumpQueueLocked(); | 47 void PumpQueueLocked(); |
| 49 void EnqueueTaskLocked(const base::PendingTask& pending_task); | 48 void EnqueueTaskLocked(const base::PendingTask& pending_task); |
| 50 | 49 |
| 51 // This lock protects all members except the work queue. | 50 // This lock protects all members except the work queue. |
| 52 mutable base::Lock lock_; | 51 mutable base::Lock lock_; |
| 53 TaskQueueManager* task_queue_manager_; | 52 TaskQueueManager* task_queue_manager_; |
| 54 base::TaskQueue incoming_queue_; | 53 base::TaskQueue incoming_queue_; |
| 55 bool auto_pump_; | 54 bool auto_pump_; |
| 56 | 55 |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 | 285 |
| 287 bool TaskQueueManager::PostNonNestableDelayedTask( | 286 bool TaskQueueManager::PostNonNestableDelayedTask( |
| 288 const tracked_objects::Location& from_here, | 287 const tracked_objects::Location& from_here, |
| 289 const base::Closure& task, | 288 const base::Closure& task, |
| 290 base::TimeDelta delay) { | 289 base::TimeDelta delay) { |
| 291 // Defer non-nestable work to the main task runner. | 290 // Defer non-nestable work to the main task runner. |
| 292 return main_task_runner_->PostNonNestableDelayedTask(from_here, task, delay); | 291 return main_task_runner_->PostNonNestableDelayedTask(from_here, task, delay); |
| 293 } | 292 } |
| 294 | 293 |
| 295 } // namespace content | 294 } // namespace content |
| OLD | NEW |