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" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/message_loop/message_loop.h" | |
13 #include "base/pending_task.h" | 12 #include "base/pending_task.h" |
14 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
15 #include "third_party/WebKit/public/platform/WebTraceLocation.h" | 14 #include "third_party/WebKit/public/platform/WebTraceLocation.h" |
16 | 15 |
17 namespace content { | 16 namespace content { |
18 | 17 |
19 class WebThreadBase::TaskObserverAdapter | 18 class WebThreadBase::TaskObserverAdapter |
20 : public base::MessageLoop::TaskObserver { | 19 : public base::MessageLoop::TaskObserver { |
21 public: | 20 public: |
22 TaskObserverAdapter(WebThread::TaskObserver* observer) | 21 TaskObserverAdapter(WebThread::TaskObserver* observer) |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 Task* task, | 109 Task* task, |
111 long long delay_ms) { | 110 long long delay_ms) { |
112 tracked_objects::Location location(web_location.functionName(), | 111 tracked_objects::Location location(web_location.functionName(), |
113 web_location.fileName(), -1, nullptr); | 112 web_location.fileName(), -1, nullptr); |
114 TaskRunner()->PostDelayedTask( | 113 TaskRunner()->PostDelayedTask( |
115 location, | 114 location, |
116 base::Bind(RunWebThreadTask, base::Passed(make_scoped_ptr(task))), | 115 base::Bind(RunWebThreadTask, base::Passed(make_scoped_ptr(task))), |
117 base::TimeDelta::FromMilliseconds(delay_ms)); | 116 base::TimeDelta::FromMilliseconds(delay_ms)); |
118 } | 117 } |
119 | 118 |
120 void WebThreadBase::enterRunLoop() { | 119 void WebThreadBase::enterRunLoop() { |
kinuko
2015/02/27 09:54:27
Is this now used only for unit tests? If so I'd ju
Sami
2015/02/27 17:23:08
There are a handful of tests on the Blink side whi
sadrul
2015/03/01 10:21:38
I have filed http://crbug.com/462927 to remove ent
| |
121 CHECK(isCurrentThread()); | 120 CHECK(isCurrentThread()); |
121 CHECK(MessageLoop()); | |
122 CHECK(!MessageLoop()->is_running()); // We don't support nesting. | 122 CHECK(!MessageLoop()->is_running()); // We don't support nesting. |
123 MessageLoop()->Run(); | 123 MessageLoop()->Run(); |
124 } | 124 } |
125 | 125 |
126 void WebThreadBase::exitRunLoop() { | 126 void WebThreadBase::exitRunLoop() { |
127 CHECK(isCurrentThread()); | 127 CHECK(isCurrentThread()); |
128 CHECK(MessageLoop()); | |
128 CHECK(MessageLoop()->is_running()); | 129 CHECK(MessageLoop()->is_running()); |
129 MessageLoop()->Quit(); | 130 MessageLoop()->Quit(); |
130 } | 131 } |
131 | 132 |
132 bool WebThreadBase::isCurrentThread() const { | 133 bool WebThreadBase::isCurrentThread() const { |
133 return TaskRunner()->BelongsToCurrentThread(); | 134 return TaskRunner()->BelongsToCurrentThread(); |
134 } | 135 } |
135 | 136 |
136 blink::PlatformThreadId WebThreadImpl::threadId() const { | 137 blink::PlatformThreadId WebThreadImpl::threadId() const { |
137 return thread_->thread_id(); | 138 return thread_->thread_id(); |
138 } | 139 } |
139 | 140 |
140 WebThreadImpl::WebThreadImpl(const char* name) | 141 WebThreadImpl::WebThreadImpl(const char* name) |
141 : thread_(new base::Thread(name)) { | 142 : thread_(new base::Thread(name)) { |
142 thread_->Start(); | 143 thread_->Start(); |
143 } | 144 } |
144 | 145 |
145 WebThreadImpl::~WebThreadImpl() { | 146 WebThreadImpl::~WebThreadImpl() { |
146 thread_->Stop(); | 147 thread_->Stop(); |
147 } | 148 } |
148 | 149 |
149 base::MessageLoop* WebThreadImpl::MessageLoop() const { | 150 base::MessageLoop* WebThreadImpl::MessageLoop() const { |
150 return thread_->message_loop(); | 151 return nullptr; |
151 } | 152 } |
152 | 153 |
153 base::SingleThreadTaskRunner* WebThreadImpl::TaskRunner() const { | 154 base::SingleThreadTaskRunner* WebThreadImpl::TaskRunner() const { |
154 return thread_->message_loop_proxy().get(); | 155 return thread_->message_loop_proxy().get(); |
155 } | 156 } |
156 | 157 |
157 WebThreadImplForMessageLoop::WebThreadImplForMessageLoop( | |
158 scoped_refptr<base::SingleThreadTaskRunner> owning_thread_task_runner) | |
159 : owning_thread_task_runner_(owning_thread_task_runner), | |
160 thread_id_(base::PlatformThread::CurrentId()) { | |
161 } | |
162 | |
163 blink::PlatformThreadId WebThreadImplForMessageLoop::threadId() const { | |
164 return thread_id_; | |
165 } | |
166 | |
167 WebThreadImplForMessageLoop::~WebThreadImplForMessageLoop() { | |
168 } | |
169 | |
170 base::MessageLoop* WebThreadImplForMessageLoop::MessageLoop() const { | |
171 DCHECK(isCurrentThread()); | |
172 return base::MessageLoop::current(); | |
173 } | |
174 | |
175 base::SingleThreadTaskRunner* WebThreadImplForMessageLoop::TaskRunner() const { | |
176 return owning_thread_task_runner_.get(); | |
177 } | |
178 | |
179 } // namespace content | 158 } // namespace content |
OLD | NEW |