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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_message_service.cc
===================================================================
--- chrome/browser/extensions/extension_message_service.cc (revision 18701)
+++ chrome/browser/extensions/extension_message_service.cc (working copy)
@@ -291,15 +291,30 @@
return port2_id;
}
-void ExtensionMessageService::CloseAutomationChannel(int port_id) {
+void ExtensionMessageService::CloseChannel(int port_id) {
DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI);
- // TODO(siggi): Cleanup from the tab seems to beat this to the punch.
- // DCHECK(channels_[GET_CHANNEL_ID(port_id)].port1 != NULL);
- // TODO(siggi): should we notify the other side of the port?
- channels_.erase(GET_CHANNEL_ID(port_id));
+ // Note: The channel might be gone already, if the other side closed first.
+ MessageChannelMap::iterator it = channels_.find(GET_CHANNEL_ID(port_id));
+ if (it != channels_.end())
+ CloseChannelImpl(it, port_id);
}
+void ExtensionMessageService::CloseChannelImpl(
+ MessageChannelMap::iterator channel_iter, int port_id) {
+ DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI);
+
+ // Notify the other side.
+ if (port_id == GET_CHANNEL_PORT1(channel_iter->first)) {
+ DispatchOnDisconnect(channel_iter->second.port2, port_id);
+ } else {
+ DCHECK_EQ(port_id, GET_CHANNEL_PORT2(channel_iter->first));
+ DispatchOnDisconnect(channel_iter->second.port1, port_id);
+ }
+
+ channels_.erase(channel_iter);
+}
+
void ExtensionMessageService::PostMessageFromRenderer(
int port_id, const std::string& message) {
DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI);
@@ -366,13 +381,9 @@
it != channels_.end(); ) {
MessageChannelMap::iterator current = it++;
if (current->second.port1 == renderer) {
- DispatchOnDisconnect(current->second.port2,
- GET_CHANNEL_PORT1(current->first));
- channels_.erase(current);
+ CloseChannelImpl(current, GET_CHANNEL_PORT1(current->first));
} else if (current->second.port2 == renderer) {
- DispatchOnDisconnect(current->second.port1,
- GET_CHANNEL_PORT2(current->first));
- channels_.erase(current);
+ CloseChannelImpl(current, GET_CHANNEL_PORT2(current->first));
}
}
}
« 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