| 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 #ifndef COMPONENTS_OFFLINE_PAGES_CORE_TASK_QUEUE_H_ | 5 #ifndef COMPONENTS_OFFLINE_PAGES_CORE_TASK_QUEUE_H_ |
| 6 #define COMPONENTS_OFFLINE_PAGES_CORE_TASK_QUEUE_H_ | 6 #define COMPONENTS_OFFLINE_PAGES_CORE_TASK_QUEUE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <queue> | 9 #include <queue> |
| 10 | 10 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 void AddTask(std::unique_ptr<Task> task); | 36 void AddTask(std::unique_ptr<Task> task); |
| 37 // Whether the task queue has any pending (not-running) tasks. | 37 // Whether the task queue has any pending (not-running) tasks. |
| 38 bool HasPendingTasks() const; | 38 bool HasPendingTasks() const; |
| 39 // Whether there is a task currently running. | 39 // Whether there is a task currently running. |
| 40 bool HasRunningTask() const; | 40 bool HasRunningTask() const; |
| 41 | 41 |
| 42 private: | 42 private: |
| 43 // Checks whether there are any tasks to run, as well as whether no task is | 43 // Checks whether there are any tasks to run, as well as whether no task is |
| 44 // currently running. When both are met, it will start the next task in the | 44 // currently running. When both are met, it will start the next task in the |
| 45 // queue. | 45 // queue. |
| 46 void MaybeStartTask(); | 46 void StartTaskIfAvailable(); |
| 47 | 47 |
| 48 // Callback for informing the queue that a task was completed. | 48 // Callback for informing the queue that a task was completed. |
| 49 void TaskCompleted(Task* task); | 49 void TaskCompleted(Task* task); |
| 50 | 50 |
| 51 // Currently running tasks. | 51 // Currently running tasks. |
| 52 std::unique_ptr<Task> current_task_; | 52 std::unique_ptr<Task> current_task_; |
| 53 | 53 |
| 54 // A FIFO queue of tasks that will be run using this task queue. | 54 // A FIFO queue of tasks that will be run using this task queue. |
| 55 std::queue<std::unique_ptr<Task>> tasks_; | 55 std::queue<std::unique_ptr<Task>> tasks_; |
| 56 | 56 |
| 57 base::WeakPtrFactory<TaskQueue> weak_ptr_factory_; | 57 base::WeakPtrFactory<TaskQueue> weak_ptr_factory_; |
| 58 | 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(TaskQueue); | 59 DISALLOW_COPY_AND_ASSIGN(TaskQueue); |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 } // namespace offline_pages | 62 } // namespace offline_pages |
| 63 | 63 |
| 64 #endif // COMPONENTS_OFFLINE_PAGES_CORE_TASK_QUEUE_H_ | 64 #endif // COMPONENTS_OFFLINE_PAGES_CORE_TASK_QUEUE_H_ |
| OLD | NEW |