OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/worker_host/message_port_dispatcher.h" | 5 #include "chrome/browser/worker_host/message_port_dispatcher.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/singleton.h" | 8 #include "base/singleton.h" |
9 #include "chrome/browser/browser_thread.h" | 9 #include "chrome/browser/browser_thread.h" |
10 #include "chrome/browser/renderer_host/resource_message_filter.h" | 10 #include "chrome/browser/renderer_host/resource_message_filter.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 // send along with the message. | 188 // send along with the message. |
189 std::vector<int> new_routing_ids(sent_message_port_ids.size()); | 189 std::vector<int> new_routing_ids(sent_message_port_ids.size()); |
190 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { | 190 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { |
191 new_routing_ids[i] = entangled_port.next_routing_id->Run(); | 191 new_routing_ids[i] = entangled_port.next_routing_id->Run(); |
192 sent_ports[i]->sender = entangled_port.sender; | 192 sent_ports[i]->sender = entangled_port.sender; |
193 | 193 |
194 // Update the entry for the sent port as it can be in a different process. | 194 // Update the entry for the sent port as it can be in a different process. |
195 sent_ports[i]->route_id = new_routing_ids[i]; | 195 sent_ports[i]->route_id = new_routing_ids[i]; |
196 } | 196 } |
197 | 197 |
198 // Now send the message to the entangled port. | 198 if (entangled_port.sender) { |
199 IPC::Message* ipc_msg = new WorkerProcessMsg_Message( | 199 // Now send the message to the entangled port. |
200 entangled_port.route_id, message, sent_message_port_ids, | 200 IPC::Message* ipc_msg = new WorkerProcessMsg_Message( |
201 new_routing_ids); | 201 entangled_port.route_id, message, sent_message_port_ids, |
202 entangled_port.sender->Send(ipc_msg); | 202 new_routing_ids); |
| 203 entangled_port.sender->Send(ipc_msg); |
| 204 } |
203 } | 205 } |
204 } | 206 } |
205 | 207 |
206 void MessagePortDispatcher::OnQueueMessages(int message_port_id) { | 208 void MessagePortDispatcher::OnQueueMessages(int message_port_id) { |
207 if (!message_ports_.count(message_port_id)) { | 209 if (!message_ports_.count(message_port_id)) { |
208 NOTREACHED(); | 210 NOTREACHED(); |
209 return; | 211 return; |
210 } | 212 } |
211 | 213 |
212 MessagePort& port = message_ports_[message_port_id]; | 214 MessagePort& port = message_ports_[message_port_id]; |
213 port.sender->Send(new WorkerProcessMsg_MessagesQueued(port.route_id)); | 215 if (port.sender) { |
214 port.queue_messages = true; | 216 port.sender->Send(new WorkerProcessMsg_MessagesQueued(port.route_id)); |
215 port.sender = NULL; | 217 port.queue_messages = true; |
| 218 port.sender = NULL; |
| 219 } |
216 } | 220 } |
217 | 221 |
218 void MessagePortDispatcher::OnSendQueuedMessages( | 222 void MessagePortDispatcher::OnSendQueuedMessages( |
219 int message_port_id, | 223 int message_port_id, |
220 const QueuedMessages& queued_messages) { | 224 const QueuedMessages& queued_messages) { |
221 if (!message_ports_.count(message_port_id)) { | 225 if (!message_ports_.count(message_port_id)) { |
222 NOTREACHED(); | 226 NOTREACHED(); |
223 return; | 227 return; |
224 } | 228 } |
225 | 229 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 int entangled_id = erase_item->second.entangled_message_port_id; | 283 int entangled_id = erase_item->second.entangled_message_port_id; |
280 if (entangled_id != MSG_ROUTING_NONE) { | 284 if (entangled_id != MSG_ROUTING_NONE) { |
281 // Do the disentanglement (and be paranoid about the other side existing | 285 // Do the disentanglement (and be paranoid about the other side existing |
282 // just in case something unusual happened during entanglement). | 286 // just in case something unusual happened during entanglement). |
283 if (message_ports_.count(entangled_id)) { | 287 if (message_ports_.count(entangled_id)) { |
284 message_ports_[entangled_id].entangled_message_port_id = MSG_ROUTING_NONE; | 288 message_ports_[entangled_id].entangled_message_port_id = MSG_ROUTING_NONE; |
285 } | 289 } |
286 } | 290 } |
287 message_ports_.erase(erase_item); | 291 message_ports_.erase(erase_item); |
288 } | 292 } |
OLD | NEW |