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 #include "content/renderer/shared_worker/embedded_shared_worker_stub.h" | 5 #include "content/renderer/shared_worker/embedded_shared_worker_stub.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 Send(new WorkerHostMsg_WorkerReadyForInspection(route_id_)); | 185 Send(new WorkerHostMsg_WorkerReadyForInspection(route_id_)); |
186 } | 186 } |
187 | 187 |
188 void EmbeddedSharedWorkerStub::workerScriptLoaded() { | 188 void EmbeddedSharedWorkerStub::workerScriptLoaded() { |
189 Send(new WorkerHostMsg_WorkerScriptLoaded(route_id_)); | 189 Send(new WorkerHostMsg_WorkerScriptLoaded(route_id_)); |
190 running_ = true; | 190 running_ = true; |
191 // Process any pending connections. | 191 // Process any pending connections. |
192 for (PendingChannelList::const_iterator iter = pending_channels_.begin(); | 192 for (PendingChannelList::const_iterator iter = pending_channels_.begin(); |
193 iter != pending_channels_.end(); | 193 iter != pending_channels_.end(); |
194 ++iter) { | 194 ++iter) { |
195 ConnectToChannel(*iter); | 195 ConnectToChannel(iter->first, iter->second); |
196 } | 196 } |
197 pending_channels_.clear(); | 197 pending_channels_.clear(); |
198 } | 198 } |
199 | 199 |
200 void EmbeddedSharedWorkerStub::workerScriptLoadFailed() { | 200 void EmbeddedSharedWorkerStub::workerScriptLoadFailed() { |
201 Send(new WorkerHostMsg_WorkerScriptLoadFailed(route_id_)); | 201 Send(new WorkerHostMsg_WorkerScriptLoadFailed(route_id_)); |
202 for (PendingChannelList::const_iterator iter = pending_channels_.begin(); | 202 for (PendingChannelList::const_iterator iter = pending_channels_.begin(); |
203 iter != pending_channels_.end(); | 203 iter != pending_channels_.end(); |
204 ++iter) { | 204 ++iter) { |
205 blink::WebMessagePortChannel* channel = *iter; | 205 delete iter->second; |
206 channel->destroy(); | |
207 } | 206 } |
208 pending_channels_.clear(); | 207 pending_channels_.clear(); |
209 Shutdown(); | 208 Shutdown(); |
210 } | 209 } |
211 | 210 |
212 void EmbeddedSharedWorkerStub::workerContextClosed() { | 211 void EmbeddedSharedWorkerStub::workerContextClosed() { |
213 Send(new WorkerHostMsg_WorkerContextClosed(route_id_)); | 212 Send(new WorkerHostMsg_WorkerContextClosed(route_id_)); |
214 } | 213 } |
215 | 214 |
216 void EmbeddedSharedWorkerStub::workerContextDestroyed() { | 215 void EmbeddedSharedWorkerStub::workerContextDestroyed() { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 // when this is called. | 289 // when this is called. |
291 impl_ = nullptr; | 290 impl_ = nullptr; |
292 delete this; | 291 delete this; |
293 } | 292 } |
294 | 293 |
295 bool EmbeddedSharedWorkerStub::Send(IPC::Message* message) { | 294 bool EmbeddedSharedWorkerStub::Send(IPC::Message* message) { |
296 return RenderThreadImpl::current()->Send(message); | 295 return RenderThreadImpl::current()->Send(message); |
297 } | 296 } |
298 | 297 |
299 void EmbeddedSharedWorkerStub::ConnectToChannel( | 298 void EmbeddedSharedWorkerStub::ConnectToChannel( |
299 int connection_request_id, | |
300 WebMessagePortChannelImpl* channel) { | 300 WebMessagePortChannelImpl* channel) { |
301 impl_->connect(channel); | 301 impl_->connect(channel); |
Ken Rockot(use gerrit already)
2017/01/23 23:20:41
I think we should send the WorkerConnected message
| |
302 Send( | 302 Send(new WorkerHostMsg_WorkerConnected(connection_request_id, route_id_)); |
303 new WorkerHostMsg_WorkerConnected(channel->message_port_id(), route_id_)); | |
304 } | 303 } |
305 | 304 |
306 void EmbeddedSharedWorkerStub::OnConnect(int port, | 305 void EmbeddedSharedWorkerStub::OnConnect(int connection_request_id, |
307 int routing_id) { | 306 const MessagePort& port) { |
308 WebMessagePortChannelImpl* channel = new WebMessagePortChannelImpl( | 307 WebMessagePortChannelImpl* channel = new WebMessagePortChannelImpl(port); |
309 routing_id, port, base::ThreadTaskRunnerHandle::Get().get()); | |
310 if (running_) { | 308 if (running_) { |
311 ConnectToChannel(channel); | 309 ConnectToChannel(connection_request_id, channel); |
312 } else { | 310 } else { |
313 // If two documents try to load a SharedWorker at the same time, the | 311 // If two documents try to load a SharedWorker at the same time, the |
314 // WorkerMsg_Connect for one of the documents can come in before the | 312 // WorkerMsg_Connect for one of the documents can come in before the |
315 // worker is started. Just queue up the connect and deliver it once the | 313 // worker is started. Just queue up the connect and deliver it once the |
316 // worker starts. | 314 // worker starts. |
317 pending_channels_.push_back(channel); | 315 pending_channels_.push_back(std::make_pair(connection_request_id, channel)); |
318 } | 316 } |
319 } | 317 } |
320 | 318 |
321 void EmbeddedSharedWorkerStub::OnTerminateWorkerContext() { | 319 void EmbeddedSharedWorkerStub::OnTerminateWorkerContext() { |
322 // After this we wouldn't get any IPC for this stub. | 320 // After this we wouldn't get any IPC for this stub. |
323 running_ = false; | 321 running_ = false; |
324 impl_->terminateWorkerContext(); | 322 impl_->terminateWorkerContext(); |
325 } | 323 } |
326 | 324 |
327 } // namespace content | 325 } // namespace content |
OLD | NEW |