| 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/singleton.h" | 7 #include "base/singleton.h" |
| 8 #include "chrome/browser/renderer_host/resource_message_filter.h" | 8 #include "chrome/browser/renderer_host/resource_message_filter.h" |
| 9 #include "chrome/browser/worker_host/worker_process_host.h" | 9 #include "chrome/browser/worker_host/worker_process_host.h" |
| 10 #include "chrome/common/notification_service.h" | 10 #include "chrome/common/notification_service.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 NOTREACHED(); | 110 NOTREACHED(); |
| 111 return; | 111 return; |
| 112 } | 112 } |
| 113 | 113 |
| 114 DCHECK(message_ports_[remote_message_port_id].entangled_message_port_id == | 114 DCHECK(message_ports_[remote_message_port_id].entangled_message_port_id == |
| 115 MSG_ROUTING_NONE); | 115 MSG_ROUTING_NONE); |
| 116 message_ports_[remote_message_port_id].entangled_message_port_id = | 116 message_ports_[remote_message_port_id].entangled_message_port_id = |
| 117 local_message_port_id; | 117 local_message_port_id; |
| 118 } | 118 } |
| 119 | 119 |
| 120 void MessagePortDispatcher::OnPostMessage(int sender_message_port_id, | 120 void MessagePortDispatcher::OnPostMessage( |
| 121 const string16& message, | 121 int sender_message_port_id, |
| 122 int sent_message_port_id) { | 122 const string16& message, |
| 123 const std::vector<int>& sent_message_port_ids) { |
| 123 if (!message_ports_.count(sender_message_port_id)) { | 124 if (!message_ports_.count(sender_message_port_id)) { |
| 124 NOTREACHED(); | 125 NOTREACHED(); |
| 125 return; | 126 return; |
| 126 } | 127 } |
| 127 | 128 |
| 128 int entangled_message_port_id = | 129 int entangled_message_port_id = |
| 129 message_ports_[sender_message_port_id].entangled_message_port_id; | 130 message_ports_[sender_message_port_id].entangled_message_port_id; |
| 130 if (entangled_message_port_id == MSG_ROUTING_NONE) | 131 if (entangled_message_port_id == MSG_ROUTING_NONE) |
| 131 return; // Process could have crashed. | 132 return; // Process could have crashed. |
| 132 | 133 |
| 133 if (!message_ports_.count(entangled_message_port_id)) { | 134 if (!message_ports_.count(entangled_message_port_id)) { |
| 134 NOTREACHED(); | 135 NOTREACHED(); |
| 135 return; | 136 return; |
| 136 } | 137 } |
| 137 | 138 |
| 138 PostMessageTo(entangled_message_port_id, message, sent_message_port_id); | 139 PostMessageTo(entangled_message_port_id, message, sent_message_port_ids); |
| 139 } | 140 } |
| 140 | 141 |
| 141 void MessagePortDispatcher::PostMessageTo(int message_port_id, | 142 void MessagePortDispatcher::PostMessageTo( |
| 142 const string16& message, | 143 int message_port_id, |
| 143 int sent_message_port_id) { | 144 const string16& message, |
| 144 if (!message_ports_.count(message_port_id) || | 145 const std::vector<int>& sent_message_port_ids) { |
| 145 (sent_message_port_id != MSG_ROUTING_NONE && | 146 if (!message_ports_.count(message_port_id)) { |
| 146 !message_ports_.count(sent_message_port_id))) { | |
| 147 NOTREACHED(); | 147 NOTREACHED(); |
| 148 return; | 148 return; |
| 149 } | 149 } |
| 150 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { |
| 151 if (!message_ports_.count(sent_message_port_ids[i])) { |
| 152 NOTREACHED(); |
| 153 return; |
| 154 } |
| 155 } |
| 150 | 156 |
| 151 MessagePort& entangled_port = message_ports_[message_port_id]; | 157 MessagePort& entangled_port = message_ports_[message_port_id]; |
| 152 | 158 |
| 153 MessagePort* sent_port = NULL; | 159 std::vector<MessagePort*> sent_ports(sent_message_port_ids.size()); |
| 154 if (sent_message_port_id != MSG_ROUTING_NONE) { | 160 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { |
| 155 sent_port = &message_ports_[sent_message_port_id]; | 161 sent_ports[i] = &message_ports_[sent_message_port_ids[i]]; |
| 156 sent_port->queue_messages = true; | 162 sent_ports[i]->queue_messages = true; |
| 157 } | 163 } |
| 158 | 164 |
| 159 if (entangled_port.queue_messages) { | 165 if (entangled_port.queue_messages) { |
| 160 entangled_port.queued_messages.push_back( | 166 entangled_port.queued_messages.push_back( |
| 161 std::make_pair(message, sent_message_port_id)); | 167 std::make_pair(message, sent_message_port_ids)); |
| 162 } else { | 168 } else { |
| 163 // If a message port was sent around, the new location will need a routing | 169 // If a message port was sent around, the new location will need a routing |
| 164 // id. Instead of having the created port send us a sync message to get it, | 170 // id. Instead of having the created port send us a sync message to get it, |
| 165 // send along with the message. | 171 // send along with the message. |
| 166 int new_routing_id = MSG_ROUTING_NONE; | 172 std::vector<int> new_routing_ids(sent_message_port_ids.size()); |
| 167 if (sent_message_port_id != MSG_ROUTING_NONE) { | 173 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { |
| 168 new_routing_id = entangled_port.next_routing_id->Run(); | 174 new_routing_ids[i] = entangled_port.next_routing_id->Run(); |
| 169 sent_port->sender = entangled_port.sender; | 175 sent_ports[i]->sender = entangled_port.sender; |
| 170 | 176 |
| 171 // Update the entry for the sent port as it can be in a different process. | 177 // Update the entry for the sent port as it can be in a different process. |
| 172 sent_port->route_id = new_routing_id; | 178 sent_ports[i]->route_id = new_routing_ids[i]; |
| 173 } | 179 } |
| 174 | 180 |
| 175 // Now send the message to the entangled port. | 181 // Now send the message to the entangled port. |
| 176 IPC::Message* ipc_msg = new WorkerProcessMsg_Message( | 182 IPC::Message* ipc_msg = new WorkerProcessMsg_Message( |
| 177 entangled_port.route_id, message, sent_message_port_id, | 183 entangled_port.route_id, message, sent_message_port_ids, |
| 178 new_routing_id); | 184 new_routing_ids); |
| 179 entangled_port.sender->Send(ipc_msg); | 185 entangled_port.sender->Send(ipc_msg); |
| 180 } | 186 } |
| 181 } | 187 } |
| 182 | 188 |
| 183 void MessagePortDispatcher::OnQueueMessages(int message_port_id) { | 189 void MessagePortDispatcher::OnQueueMessages(int message_port_id) { |
| 184 if (!message_ports_.count(message_port_id)) { | 190 if (!message_ports_.count(message_port_id)) { |
| 185 NOTREACHED(); | 191 NOTREACHED(); |
| 186 return; | 192 return; |
| 187 } | 193 } |
| 188 | 194 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 MessagePorts::iterator cur_item = iter++; | 237 MessagePorts::iterator cur_item = iter++; |
| 232 if (cur_item->second.sender == sender) { | 238 if (cur_item->second.sender == sender) { |
| 233 if (cur_item->second.entangled_message_port_id != MSG_ROUTING_NONE) { | 239 if (cur_item->second.entangled_message_port_id != MSG_ROUTING_NONE) { |
| 234 message_ports_[cur_item->second.entangled_message_port_id]. | 240 message_ports_[cur_item->second.entangled_message_port_id]. |
| 235 entangled_message_port_id = MSG_ROUTING_NONE; | 241 entangled_message_port_id = MSG_ROUTING_NONE; |
| 236 } | 242 } |
| 237 message_ports_.erase(cur_item); | 243 message_ports_.erase(cur_item); |
| 238 } | 244 } |
| 239 } | 245 } |
| 240 } | 246 } |
| OLD | NEW |