1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/chromium/src/chrome/common/task_queue.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,46 @@ 1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#include "chrome/common/task_queue.h" 1.9 + 1.10 +#include "base/stl_util-inl.h" 1.11 + 1.12 +TaskQueue::TaskQueue() { 1.13 +} 1.14 + 1.15 +TaskQueue::~TaskQueue() { 1.16 + // We own all the pointes in |queue_|. It is our job to delete them. 1.17 + STLDeleteElements(&queue_); 1.18 +} 1.19 + 1.20 +void TaskQueue::Run() { 1.21 + // Nothing to run if our queue is empty. 1.22 + if (queue_.empty()) 1.23 + return; 1.24 + 1.25 + std::deque<Task*> ready; 1.26 + queue_.swap(ready); 1.27 + 1.28 + // Run the tasks that are ready. 1.29 + std::deque<Task*>::const_iterator task; 1.30 + for (task = ready.begin(); task != ready.end(); ++task) { 1.31 + // Run the task and then delete it. 1.32 + (*task)->Run(); 1.33 + delete (*task); 1.34 + } 1.35 +} 1.36 + 1.37 +void TaskQueue::Push(Task* task) { 1.38 + // Add the task to the back of the queue. 1.39 + queue_.push_back(task); 1.40 +} 1.41 + 1.42 +void TaskQueue::Clear() { 1.43 + // Delete all the elements in the queue and clear the dead pointers. 1.44 + STLDeleteElements(&queue_); 1.45 +} 1.46 + 1.47 +bool TaskQueue::Empty() const { 1.48 + return queue_.empty(); 1.49 +}