Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: net/quic/test_tools/test_task_runner.cc

Issue 2434783002: Use OnceClosure in TestPendingTask (Closed)
Patch Set: +comment Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/bluetooth/test/bluetooth_test_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « device/bluetooth/test/bluetooth_test_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698