|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
|
2 // Use of this source code is governed by a BSD-style license that can be |
|
3 // found in the LICENSE file. |
|
4 |
|
5 #ifndef CHROME_COMMON_TASK_QUEUE_H__ |
|
6 #define CHROME_COMMON_TASK_QUEUE_H__ |
|
7 |
|
8 #include <deque> |
|
9 |
|
10 #include "base/task.h" |
|
11 |
|
12 // A TaskQueue is a queue of tasks waiting to be run. To run the tasks, call |
|
13 // the Run method. A task queue is itself a Task so that it can be placed in a |
|
14 // message loop or another task queue. |
|
15 class TaskQueue : public Task { |
|
16 public: |
|
17 TaskQueue(); |
|
18 ~TaskQueue(); |
|
19 |
|
20 // Run all the tasks in the queue. New tasks pushed onto the queue during |
|
21 // a run will be run next time |Run| is called. |
|
22 virtual void Run(); |
|
23 |
|
24 // Push the specified task onto the queue. When the queue is run, the tasks |
|
25 // will be run in the order they are pushed. |
|
26 // |
|
27 // This method takes ownership of |task| and will delete task after it is run |
|
28 // (or when the TaskQueue is destroyed, if we never got a chance to run it). |
|
29 void Push(Task* task); |
|
30 |
|
31 // Remove all tasks from the queue. The tasks are deleted. |
|
32 void Clear(); |
|
33 |
|
34 // Returns true if this queue contains no tasks. |
|
35 bool Empty() const; |
|
36 |
|
37 private: |
|
38 // The list of tasks we are waiting to run. |
|
39 std::deque<Task*> queue_; |
|
40 }; |
|
41 |
|
42 #endif // CHROME_COMMON_TASK_QUEUE_H__ |