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

Side by Side Diff: chrome/browser/extensions/extension_message_service.cc

Issue 125280: Send port-closed notification when a frame with ports unloads.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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 | Annotate | Revision Log
OLDNEW
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/extensions/extension_message_service.h" 5 #include "chrome/browser/extensions/extension_message_service.h"
6 6
7 #include "base/json_writer.h" 7 #include "base/json_writer.h"
8 #include "base/singleton.h" 8 #include "base/singleton.h"
9 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 // describe the originating tab to the target extension. 284 // describe the originating tab to the target extension.
285 // This isn't really appropriate here, the originating tab 285 // This isn't really appropriate here, the originating tab
286 // information should be supplied by the caller for 286 // information should be supplied by the caller for
287 // automation-initiated ports. 287 // automation-initiated ports.
288 OpenChannelOnUIThreadImpl(routing_id, port1_id, source, port2_id, 288 OpenChannelOnUIThreadImpl(routing_id, port1_id, source, port2_id,
289 process_id, source_process_id); 289 process_id, source_process_id);
290 290
291 return port2_id; 291 return port2_id;
292 } 292 }
293 293
294 void ExtensionMessageService::CloseAutomationChannel(int port_id) { 294 void ExtensionMessageService::CloseChannel(int port_id) {
295 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); 295 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI);
296 296
297 // TODO(siggi): Cleanup from the tab seems to beat this to the punch. 297 // Note: The channel might be gone already, if the other side closed first.
298 // DCHECK(channels_[GET_CHANNEL_ID(port_id)].port1 != NULL); 298 MessageChannelMap::iterator it = channels_.find(GET_CHANNEL_ID(port_id));
299 // TODO(siggi): should we notify the other side of the port? 299 if (it != channels_.end())
300 channels_.erase(GET_CHANNEL_ID(port_id)); 300 CloseChannelImpl(it, port_id);
301 }
302
303 void ExtensionMessageService::CloseChannelImpl(
304 MessageChannelMap::iterator channel_iter, int port_id) {
305 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI);
306
307 // Notify the other side.
308 if (port_id == GET_CHANNEL_PORT1(channel_iter->first)) {
309 DispatchOnDisconnect(channel_iter->second.port2, port_id);
310 } else {
311 DCHECK_EQ(port_id, GET_CHANNEL_PORT2(channel_iter->first));
312 DispatchOnDisconnect(channel_iter->second.port1, port_id);
313 }
314
315 channels_.erase(channel_iter);
301 } 316 }
302 317
303 void ExtensionMessageService::PostMessageFromRenderer( 318 void ExtensionMessageService::PostMessageFromRenderer(
304 int port_id, const std::string& message) { 319 int port_id, const std::string& message) {
305 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); 320 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI);
306 321
307 MessageChannelMap::iterator iter = 322 MessageChannelMap::iterator iter =
308 channels_.find(GET_CHANNEL_ID(port_id)); 323 channels_.find(GET_CHANNEL_ID(port_id));
309 if (iter == channels_.end()) 324 if (iter == channels_.end())
310 return; 325 return;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 } 374 }
360 } 375 }
361 } 376 }
362 377
363 // Close any channels that share this renderer. We notify the opposite 378 // Close any channels that share this renderer. We notify the opposite
364 // port that his pair has closed. 379 // port that his pair has closed.
365 for (MessageChannelMap::iterator it = channels_.begin(); 380 for (MessageChannelMap::iterator it = channels_.begin();
366 it != channels_.end(); ) { 381 it != channels_.end(); ) {
367 MessageChannelMap::iterator current = it++; 382 MessageChannelMap::iterator current = it++;
368 if (current->second.port1 == renderer) { 383 if (current->second.port1 == renderer) {
369 DispatchOnDisconnect(current->second.port2, 384 CloseChannelImpl(current, GET_CHANNEL_PORT1(current->first));
370 GET_CHANNEL_PORT1(current->first));
371 channels_.erase(current);
372 } else if (current->second.port2 == renderer) { 385 } else if (current->second.port2 == renderer) {
373 DispatchOnDisconnect(current->second.port1, 386 CloseChannelImpl(current, GET_CHANNEL_PORT2(current->first));
374 GET_CHANNEL_PORT2(current->first));
375 channels_.erase(current);
376 } 387 }
377 } 388 }
378 } 389 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_message_service.h ('k') | chrome/browser/renderer_host/browser_render_process_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698