OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/glue/webthread_impl.h" | 8 #include "webkit/glue/webthread_impl.h" |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 63 } |
64 | 64 |
65 void WebThreadImpl::postDelayedTask( | 65 void WebThreadImpl::postDelayedTask( |
66 Task* task, long long delay_ms) { | 66 Task* task, long long delay_ms) { |
67 thread_->message_loop()->PostDelayedTask( | 67 thread_->message_loop()->PostDelayedTask( |
68 FROM_HERE, | 68 FROM_HERE, |
69 base::Bind(&WebKit::WebThread::Task::run, base::Owned(task)), | 69 base::Bind(&WebKit::WebThread::Task::run, base::Owned(task)), |
70 base::TimeDelta::FromMilliseconds(delay_ms)); | 70 base::TimeDelta::FromMilliseconds(delay_ms)); |
71 } | 71 } |
72 | 72 |
| 73 void WebThreadImpl::enterRunLoop() { |
| 74 CHECK(IsCurrentThread()); |
| 75 CHECK(!thread_->message_loop()->is_running()); // We don't support nesting. |
| 76 thread_->message_loop()->Run(); |
| 77 } |
| 78 |
| 79 void WebThreadImpl::exitRunLoop() { |
| 80 CHECK(IsCurrentThread()); |
| 81 CHECK(thread_->message_loop()->is_running()); |
| 82 thread_->message_loop()->Quit(); |
| 83 } |
| 84 |
73 bool WebThreadImpl::IsCurrentThread() const { | 85 bool WebThreadImpl::IsCurrentThread() const { |
74 return thread_->thread_id() == base::PlatformThread::CurrentId(); | 86 return thread_->thread_id() == base::PlatformThread::CurrentId(); |
75 } | 87 } |
76 | 88 |
77 WebThreadImpl::~WebThreadImpl() { | 89 WebThreadImpl::~WebThreadImpl() { |
78 thread_->Stop(); | 90 thread_->Stop(); |
79 } | 91 } |
80 | 92 |
81 WebThreadImplForMessageLoop::WebThreadImplForMessageLoop( | 93 WebThreadImplForMessageLoop::WebThreadImplForMessageLoop( |
82 base::MessageLoopProxy* message_loop) | 94 base::MessageLoopProxy* message_loop) |
83 : message_loop_(message_loop) { | 95 : message_loop_(message_loop) { |
84 } | 96 } |
85 | 97 |
86 void WebThreadImplForMessageLoop::postTask(Task* task) { | 98 void WebThreadImplForMessageLoop::postTask(Task* task) { |
87 message_loop_->PostTask( | 99 message_loop_->PostTask( |
88 FROM_HERE, base::Bind(&WebKit::WebThread::Task::run, base::Owned(task))); | 100 FROM_HERE, base::Bind(&WebKit::WebThread::Task::run, base::Owned(task))); |
89 } | 101 } |
90 | 102 |
91 void WebThreadImplForMessageLoop::postDelayedTask( | 103 void WebThreadImplForMessageLoop::postDelayedTask( |
92 Task* task, long long delay_ms) { | 104 Task* task, long long delay_ms) { |
93 message_loop_->PostDelayedTask( | 105 message_loop_->PostDelayedTask( |
94 FROM_HERE, | 106 FROM_HERE, |
95 base::Bind(&WebKit::WebThread::Task::run, base::Owned(task)), | 107 base::Bind(&WebKit::WebThread::Task::run, base::Owned(task)), |
96 delay_ms); | 108 delay_ms); |
97 } | 109 } |
98 | 110 |
| 111 void WebThreadImplForMessageLoop::enterRunLoop() { |
| 112 CHECK(IsCurrentThread()); |
| 113 CHECK(!MessageLoop::current()->is_running()); // We don't support nesting. |
| 114 MessageLoop::current()->Run(); |
| 115 } |
| 116 |
| 117 void WebThreadImplForMessageLoop::exitRunLoop() { |
| 118 CHECK(IsCurrentThread()); |
| 119 CHECK(MessageLoop::current()->is_running()); |
| 120 MessageLoop::current()->Quit(); |
| 121 } |
| 122 |
99 bool WebThreadImplForMessageLoop::IsCurrentThread() const { | 123 bool WebThreadImplForMessageLoop::IsCurrentThread() const { |
100 return message_loop_->BelongsToCurrentThread(); | 124 return message_loop_->BelongsToCurrentThread(); |
101 } | 125 } |
102 | 126 |
103 WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() { | 127 WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() { |
104 } | 128 } |
105 | 129 |
106 } | 130 } |
OLD | NEW |