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

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

Issue 2627863002: Split Closure part of TestPendingTask out of the struct (Closed)
Patch Set: rebase Created 3 years, 11 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 | « net/quic/test_tools/test_task_runner.h ('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"
11 11
12 namespace net { 12 namespace net {
13 namespace test { 13 namespace test {
14 14
15 TestTaskRunner::TestTaskRunner(MockClock* clock) : clock_(clock) {} 15 TestTaskRunner::TestTaskRunner(MockClock* clock) : clock_(clock) {}
16 16
17 TestTaskRunner::~TestTaskRunner() {} 17 TestTaskRunner::~TestTaskRunner() {}
18 18
19 bool TestTaskRunner::PostDelayedTask(const tracked_objects::Location& from_here, 19 bool TestTaskRunner::PostDelayedTask(const tracked_objects::Location& from_here,
20 const base::Closure& task, 20 const base::Closure& task,
21 base::TimeDelta delay) { 21 base::TimeDelta delay) {
22 EXPECT_GE(delay, base::TimeDelta()); 22 EXPECT_GE(delay, base::TimeDelta());
23 tasks_.push_back(PostedTask(from_here, task, clock_->NowInTicks(), delay, 23 base::TestPendingTaskInfo task_info(from_here, clock_->NowInTicks(), delay,
24 base::TestPendingTask::NESTABLE)); 24 base::TestPendingTaskInfo::NESTABLE);
25 tasks_.push_back(std::make_pair(task_info, task));
25 return false; 26 return false;
26 } 27 }
27 28
28 bool TestTaskRunner::RunsTasksOnCurrentThread() const { 29 bool TestTaskRunner::RunsTasksOnCurrentThread() const {
29 return true; 30 return true;
30 } 31 }
31 32
32 const std::vector<PostedTask>& TestTaskRunner::GetPostedTasks() const { 33 const std::vector<PostedTask>& TestTaskRunner::GetPostedTasks() const {
33 return tasks_; 34 return tasks_;
34 } 35 }
35 36
36 void TestTaskRunner::RunNextTask() { 37 void TestTaskRunner::RunNextTask() {
37 // Find the next task to run, advance the time to the correct time 38 // Find the next task to run, advance the time to the correct time
38 // and then run the task. 39 // and then run the task.
39 std::vector<PostedTask>::iterator next = FindNextTask(); 40 std::vector<PostedTask>::iterator next = FindNextTask();
40 DCHECK(next != tasks_.end()); 41 DCHECK(next != tasks_.end());
42
43 const base::TestPendingTaskInfo& task_info = next->first;
41 clock_->AdvanceTime(QuicTime::Delta::FromMicroseconds( 44 clock_->AdvanceTime(QuicTime::Delta::FromMicroseconds(
42 (next->GetTimeToRun() - clock_->NowInTicks()).InMicroseconds())); 45 (task_info.GetTimeToRun() - clock_->NowInTicks()).InMicroseconds()));
43 PostedTask task = *next; 46 base::OnceClosure task = std::move(next->second);
44 tasks_.erase(next); 47 tasks_.erase(next);
45 task.task.Run(); 48 std::move(task).Run();
46 } 49 }
47 50
48 namespace { 51 namespace {
49 52
50 struct ShouldRunBeforeLessThan { 53 struct ShouldRunBeforeLessThan {
51 bool operator()(const PostedTask& task1, const PostedTask& task2) const { 54 bool operator()(const PostedTask& task1, const PostedTask& task2) const {
52 return task1.ShouldRunBefore(task2); 55 return task1.first.ShouldRunBefore(task2.first);
53 } 56 }
54 }; 57 };
55 58
56 } // namespace 59 } // namespace
57 60
58 std::vector<PostedTask>::iterator TestTaskRunner::FindNextTask() { 61 std::vector<PostedTask>::iterator TestTaskRunner::FindNextTask() {
59 return std::min_element(tasks_.begin(), tasks_.end(), 62 return std::min_element(tasks_.begin(), tasks_.end(),
60 ShouldRunBeforeLessThan()); 63 ShouldRunBeforeLessThan());
61 } 64 }
62 65
63 } // namespace test 66 } // namespace test
64 } // namespace net 67 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/test_task_runner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698