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

Unified Diff: chrome/browser/extensions/extension_message_service.cc

Issue 150125: Send port disconnect events when a frame is unloaded. (Closed)
Patch Set: from linux 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
diff --git a/chrome/browser/extensions/extension_message_service.cc b/chrome/browser/extensions/extension_message_service.cc
index 7a65078ee78a818b6f7d7f5e894b8a35ae50c3ca..0ee45798f5cc339a8ad16a0b7386b59a882f3875 100644
--- a/chrome/browser/extensions/extension_message_service.cc
+++ b/chrome/browser/extensions/extension_message_service.cc
@@ -290,13 +290,28 @@ int ExtensionMessageService::OpenAutomationChannelToExtension(
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(
@@ -365,13 +380,9 @@ void ExtensionMessageService::Observe(NotificationType type,
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