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

Side by Side Diff: content/browser/message_port_service.cc

Issue 1974613002: Remove code that was only used by navigator.connect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix comment Created 4 years, 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/browser/message_port_service.h" 5 #include "content/browser/message_port_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "content/common/message_port_messages.h" 9 #include "content/common/message_port_messages.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 } 144 }
145 145
146 DCHECK(message_ports_[remote_message_port_id].entangled_message_port_id == 146 DCHECK(message_ports_[remote_message_port_id].entangled_message_port_id ==
147 MSG_ROUTING_NONE); 147 MSG_ROUTING_NONE);
148 message_ports_[remote_message_port_id].entangled_message_port_id = 148 message_ports_[remote_message_port_id].entangled_message_port_id =
149 local_message_port_id; 149 local_message_port_id;
150 } 150 }
151 151
152 void MessagePortService::PostMessage( 152 void MessagePortService::PostMessage(
153 int sender_message_port_id, 153 int sender_message_port_id,
154 const MessagePortMessage& message, 154 const base::string16& message,
155 const std::vector<TransferredMessagePort>& sent_message_ports) { 155 const std::vector<int>& sent_message_ports) {
156 DCHECK_CURRENTLY_ON(BrowserThread::IO); 156 DCHECK_CURRENTLY_ON(BrowserThread::IO);
157 if (!message_ports_.count(sender_message_port_id)) { 157 if (!message_ports_.count(sender_message_port_id)) {
158 NOTREACHED(); 158 NOTREACHED();
159 return; 159 return;
160 } 160 }
161 161
162 int entangled_message_port_id = 162 int entangled_message_port_id =
163 message_ports_[sender_message_port_id].entangled_message_port_id; 163 message_ports_[sender_message_port_id].entangled_message_port_id;
164 if (entangled_message_port_id == MSG_ROUTING_NONE) 164 if (entangled_message_port_id == MSG_ROUTING_NONE)
165 return; // Process could have crashed. 165 return; // Process could have crashed.
166 166
167 if (!message_ports_.count(entangled_message_port_id)) { 167 if (!message_ports_.count(entangled_message_port_id)) {
168 NOTREACHED(); 168 NOTREACHED();
169 return; 169 return;
170 } 170 }
171 171
172 PostMessageTo(entangled_message_port_id, message, sent_message_ports); 172 PostMessageTo(entangled_message_port_id, message, sent_message_ports);
173 } 173 }
174 174
175 void MessagePortService::PostMessageTo( 175 void MessagePortService::PostMessageTo(
176 int message_port_id, 176 int message_port_id,
177 const MessagePortMessage& message, 177 const base::string16& message,
178 const std::vector<TransferredMessagePort>& sent_message_ports) { 178 const std::vector<int>& sent_message_ports) {
179 if (!message_ports_.count(message_port_id)) { 179 if (!message_ports_.count(message_port_id)) {
180 NOTREACHED(); 180 NOTREACHED();
181 return; 181 return;
182 } 182 }
183 for (size_t i = 0; i < sent_message_ports.size(); ++i) { 183 for (size_t i = 0; i < sent_message_ports.size(); ++i) {
184 if (!message_ports_.count(sent_message_ports[i].id)) { 184 if (!message_ports_.count(sent_message_ports[i])) {
185 NOTREACHED(); 185 NOTREACHED();
186 return; 186 return;
187 } 187 }
188 } 188 }
189 189
190 MessagePort& entangled_port = message_ports_[message_port_id]; 190 MessagePort& entangled_port = message_ports_[message_port_id];
191 if (entangled_port.queue_messages()) { 191 if (entangled_port.queue_messages()) {
192 // If the target port is currently holding messages because the destination 192 // If the target port is currently holding messages because the destination
193 // renderer isn't available yet, all message ports being sent should also be 193 // renderer isn't available yet, all message ports being sent should also be
194 // put in this state. 194 // put in this state.
195 if (entangled_port.hold_messages_for_destination) { 195 if (entangled_port.hold_messages_for_destination) {
196 for (const auto& port : sent_message_ports) 196 for (const auto& port : sent_message_ports)
197 HoldMessages(port.id); 197 HoldMessages(port);
198 } 198 }
199 entangled_port.queued_messages.push_back( 199 entangled_port.queued_messages.push_back(
200 std::make_pair(message, sent_message_ports)); 200 std::make_pair(message, sent_message_ports));
201 return; 201 return;
202 } 202 }
203 203
204 if (!entangled_port.delegate) { 204 if (!entangled_port.delegate) {
205 NOTREACHED(); 205 NOTREACHED();
206 return; 206 return;
207 } 207 }
(...skipping 29 matching lines...) Expand all
237 237
238 // Send the queued messages to the port again. This time they'll reach the 238 // Send the queued messages to the port again. This time they'll reach the
239 // new location. 239 // new location.
240 MessagePort& port = message_ports_[message_port_id]; 240 MessagePort& port = message_ports_[message_port_id];
241 port.queue_for_inflight_messages = false; 241 port.queue_for_inflight_messages = false;
242 242
243 // If the port is currently holding messages waiting for the target renderer, 243 // If the port is currently holding messages waiting for the target renderer,
244 // all ports in messages being sent to the port should also be put on hold. 244 // all ports in messages being sent to the port should also be put on hold.
245 if (port.hold_messages_for_destination) { 245 if (port.hold_messages_for_destination) {
246 for (const auto& message : queued_messages) 246 for (const auto& message : queued_messages)
247 for (const TransferredMessagePort& sent_port : message.second) 247 for (int sent_port : message.second)
248 HoldMessages(sent_port.id); 248 HoldMessages(sent_port);
249 } 249 }
250 250
251 port.queued_messages.insert(port.queued_messages.begin(), 251 port.queued_messages.insert(port.queued_messages.begin(),
252 queued_messages.begin(), 252 queued_messages.begin(),
253 queued_messages.end()); 253 queued_messages.end());
254 254
255 if (port.should_be_destroyed) 255 if (port.should_be_destroyed)
256 ClosePort(message_port_id); 256 ClosePort(message_port_id);
257 else 257 else
258 SendQueuedMessagesIfPossible(message_port_id); 258 SendQueuedMessagesIfPossible(message_port_id);
(...skipping 19 matching lines...) Expand all
278 278
279 void MessagePortService::HoldMessages(int message_port_id) { 279 void MessagePortService::HoldMessages(int message_port_id) {
280 DCHECK_CURRENTLY_ON(BrowserThread::IO); 280 DCHECK_CURRENTLY_ON(BrowserThread::IO);
281 if (!message_ports_.count(message_port_id)) { 281 if (!message_ports_.count(message_port_id)) {
282 NOTREACHED(); 282 NOTREACHED();
283 return; 283 return;
284 } 284 }
285 285
286 // Any ports in messages currently in the queue should also be put on hold. 286 // Any ports in messages currently in the queue should also be put on hold.
287 for (const auto& message : message_ports_[message_port_id].queued_messages) 287 for (const auto& message : message_ports_[message_port_id].queued_messages)
288 for (const TransferredMessagePort& sent_port : message.second) 288 for (int sent_port : message.second)
289 HoldMessages(sent_port.id); 289 HoldMessages(sent_port);
290 290
291 message_ports_[message_port_id].hold_messages_for_destination = true; 291 message_ports_[message_port_id].hold_messages_for_destination = true;
292 } 292 }
293 293
294 bool MessagePortService::AreMessagesHeld(int message_port_id) { 294 bool MessagePortService::AreMessagesHeld(int message_port_id) {
295 DCHECK_CURRENTLY_ON(BrowserThread::IO); 295 DCHECK_CURRENTLY_ON(BrowserThread::IO);
296 if (!message_ports_.count(message_port_id)) 296 if (!message_ports_.count(message_port_id))
297 return false; 297 return false;
298 return message_ports_[message_port_id].hold_messages_for_destination; 298 return message_ports_[message_port_id].hold_messages_for_destination;
299 } 299 }
300 300
301 void MessagePortService::ClosePort(int message_port_id) { 301 void MessagePortService::ClosePort(int message_port_id) {
302 DCHECK_CURRENTLY_ON(BrowserThread::IO); 302 DCHECK_CURRENTLY_ON(BrowserThread::IO);
303 if (!message_ports_.count(message_port_id)) { 303 if (!message_ports_.count(message_port_id)) {
304 NOTREACHED(); 304 NOTREACHED();
305 return; 305 return;
306 } 306 }
307 307
308 if (message_ports_[message_port_id].queue_for_inflight_messages) { 308 if (message_ports_[message_port_id].queue_for_inflight_messages) {
309 message_ports_[message_port_id].should_be_destroyed = true; 309 message_ports_[message_port_id].should_be_destroyed = true;
310 return; 310 return;
311 } 311 }
312 312
313 // First close any message ports in the queue for this message port. 313 // First close any message ports in the queue for this message port.
314 for (const auto& message : message_ports_[message_port_id].queued_messages) 314 for (const auto& message : message_ports_[message_port_id].queued_messages)
315 for (const TransferredMessagePort& sent_port : message.second) 315 for (int sent_port : message.second)
316 ClosePort(sent_port.id); 316 ClosePort(sent_port);
317 317
318 Erase(message_port_id); 318 Erase(message_port_id);
319 } 319 }
320 320
321 void MessagePortService::ReleaseMessages(int message_port_id) { 321 void MessagePortService::ReleaseMessages(int message_port_id) {
322 DCHECK_CURRENTLY_ON(BrowserThread::IO); 322 DCHECK_CURRENTLY_ON(BrowserThread::IO);
323 if (!message_ports_.count(message_port_id)) { 323 if (!message_ports_.count(message_port_id)) {
324 NOTREACHED(); 324 NOTREACHED();
325 return; 325 return;
326 } 326 }
(...skipping 11 matching lines...) Expand all
338 // Do the disentanglement (and be paranoid about the other side existing 338 // Do the disentanglement (and be paranoid about the other side existing
339 // just in case something unusual happened during entanglement). 339 // just in case something unusual happened during entanglement).
340 if (message_ports_.count(entangled_id)) { 340 if (message_ports_.count(entangled_id)) {
341 message_ports_[entangled_id].entangled_message_port_id = MSG_ROUTING_NONE; 341 message_ports_[entangled_id].entangled_message_port_id = MSG_ROUTING_NONE;
342 } 342 }
343 } 343 }
344 message_ports_.erase(erase_item); 344 message_ports_.erase(erase_item);
345 } 345 }
346 346
347 } // namespace content 347 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/message_port_service.h ('k') | content/browser/service_worker/service_worker_dispatcher_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698