Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "content/child/scheduler/webthread_impl_for_worker_scheduler.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/synchronization/waitable_event.h" | |
| 9 #include "content/child/scheduler/scheduler_message_loop_delegate.h" | |
| 10 #include "content/child/scheduler/worker_scheduler_impl.h" | |
| 11 #include "third_party/WebKit/public/platform/WebTraceLocation.h" | |
| 12 | |
| 13 namespace content { | |
| 14 | |
| 15 WebThreadImplForWorkerScheduler::WebThreadImplForWorkerScheduler( | |
| 16 const char* name) | |
| 17 : thread_(new base::Thread(name)) { | |
| 18 thread_->Start(); | |
| 19 | |
| 20 base::WaitableEvent completion(false, false); | |
| 21 thread_->message_loop()->PostTask( | |
| 22 FROM_HERE, base::Bind(&WebThreadImplForWorkerScheduler::InitOnThread, | |
| 23 base::Unretained(this), &completion)); | |
| 24 completion.Wait(); | |
| 25 } | |
| 26 | |
| 27 WebThreadImplForWorkerScheduler::~WebThreadImplForWorkerScheduler() { | |
| 28 base::WaitableEvent completion(false, false); | |
| 29 // We need to post the shutdown task on the scheduler's task queue or tasks | |
| 30 // posted on the worker scheduler may not get run when the thread is deleted. | |
| 31 TaskRunner()->PostTask( | |
|
Sami
2015/04/13 17:38:49
In other words this shutdown task mustn't be allow
| |
| 32 FROM_HERE, base::Bind(&WebThreadImplForWorkerScheduler::ShutDownOnThread, | |
| 33 base::Unretained(this), &completion)); | |
| 34 completion.Wait(); | |
| 35 | |
| 36 thread_->Stop(); | |
| 37 } | |
| 38 | |
| 39 void WebThreadImplForWorkerScheduler::InitOnThread( | |
| 40 base::WaitableEvent* completion) { | |
| 41 worker_scheduler_ = WorkerScheduler::Create(thread_->message_loop()); | |
| 42 worker_scheduler_->Init(); | |
| 43 task_runner_ = worker_scheduler_->DefaultTaskRunner(); | |
| 44 idle_task_runner_ = worker_scheduler_->IdleTaskRunner(); | |
| 45 completion->Signal(); | |
| 46 } | |
| 47 | |
| 48 void WebThreadImplForWorkerScheduler::ShutDownOnThread( | |
| 49 base::WaitableEvent* completion) { | |
| 50 task_runner_ = nullptr; | |
| 51 idle_task_runner_ = nullptr; | |
| 52 worker_scheduler_.reset(nullptr); | |
| 53 completion->Signal(); | |
| 54 } | |
| 55 | |
| 56 blink::PlatformThreadId WebThreadImplForWorkerScheduler::threadId() const { | |
| 57 return thread_->thread_id(); | |
| 58 } | |
| 59 | |
| 60 base::MessageLoop* WebThreadImplForWorkerScheduler::MessageLoop() const { | |
| 61 // As per WebThreadImpl::MessageLoop() | |
| 62 return nullptr; | |
| 63 } | |
| 64 | |
| 65 base::SingleThreadTaskRunner* WebThreadImplForWorkerScheduler::TaskRunner() | |
| 66 const { | |
| 67 return task_runner_.get(); | |
| 68 } | |
| 69 | |
| 70 SingleThreadIdleTaskRunner* WebThreadImplForWorkerScheduler::IdleTaskRunner() | |
| 71 const { | |
| 72 return idle_task_runner_.get(); | |
| 73 } | |
| 74 | |
| 75 void WebThreadImplForWorkerScheduler::AddTaskObserverInternal( | |
| 76 base::MessageLoop::TaskObserver* observer) { | |
| 77 worker_scheduler_->AddTaskObserver(observer); | |
| 78 } | |
| 79 | |
| 80 void WebThreadImplForWorkerScheduler::RemoveTaskObserverInternal( | |
| 81 base::MessageLoop::TaskObserver* observer) { | |
| 82 worker_scheduler_->RemoveTaskObserver(observer); | |
| 83 } | |
| 84 | |
| 85 } // namespace content | |
| OLD | NEW |