WebKit roll 98705:98715
[chromium-blink-merge.git] / base / task_queue.h
blob877201c422256ca79c851f7a6b15cd86fe944ac4
1 // Copyright (c) 2011 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.
5 #ifndef BASE_TASK_QUEUE_H_
6 #define BASE_TASK_QUEUE_H_
7 #pragma once
9 #include <deque>
11 #include "base/base_export.h"
12 #include "base/task.h"
14 // A TaskQueue is a queue of tasks waiting to be run. To run the tasks, call
15 // the Run method. A task queue is itself a Task so that it can be placed in a
16 // message loop or another task queue.
17 class BASE_EXPORT TaskQueue : public Task {
18 public:
19 TaskQueue();
20 virtual ~TaskQueue();
22 // Push the specified task onto the queue. When the queue is run, the tasks
23 // will be run in the order they are pushed.
25 // This method takes ownership of |task| and will delete task after it is run
26 // (or when the TaskQueue is destroyed, if we never got a chance to run it).
27 void Push(Task* task);
29 // Remove all tasks from the queue. The tasks are deleted.
30 void Clear();
32 // Returns true if this queue contains no tasks.
33 bool IsEmpty() const;
35 // Run all the tasks in the queue. New tasks pushed onto the queue during
36 // a run will be run next time |Run| is called.
37 virtual void Run();
39 private:
40 // The list of tasks we are waiting to run.
41 std::deque<Task*> queue_;
44 #endif // BASE_TASK_QUEUE_H_