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

Side by Side Diff: cc/test/task_graph_runner_test_template.cc

Issue 1449133002: TaskGraphRunner refactor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: feedback Created 5 years 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 | « cc/test/task_graph_runner_test_template.h ('k') | cc/test/test_task_graph_runner.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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.
4
5 #include "cc/test/task_graph_runner_test_template.h"
6
7 namespace cc {
8
9 const int TaskGraphRunnerTestBase::kNamespaceCount;
10
11 void TaskGraphRunnerTestBase::SetTaskGraphRunner(
12 TaskGraphRunner* task_graph_runner) {
13 task_graph_runner_ = task_graph_runner;
14 }
15
16 void TaskGraphRunnerTestBase::ResetIds(int namespace_index) {
17 run_task_ids_[namespace_index].clear();
18 on_task_completed_ids_[namespace_index].clear();
19 }
20
21 void TaskGraphRunnerTestBase::RunAllTasks(int namespace_index) {
22 task_graph_runner_->WaitForTasksToFinishRunning(
23 namespace_token_[namespace_index]);
24
25 Task::Vector completed_tasks;
26 task_graph_runner_->CollectCompletedTasks(namespace_token_[namespace_index],
27 &completed_tasks);
28 for (Task::Vector::const_iterator it = completed_tasks.begin();
29 it != completed_tasks.end(); ++it) {
30 FakeTaskImpl* task = static_cast<FakeTaskImpl*>(it->get());
31 task->CompleteOnOriginThread();
32 }
33 }
34
35 void TaskGraphRunnerTestBase::RunTaskOnWorkerThread(int namespace_index,
36 unsigned id) {
37 base::AutoLock lock(run_task_ids_lock_);
38 run_task_ids_[namespace_index].push_back(id);
39 }
40
41 void TaskGraphRunnerTestBase::OnTaskCompleted(int namespace_index,
42 unsigned id) {
43 on_task_completed_ids_[namespace_index].push_back(id);
44 }
45
46 const std::vector<unsigned>& TaskGraphRunnerTestBase::run_task_ids(
47 int namespace_index) {
48 return run_task_ids_[namespace_index];
49 }
50
51 const std::vector<unsigned>& TaskGraphRunnerTestBase::on_task_completed_ids(
52 int namespace_index) {
53 return on_task_completed_ids_[namespace_index];
54 }
55
56 void TaskGraphRunnerTestBase::ScheduleTasks(
57 int namespace_index,
58 const std::vector<TaskInfo>& tasks) {
59 Task::Vector new_tasks;
60 Task::Vector new_dependents;
61 TaskGraph new_graph;
62
63 for (std::vector<TaskInfo>::const_iterator it = tasks.begin();
64 it != tasks.end(); ++it) {
65 scoped_refptr<FakeTaskImpl> new_task(
66 new FakeTaskImpl(this, it->namespace_index, it->id));
67 new_graph.nodes.push_back(
68 TaskGraph::Node(new_task.get(), it->priority, 0u));
69 for (unsigned i = 0; i < it->dependent_count; ++i) {
70 scoped_refptr<FakeDependentTaskImpl> new_dependent_task(
71 new FakeDependentTaskImpl(this, it->namespace_index,
72 it->dependent_id));
73 new_graph.nodes.push_back(
74 TaskGraph::Node(new_dependent_task.get(), it->priority, 1u));
75 new_graph.edges.push_back(
76 TaskGraph::Edge(new_task.get(), new_dependent_task.get()));
77
78 new_dependents.push_back(new_dependent_task.get());
79 }
80
81 new_tasks.push_back(new_task.get());
82 }
83
84 task_graph_runner_->ScheduleTasks(namespace_token_[namespace_index],
85 &new_graph);
86
87 dependents_[namespace_index].swap(new_dependents);
88 tasks_[namespace_index].swap(new_tasks);
89 }
90
91 void TaskGraphRunnerTestBase::FakeTaskImpl::RunOnWorkerThread() {
92 test_->RunTaskOnWorkerThread(namespace_index_, id_);
93 }
94
95 void TaskGraphRunnerTestBase::FakeTaskImpl::CompleteOnOriginThread() {
96 test_->OnTaskCompleted(namespace_index_, id_);
97 }
98
99 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/task_graph_runner_test_template.h ('k') | cc/test/test_task_graph_runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698