| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // An implementation of WebThread in terms of base::MessageLoop and | 5 // An implementation of WebThread in terms of base::MessageLoop and |
| 6 // base::Thread | 6 // base::Thread |
| 7 | 7 |
| 8 #include "public/platform/scheduler/child/webthread_base.h" | 8 #include "public/platform/scheduler/child/webthread_base.h" |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/pending_task.h" | 13 #include "base/pending_task.h" |
| 14 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
| 15 #include "platform/scheduler/child/webthread_impl_for_worker_scheduler.h" |
| 16 #include "public/platform/WebTraceLocation.h" |
| 17 #include "public/platform/scheduler/child/compositor_worker_scheduler.h" |
| 15 #include "public/platform/scheduler/child/single_thread_idle_task_runner.h" | 18 #include "public/platform/scheduler/child/single_thread_idle_task_runner.h" |
| 16 #include "public/platform/WebTraceLocation.h" | |
| 17 | 19 |
| 18 namespace blink { | 20 namespace blink { |
| 19 namespace scheduler { | 21 namespace scheduler { |
| 20 | 22 |
| 21 class WebThreadBase::TaskObserverAdapter | 23 class WebThreadBase::TaskObserverAdapter |
| 22 : public base::MessageLoop::TaskObserver { | 24 : public base::MessageLoop::TaskObserver { |
| 23 public: | 25 public: |
| 24 explicit TaskObserverAdapter(WebThread::TaskObserver* observer) | 26 explicit TaskObserverAdapter(WebThread::TaskObserver* observer) |
| 25 : observer_(observer) {} | 27 : observer_(observer) {} |
| 26 | 28 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 IdleTask* idle_task) { | 95 IdleTask* idle_task) { |
| 94 GetIdleTaskRunner()->PostIdleTask( | 96 GetIdleTaskRunner()->PostIdleTask( |
| 95 location, base::Bind(&WebThreadBase::RunWebThreadIdleTask, | 97 location, base::Bind(&WebThreadBase::RunWebThreadIdleTask, |
| 96 base::Passed(base::WrapUnique(idle_task)))); | 98 base::Passed(base::WrapUnique(idle_task)))); |
| 97 } | 99 } |
| 98 | 100 |
| 99 bool WebThreadBase::IsCurrentThread() const { | 101 bool WebThreadBase::IsCurrentThread() const { |
| 100 return GetTaskRunner()->BelongsToCurrentThread(); | 102 return GetTaskRunner()->BelongsToCurrentThread(); |
| 101 } | 103 } |
| 102 | 104 |
| 105 namespace { |
| 106 |
| 107 class WebThreadForCompositor : public WebThreadImplForWorkerScheduler { |
| 108 public: |
| 109 explicit WebThreadForCompositor(base::Thread::Options options) |
| 110 : WebThreadImplForWorkerScheduler("Compositor", options) { |
| 111 Init(); |
| 112 } |
| 113 ~WebThreadForCompositor() override {} |
| 114 |
| 115 private: |
| 116 // WebThreadImplForWorkerScheduler: |
| 117 std::unique_ptr<blink::scheduler::WorkerScheduler> CreateWorkerScheduler() |
| 118 override { |
| 119 return base::MakeUnique<CompositorWorkerScheduler>(GetThread()); |
| 120 } |
| 121 |
| 122 DISALLOW_COPY_AND_ASSIGN(WebThreadForCompositor); |
| 123 }; |
| 124 |
| 125 } // namespace |
| 126 |
| 127 std::unique_ptr<WebThreadBase> WebThreadBase::CreateWorkerThread( |
| 128 const char* name, |
| 129 base::Thread::Options options) { |
| 130 return base::MakeUnique<WebThreadImplForWorkerScheduler>(name, options); |
| 131 } |
| 132 |
| 133 std::unique_ptr<WebThreadBase> WebThreadBase::CreateCompositorThread( |
| 134 base::Thread::Options options) { |
| 135 return base::MakeUnique<WebThreadForCompositor>(options); |
| 136 } |
| 137 |
| 103 } // namespace scheduler | 138 } // namespace scheduler |
| 104 } // namespace blink | 139 } // namespace blink |
| OLD | NEW |