| 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 "base/test/sequenced_task_runner_test_template.h" | 5 #include "base/test/sequenced_task_runner_test_template.h" |
| 6 | 6 |
| 7 #include <ostream> | 7 #include <ostream> |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 | 10 |
| 11 namespace base { | 11 namespace base { |
| 12 | 12 |
| 13 namespace internal { | 13 namespace internal { |
| 14 | 14 |
| 15 TaskEvent::TaskEvent(int i, Type type) | 15 TaskEvent::TaskEvent(int i, Type type) |
| 16 : i(i), type(type) { | 16 : i(i), type(type) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 SequencedTaskTracker::SequencedTaskTracker() : next_post_i_(0) { | 19 SequencedTaskTracker::SequencedTaskTracker() |
| 20 : next_post_i_(0), |
| 21 task_end_count_(0), |
| 22 task_end_cv_(&lock_) { |
| 20 } | 23 } |
| 21 | 24 |
| 22 void SequencedTaskTracker::PostWrappedNonNestableTask( | 25 void SequencedTaskTracker::PostWrappedNonNestableTask( |
| 23 const scoped_refptr<SequencedTaskRunner>& task_runner, | 26 const scoped_refptr<SequencedTaskRunner>& task_runner, |
| 24 const Closure& task) { | 27 const Closure& task) { |
| 25 AutoLock event_lock(lock_); | 28 AutoLock event_lock(lock_); |
| 26 const int post_i = next_post_i_++; | 29 const int post_i = next_post_i_++; |
| 27 Closure wrapped_task = Bind(&SequencedTaskTracker::RunTask, this, | 30 Closure wrapped_task = Bind(&SequencedTaskTracker::RunTask, this, |
| 28 task, post_i); | 31 task, post_i); |
| 29 task_runner->PostNonNestableTask(FROM_HERE, wrapped_task); | 32 task_runner->PostNonNestableTask(FROM_HERE, wrapped_task); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } | 77 } |
| 75 | 78 |
| 76 void SequencedTaskTracker::TaskStarted(int i) { | 79 void SequencedTaskTracker::TaskStarted(int i) { |
| 77 AutoLock lock(lock_); | 80 AutoLock lock(lock_); |
| 78 events_.push_back(TaskEvent(i, TaskEvent::START)); | 81 events_.push_back(TaskEvent(i, TaskEvent::START)); |
| 79 } | 82 } |
| 80 | 83 |
| 81 void SequencedTaskTracker::TaskEnded(int i) { | 84 void SequencedTaskTracker::TaskEnded(int i) { |
| 82 AutoLock lock(lock_); | 85 AutoLock lock(lock_); |
| 83 events_.push_back(TaskEvent(i, TaskEvent::END)); | 86 events_.push_back(TaskEvent(i, TaskEvent::END)); |
| 87 ++task_end_count_; |
| 88 task_end_cv_.Signal(); |
| 84 } | 89 } |
| 85 | 90 |
| 86 const std::vector<TaskEvent>& | 91 const std::vector<TaskEvent>& |
| 87 SequencedTaskTracker::GetTaskEvents() const { | 92 SequencedTaskTracker::GetTaskEvents() const { |
| 88 return events_; | 93 return events_; |
| 89 } | 94 } |
| 90 | 95 |
| 96 void SequencedTaskTracker::WaitForCompletedTasks(int count) { |
| 97 AutoLock lock(lock_); |
| 98 while (task_end_count_ < count) |
| 99 task_end_cv_.Wait(); |
| 100 } |
| 101 |
| 91 SequencedTaskTracker::~SequencedTaskTracker() { | 102 SequencedTaskTracker::~SequencedTaskTracker() { |
| 92 } | 103 } |
| 93 | 104 |
| 94 void PrintTo(const TaskEvent& event, std::ostream* os) { | 105 void PrintTo(const TaskEvent& event, std::ostream* os) { |
| 95 *os << "(i=" << event.i << ", type="; | 106 *os << "(i=" << event.i << ", type="; |
| 96 switch (event.type) { | 107 switch (event.type) { |
| 97 case TaskEvent::POST: *os << "POST"; break; | 108 case TaskEvent::POST: *os << "POST"; break; |
| 98 case TaskEvent::START: *os << "START"; break; | 109 case TaskEvent::START: *os << "START"; break; |
| 99 case TaskEvent::END: *os << "END"; break; | 110 case TaskEvent::END: *os << "END"; break; |
| 100 } | 111 } |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 CheckEventOrdersForEachTask(events, task_count); | 261 CheckEventOrdersForEachTask(events, task_count); |
| 251 if (!result) | 262 if (!result) |
| 252 return result; | 263 return result; |
| 253 | 264 |
| 254 return CheckNoTaskRunsOverlap(events); | 265 return CheckNoTaskRunsOverlap(events); |
| 255 } | 266 } |
| 256 | 267 |
| 257 } // namespace internal | 268 } // namespace internal |
| 258 | 269 |
| 259 } // namespace base | 270 } // namespace base |
| OLD | NEW |