| 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 "content/child/webthread_impl.h" | 8 #include "content/child/webthread_impl.h" |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 90 |
| 91 blink::PlatformThreadId WebThreadImpl::threadId() const { | 91 blink::PlatformThreadId WebThreadImpl::threadId() const { |
| 92 return thread_->thread_id(); | 92 return thread_->thread_id(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 WebThreadImpl::~WebThreadImpl() { | 95 WebThreadImpl::~WebThreadImpl() { |
| 96 thread_->Stop(); | 96 thread_->Stop(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 WebThreadImplForMessageLoop::WebThreadImplForMessageLoop( | 99 WebThreadImplForMessageLoop::WebThreadImplForMessageLoop( |
| 100 base::MessageLoopProxy* message_loop) | 100 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) |
| 101 : message_loop_(message_loop), | 101 : main_thread_task_runner_(main_thread_task_runner), |
| 102 thread_id_(base::PlatformThread::CurrentId()) {} | 102 thread_id_(base::PlatformThread::CurrentId()) {} |
| 103 | 103 |
| 104 void WebThreadImplForMessageLoop::postTask(Task* task) { | 104 void WebThreadImplForMessageLoop::postTask(Task* task) { |
| 105 message_loop_->PostTask( | 105 main_thread_task_runner_->PostTask( |
| 106 FROM_HERE, base::Bind(&blink::WebThread::Task::run, base::Owned(task))); | 106 FROM_HERE, base::Bind(&blink::WebThread::Task::run, base::Owned(task))); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void WebThreadImplForMessageLoop::postDelayedTask(Task* task, | 109 void WebThreadImplForMessageLoop::postDelayedTask(Task* task, |
| 110 long long delay_ms) { | 110 long long delay_ms) { |
| 111 message_loop_->PostDelayedTask( | 111 main_thread_task_runner_->PostDelayedTask( |
| 112 FROM_HERE, | 112 FROM_HERE, |
| 113 base::Bind(&blink::WebThread::Task::run, base::Owned(task)), | 113 base::Bind(&blink::WebThread::Task::run, base::Owned(task)), |
| 114 base::TimeDelta::FromMilliseconds(delay_ms)); | 114 base::TimeDelta::FromMilliseconds(delay_ms)); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void WebThreadImplForMessageLoop::enterRunLoop() { | 117 void WebThreadImplForMessageLoop::enterRunLoop() { |
| 118 CHECK(isCurrentThread()); | 118 CHECK(isCurrentThread()); |
| 119 // We don't support nesting. | 119 // We don't support nesting. |
| 120 CHECK(!base::MessageLoop::current()->is_running()); | 120 CHECK(!base::MessageLoop::current()->is_running()); |
| 121 base::MessageLoop::current()->Run(); | 121 base::MessageLoop::current()->Run(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 void WebThreadImplForMessageLoop::exitRunLoop() { | 124 void WebThreadImplForMessageLoop::exitRunLoop() { |
| 125 CHECK(isCurrentThread()); | 125 CHECK(isCurrentThread()); |
| 126 CHECK(base::MessageLoop::current()->is_running()); | 126 CHECK(base::MessageLoop::current()->is_running()); |
| 127 base::MessageLoop::current()->Quit(); | 127 base::MessageLoop::current()->Quit(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 bool WebThreadImplForMessageLoop::isCurrentThread() const { | 130 bool WebThreadImplForMessageLoop::isCurrentThread() const { |
| 131 return message_loop_->BelongsToCurrentThread(); | 131 return main_thread_task_runner_->BelongsToCurrentThread(); |
| 132 } | 132 } |
| 133 | 133 |
| 134 blink::PlatformThreadId WebThreadImplForMessageLoop::threadId() const { | 134 blink::PlatformThreadId WebThreadImplForMessageLoop::threadId() const { |
| 135 return thread_id_; | 135 return thread_id_; |
| 136 } | 136 } |
| 137 | 137 |
| 138 WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() {} | 138 WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() {} |
| 139 | 139 |
| 140 } // namespace content | 140 } // namespace content |
| OLD | NEW |