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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 } | 182 } |
183 | 183 |
184 void EmbeddedSharedWorkerStub::workerReadyForInspection() { | 184 void EmbeddedSharedWorkerStub::workerReadyForInspection() { |
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 (auto& item : pending_channels_) |
193 iter != pending_channels_.end(); | 193 ConnectToChannel(item.first, std::move(item.second)); |
194 ++iter) { | |
195 ConnectToChannel(*iter); | |
196 } | |
197 pending_channels_.clear(); | 194 pending_channels_.clear(); |
198 } | 195 } |
199 | 196 |
200 void EmbeddedSharedWorkerStub::workerScriptLoadFailed() { | 197 void EmbeddedSharedWorkerStub::workerScriptLoadFailed() { |
201 Send(new WorkerHostMsg_WorkerScriptLoadFailed(route_id_)); | 198 Send(new WorkerHostMsg_WorkerScriptLoadFailed(route_id_)); |
202 for (PendingChannelList::const_iterator iter = pending_channels_.begin(); | |
203 iter != pending_channels_.end(); | |
204 ++iter) { | |
205 blink::WebMessagePortChannel* channel = *iter; | |
206 channel->destroy(); | |
207 } | |
208 pending_channels_.clear(); | 199 pending_channels_.clear(); |
209 Shutdown(); | 200 Shutdown(); |
210 } | 201 } |
211 | 202 |
212 void EmbeddedSharedWorkerStub::countFeature(uint32_t feature) { | 203 void EmbeddedSharedWorkerStub::countFeature(uint32_t feature) { |
213 Send(new WorkerHostMsg_CountFeature(route_id_, feature)); | 204 Send(new WorkerHostMsg_CountFeature(route_id_, feature)); |
214 } | 205 } |
215 | 206 |
216 void EmbeddedSharedWorkerStub::workerContextClosed() { | 207 void EmbeddedSharedWorkerStub::workerContextClosed() { |
217 Send(new WorkerHostMsg_WorkerContextClosed(route_id_)); | 208 Send(new WorkerHostMsg_WorkerContextClosed(route_id_)); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 // when this is called. | 285 // when this is called. |
295 impl_ = nullptr; | 286 impl_ = nullptr; |
296 delete this; | 287 delete this; |
297 } | 288 } |
298 | 289 |
299 bool EmbeddedSharedWorkerStub::Send(IPC::Message* message) { | 290 bool EmbeddedSharedWorkerStub::Send(IPC::Message* message) { |
300 return RenderThreadImpl::current()->Send(message); | 291 return RenderThreadImpl::current()->Send(message); |
301 } | 292 } |
302 | 293 |
303 void EmbeddedSharedWorkerStub::ConnectToChannel( | 294 void EmbeddedSharedWorkerStub::ConnectToChannel( |
304 WebMessagePortChannelImpl* channel) { | 295 int connection_request_id, |
305 impl_->connect(channel); | 296 std::unique_ptr<WebMessagePortChannelImpl> channel) { |
306 Send( | 297 impl_->connect(channel.release()); |
307 new WorkerHostMsg_WorkerConnected(channel->message_port_id(), route_id_)); | 298 Send(new WorkerHostMsg_WorkerConnected(connection_request_id, route_id_)); |
308 } | 299 } |
309 | 300 |
310 void EmbeddedSharedWorkerStub::OnConnect(int port, | 301 void EmbeddedSharedWorkerStub::OnConnect(int connection_request_id, |
311 int routing_id) { | 302 const MessagePort& port) { |
312 WebMessagePortChannelImpl* channel = new WebMessagePortChannelImpl( | 303 auto channel = base::MakeUnique<WebMessagePortChannelImpl>(port); |
313 routing_id, port, base::ThreadTaskRunnerHandle::Get().get()); | |
314 if (running_) { | 304 if (running_) { |
315 ConnectToChannel(channel); | 305 ConnectToChannel(connection_request_id, std::move(channel)); |
316 } else { | 306 } else { |
317 // If two documents try to load a SharedWorker at the same time, the | 307 // If two documents try to load a SharedWorker at the same time, the |
318 // WorkerMsg_Connect for one of the documents can come in before the | 308 // WorkerMsg_Connect for one of the documents can come in before the |
319 // worker is started. Just queue up the connect and deliver it once the | 309 // worker is started. Just queue up the connect and deliver it once the |
320 // worker starts. | 310 // worker starts. |
321 pending_channels_.push_back(channel); | 311 pending_channels_.emplace_back( |
| 312 std::make_pair(connection_request_id, std::move(channel))); |
322 } | 313 } |
323 } | 314 } |
324 | 315 |
325 void EmbeddedSharedWorkerStub::OnTerminateWorkerContext() { | 316 void EmbeddedSharedWorkerStub::OnTerminateWorkerContext() { |
326 // After this we wouldn't get any IPC for this stub. | 317 // After this we wouldn't get any IPC for this stub. |
327 running_ = false; | 318 running_ = false; |
328 impl_->terminateWorkerContext(); | 319 impl_->terminateWorkerContext(); |
329 } | 320 } |
330 | 321 |
331 } // namespace content | 322 } // namespace content |
OLD | NEW |