OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/task_scheduler/scheduler_worker.h" | 5 #include "base/task_scheduler/scheduler_worker.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
(...skipping 28 matching lines...) Expand all Loading... |
39 class SchedulerWorkerDefaultDelegate : public SchedulerWorker::Delegate { | 39 class SchedulerWorkerDefaultDelegate : public SchedulerWorker::Delegate { |
40 public: | 40 public: |
41 SchedulerWorkerDefaultDelegate() = default; | 41 SchedulerWorkerDefaultDelegate() = default; |
42 | 42 |
43 // SchedulerWorker::Delegate: | 43 // SchedulerWorker::Delegate: |
44 void OnMainEntry(SchedulerWorker* worker) override {} | 44 void OnMainEntry(SchedulerWorker* worker) override {} |
45 scoped_refptr<Sequence> GetWork(SchedulerWorker* worker) override { | 45 scoped_refptr<Sequence> GetWork(SchedulerWorker* worker) override { |
46 return nullptr; | 46 return nullptr; |
47 } | 47 } |
48 void DidRunTaskWithPriority(TaskPriority task_priority, | 48 void DidRunTaskWithPriority(TaskPriority task_priority, |
49 const TimeDelta& task_latency) override { | 49 TimeDelta task_latency) override { |
50 ADD_FAILURE() << "Unexpected call to DidRunTaskWithPriority()"; | 50 ADD_FAILURE() << "Unexpected call to DidRunTaskWithPriority()"; |
51 } | 51 } |
52 void ReEnqueueSequence(scoped_refptr<Sequence> sequence) override { | 52 void ReEnqueueSequence(scoped_refptr<Sequence> sequence) override { |
53 ADD_FAILURE() << "Unexpected call to ReEnqueueSequence()"; | 53 ADD_FAILURE() << "Unexpected call to ReEnqueueSequence()"; |
54 } | 54 } |
55 TimeDelta GetSleepTimeout() override { return TimeDelta::Max(); } | 55 TimeDelta GetSleepTimeout() override { return TimeDelta::Max(); } |
56 bool CanDetach(SchedulerWorker* worker) override { return false; } | 56 bool CanDetach(SchedulerWorker* worker) override { return false; } |
57 void OnDetach() override { ADD_FAILURE() << "Unexpected call to OnDetach()"; } | 57 void OnDetach() override { ADD_FAILURE() << "Unexpected call to OnDetach()"; } |
58 | 58 |
59 private: | 59 private: |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 { | 179 { |
180 // Add the Sequence to the vector of created Sequences. | 180 // Add the Sequence to the vector of created Sequences. |
181 AutoSchedulerLock auto_lock(outer_->lock_); | 181 AutoSchedulerLock auto_lock(outer_->lock_); |
182 outer_->created_sequences_.push_back(sequence); | 182 outer_->created_sequences_.push_back(sequence); |
183 } | 183 } |
184 | 184 |
185 return sequence; | 185 return sequence; |
186 } | 186 } |
187 | 187 |
188 void DidRunTaskWithPriority(TaskPriority task_priority, | 188 void DidRunTaskWithPriority(TaskPriority task_priority, |
189 const TimeDelta& task_latency) override { | 189 TimeDelta task_latency) override { |
190 AutoSchedulerLock auto_lock(expect_did_run_task_with_priority_lock_); | 190 AutoSchedulerLock auto_lock(expect_did_run_task_with_priority_lock_); |
191 EXPECT_TRUE(expect_did_run_task_with_priority_); | 191 EXPECT_TRUE(expect_did_run_task_with_priority_); |
192 EXPECT_EQ(expected_task_priority_, task_priority); | 192 EXPECT_EQ(expected_task_priority_, task_priority); |
193 EXPECT_FALSE(task_latency.is_max()); | 193 EXPECT_FALSE(task_latency.is_max()); |
194 expect_did_run_task_with_priority_ = false; | 194 expect_did_run_task_with_priority_ = false; |
195 } | 195 } |
196 | 196 |
197 // This override verifies that |sequence| contains the expected number of | 197 // This override verifies that |sequence| contains the expected number of |
198 // Tasks and adds it to |enqueued_sequences_|. Unlike a normal | 198 // Tasks and adds it to |enqueued_sequences_|. Unlike a normal |
199 // EnqueueSequence implementation, it doesn't reinsert |sequence| into a | 199 // EnqueueSequence implementation, it doesn't reinsert |sequence| into a |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 scoped_refptr<Sequence> sequence(new Sequence); | 384 scoped_refptr<Sequence> sequence(new Sequence); |
385 std::unique_ptr<Task> task(new Task( | 385 std::unique_ptr<Task> task(new Task( |
386 FROM_HERE, Bind(&WaitableEvent::Signal, Unretained(&work_processed_)), | 386 FROM_HERE, Bind(&WaitableEvent::Signal, Unretained(&work_processed_)), |
387 TaskTraits(), TimeDelta())); | 387 TaskTraits(), TimeDelta())); |
388 EXPECT_TRUE(task_tracker_->WillPostTask(task.get())); | 388 EXPECT_TRUE(task_tracker_->WillPostTask(task.get())); |
389 sequence->PushTask(std::move(task)); | 389 sequence->PushTask(std::move(task)); |
390 return sequence; | 390 return sequence; |
391 } | 391 } |
392 | 392 |
393 void DidRunTaskWithPriority(TaskPriority task, | 393 void DidRunTaskWithPriority(TaskPriority task, |
394 const TimeDelta& task_latency) override {} | 394 TimeDelta task_latency) override {} |
395 | 395 |
396 bool CanDetach(SchedulerWorker* worker) override { | 396 bool CanDetach(SchedulerWorker* worker) override { |
397 detach_requested_.Signal(); | 397 detach_requested_.Signal(); |
398 return can_detach_; | 398 return can_detach_; |
399 } | 399 } |
400 | 400 |
401 void OnDetach() override { | 401 void OnDetach() override { |
402 EXPECT_TRUE(can_detach_); | 402 EXPECT_TRUE(can_detach_); |
403 EXPECT_TRUE(detach_requested_.IsSignaled()); | 403 EXPECT_TRUE(detach_requested_.IsSignaled()); |
404 detached_.Signal(); | 404 detached_.Signal(); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 // OnMainEntry() and GetWork() are called. | 601 // OnMainEntry() and GetWork() are called. |
602 worker->WakeUp(); | 602 worker->WakeUp(); |
603 delegate_raw->WaitForPriorityVerifiedInGetWork(); | 603 delegate_raw->WaitForPriorityVerifiedInGetWork(); |
604 | 604 |
605 worker->JoinForTesting(); | 605 worker->JoinForTesting(); |
606 } | 606 } |
607 | 607 |
608 } // namespace | 608 } // namespace |
609 } // namespace internal | 609 } // namespace internal |
610 } // namespace base | 610 } // namespace base |
OLD | NEW |