michael@0: // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef CHROME_COMMON_TASK_QUEUE_H__ michael@0: #define CHROME_COMMON_TASK_QUEUE_H__ michael@0: michael@0: #include michael@0: michael@0: #include "base/task.h" michael@0: michael@0: // A TaskQueue is a queue of tasks waiting to be run. To run the tasks, call michael@0: // the Run method. A task queue is itself a Task so that it can be placed in a michael@0: // message loop or another task queue. michael@0: class TaskQueue : public Task { michael@0: public: michael@0: TaskQueue(); michael@0: ~TaskQueue(); michael@0: michael@0: // Run all the tasks in the queue. New tasks pushed onto the queue during michael@0: // a run will be run next time |Run| is called. michael@0: virtual void Run(); michael@0: michael@0: // Push the specified task onto the queue. When the queue is run, the tasks michael@0: // will be run in the order they are pushed. michael@0: // michael@0: // This method takes ownership of |task| and will delete task after it is run michael@0: // (or when the TaskQueue is destroyed, if we never got a chance to run it). michael@0: void Push(Task* task); michael@0: michael@0: // Remove all tasks from the queue. The tasks are deleted. michael@0: void Clear(); michael@0: michael@0: // Returns true if this queue contains no tasks. michael@0: bool Empty() const; michael@0: michael@0: private: michael@0: // The list of tasks we are waiting to run. michael@0: std::deque queue_; michael@0: }; michael@0: michael@0: #endif // CHROME_COMMON_TASK_QUEUE_H__