Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / cc / test / ordered_simple_task_runner.cc
blob188ffe72b5f8adea6208635d68263b3139811000
1 // Copyright 2014 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 #include "cc/test/ordered_simple_task_runner.h"
7 #include <algorithm>
8 #include <deque>
10 #include "base/logging.h"
12 namespace {
14 bool TestPendingTaskComparator(const base::TestPendingTask& lhs,
15 const base::TestPendingTask& rhs) {
16 return lhs.ShouldRunBefore(rhs);
21 namespace cc {
23 OrderedSimpleTaskRunner::OrderedSimpleTaskRunner() {}
25 OrderedSimpleTaskRunner::~OrderedSimpleTaskRunner() {}
27 void OrderedSimpleTaskRunner::RunPendingTasks() {
28 DCHECK(thread_checker_.CalledOnValidThread());
29 // Swap with a local variable to avoid re-entrancy problems.
30 std::deque<base::TestPendingTask> tasks_to_run;
31 tasks_to_run.swap(pending_tasks_);
32 std::stable_sort(tasks_to_run.begin(),
33 tasks_to_run.end(),
34 TestPendingTaskComparator);
35 for (std::deque<base::TestPendingTask>::iterator it = tasks_to_run.begin();
36 it != tasks_to_run.end(); ++it) {
37 it->task.Run();
41 } // namespace cc