OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "public/platform/scheduler/child/webthread_impl_for_worker_scheduler.h" | 5 #include "public/platform/scheduler/child/webthread_impl_for_worker_scheduler.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
9 #include "platform/scheduler/child/web_scheduler_impl.h" | 9 #include "platform/scheduler/child/web_scheduler_impl.h" |
10 #include "platform/scheduler/child/worker_scheduler_impl.h" | 10 #include "platform/scheduler/child/worker_scheduler_impl.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 WebThreadImplForWorkerSchedulerTest() {} | 91 WebThreadImplForWorkerSchedulerTest() {} |
92 | 92 |
93 ~WebThreadImplForWorkerSchedulerTest() override {} | 93 ~WebThreadImplForWorkerSchedulerTest() override {} |
94 | 94 |
95 void SetUp() override { | 95 void SetUp() override { |
96 thread_.reset(new WebThreadImplForWorkerScheduler("test thread")); | 96 thread_.reset(new WebThreadImplForWorkerScheduler("test thread")); |
97 thread_->Init(); | 97 thread_->Init(); |
98 } | 98 } |
99 | 99 |
100 void RunOnWorkerThread(const tracked_objects::Location& from_here, | 100 void RunOnWorkerThread(const tracked_objects::Location& from_here, |
101 const base::Closure& task) { | 101 base::OnceClosure task) { |
102 base::WaitableEvent completion( | 102 base::WaitableEvent completion( |
103 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 103 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
104 base::WaitableEvent::InitialState::NOT_SIGNALED); | 104 base::WaitableEvent::InitialState::NOT_SIGNALED); |
105 thread_->GetTaskRunner()->PostTask( | 105 thread_->GetTaskRunner()->PostTask( |
106 from_here, | 106 from_here, |
107 base::Bind(&WebThreadImplForWorkerSchedulerTest::RunOnWorkerThreadTask, | 107 base::BindOnce(&WebThreadImplForWorkerSchedulerTest::RunOnWorkerThreadTa
sk, |
108 base::Unretained(this), task, &completion)); | 108 base::Unretained(this), std::move(task), &completion)); |
109 completion.Wait(); | 109 completion.Wait(); |
110 } | 110 } |
111 | 111 |
112 protected: | 112 protected: |
113 void RunOnWorkerThreadTask(const base::Closure& task, | 113 void RunOnWorkerThreadTask(base::OnceClosure task, |
114 base::WaitableEvent* completion) { | 114 base::WaitableEvent* completion) { |
115 task.Run(); | 115 std::move(task).Run(); |
116 completion->Signal(); | 116 completion->Signal(); |
117 } | 117 } |
118 | 118 |
119 std::unique_ptr<WebThreadImplForWorkerScheduler> thread_; | 119 std::unique_ptr<WebThreadImplForWorkerScheduler> thread_; |
120 | 120 |
121 DISALLOW_COPY_AND_ASSIGN(WebThreadImplForWorkerSchedulerTest); | 121 DISALLOW_COPY_AND_ASSIGN(WebThreadImplForWorkerSchedulerTest); |
122 }; | 122 }; |
123 | 123 |
124 TEST_F(WebThreadImplForWorkerSchedulerTest, TestDefaultTask) { | 124 TEST_F(WebThreadImplForWorkerSchedulerTest, TestDefaultTask) { |
125 std::unique_ptr<MockTask> task(new MockTask()); | 125 std::unique_ptr<MockTask> task(new MockTask()); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 RunOnWorkerThread(FROM_HERE, base::Bind(&shutdownOnThread, thread_.get())); | 199 RunOnWorkerThread(FROM_HERE, base::Bind(&shutdownOnThread, thread_.get())); |
200 thread_->getWebTaskRunner()->postTask(blink::WebTraceLocation(), | 200 thread_->getWebTaskRunner()->postTask(blink::WebTraceLocation(), |
201 task.release()); | 201 task.release()); |
202 thread_->getWebTaskRunner()->postDelayedTask(blink::WebTraceLocation(), | 202 thread_->getWebTaskRunner()->postDelayedTask(blink::WebTraceLocation(), |
203 task.release(), 50ll); | 203 task.release(), 50ll); |
204 thread_.reset(); | 204 thread_.reset(); |
205 } | 205 } |
206 | 206 |
207 } // namespace scheduler | 207 } // namespace scheduler |
208 } // namespace blink | 208 } // namespace blink |
OLD | NEW |