| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/test_tools/test_task_runner.h" | 5 #include "net/quic/test_tools/test_task_runner.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "net/quic/test_tools/mock_clock.h" | 9 #include "net/quic/test_tools/mock_clock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 return tasks_; | 33 return tasks_; |
| 34 } | 34 } |
| 35 | 35 |
| 36 void TestTaskRunner::RunNextTask() { | 36 void TestTaskRunner::RunNextTask() { |
| 37 // Find the next task to run, advance the time to the correct time | 37 // Find the next task to run, advance the time to the correct time |
| 38 // and then run the task. | 38 // and then run the task. |
| 39 std::vector<PostedTask>::iterator next = FindNextTask(); | 39 std::vector<PostedTask>::iterator next = FindNextTask(); |
| 40 DCHECK(next != tasks_.end()); | 40 DCHECK(next != tasks_.end()); |
| 41 clock_->AdvanceTime(QuicTime::Delta::FromMicroseconds( | 41 clock_->AdvanceTime(QuicTime::Delta::FromMicroseconds( |
| 42 (next->GetTimeToRun() - clock_->NowInTicks()).InMicroseconds())); | 42 (next->GetTimeToRun() - clock_->NowInTicks()).InMicroseconds())); |
| 43 PostedTask task = *next; | 43 PostedTask task = std::move(*next); |
| 44 tasks_.erase(next); | 44 tasks_.erase(next); |
| 45 task.task.Run(); | 45 std::move(task.task).Run(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 namespace { | 48 namespace { |
| 49 | 49 |
| 50 struct ShouldRunBeforeLessThan { | 50 struct ShouldRunBeforeLessThan { |
| 51 bool operator()(const PostedTask& task1, const PostedTask& task2) const { | 51 bool operator()(const PostedTask& task1, const PostedTask& task2) const { |
| 52 return task1.ShouldRunBefore(task2); | 52 return task1.ShouldRunBefore(task2); |
| 53 } | 53 } |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 } // namespace | 56 } // namespace |
| 57 | 57 |
| 58 std::vector<PostedTask>::iterator TestTaskRunner::FindNextTask() { | 58 std::vector<PostedTask>::iterator TestTaskRunner::FindNextTask() { |
| 59 return std::min_element(tasks_.begin(), tasks_.end(), | 59 return std::min_element(tasks_.begin(), tasks_.end(), |
| 60 ShouldRunBeforeLessThan()); | 60 ShouldRunBeforeLessThan()); |
| 61 } | 61 } |
| 62 | 62 |
| 63 } // namespace test | 63 } // namespace test |
| 64 } // namespace net | 64 } // namespace net |
| OLD | NEW |