Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1813)

Side by Side Diff: content/renderer/shared_worker/embedded_shared_worker_stub.cc

Issue 2422793002: HTML MessagePort as mojo::MessagePipeHandle (Closed)
Patch Set: Address feedback from yusuf Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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::workerContextClosed() { 203 void EmbeddedSharedWorkerStub::workerContextClosed() {
213 Send(new WorkerHostMsg_WorkerContextClosed(route_id_)); 204 Send(new WorkerHostMsg_WorkerContextClosed(route_id_));
214 } 205 }
215 206
216 void EmbeddedSharedWorkerStub::workerContextDestroyed() { 207 void EmbeddedSharedWorkerStub::workerContextDestroyed() {
217 Send(new WorkerHostMsg_WorkerContextDestroyed(route_id_)); 208 Send(new WorkerHostMsg_WorkerContextDestroyed(route_id_));
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 // when this is called. 281 // when this is called.
291 impl_ = nullptr; 282 impl_ = nullptr;
292 delete this; 283 delete this;
293 } 284 }
294 285
295 bool EmbeddedSharedWorkerStub::Send(IPC::Message* message) { 286 bool EmbeddedSharedWorkerStub::Send(IPC::Message* message) {
296 return RenderThreadImpl::current()->Send(message); 287 return RenderThreadImpl::current()->Send(message);
297 } 288 }
298 289
299 void EmbeddedSharedWorkerStub::ConnectToChannel( 290 void EmbeddedSharedWorkerStub::ConnectToChannel(
300 WebMessagePortChannelImpl* channel) { 291 int connection_request_id,
301 impl_->connect(channel); 292 std::unique_ptr<WebMessagePortChannelImpl> channel) {
302 Send( 293 impl_->connect(channel.release());
303 new WorkerHostMsg_WorkerConnected(channel->message_port_id(), route_id_)); 294 Send(new WorkerHostMsg_WorkerConnected(connection_request_id, route_id_));
304 } 295 }
305 296
306 void EmbeddedSharedWorkerStub::OnConnect(int port, 297 void EmbeddedSharedWorkerStub::OnConnect(int connection_request_id,
307 int routing_id) { 298 const MessagePort& port) {
308 WebMessagePortChannelImpl* channel = new WebMessagePortChannelImpl( 299 auto channel = base::MakeUnique<WebMessagePortChannelImpl>(port);
309 routing_id, port, base::ThreadTaskRunnerHandle::Get().get());
310 if (running_) { 300 if (running_) {
311 ConnectToChannel(channel); 301 ConnectToChannel(connection_request_id, std::move(channel));
312 } else { 302 } else {
313 // If two documents try to load a SharedWorker at the same time, the 303 // 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 304 // 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 305 // worker is started. Just queue up the connect and deliver it once the
316 // worker starts. 306 // worker starts.
317 pending_channels_.push_back(channel); 307 pending_channels_.emplace_back(
308 std::make_pair(connection_request_id, std::move(channel)));
318 } 309 }
319 } 310 }
320 311
321 void EmbeddedSharedWorkerStub::OnTerminateWorkerContext() { 312 void EmbeddedSharedWorkerStub::OnTerminateWorkerContext() {
322 // After this we wouldn't get any IPC for this stub. 313 // After this we wouldn't get any IPC for this stub.
323 running_ = false; 314 running_ = false;
324 impl_->terminateWorkerContext(); 315 impl_->terminateWorkerContext();
325 } 316 }
326 317
327 } // namespace content 318 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698