diff options
author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-24 00:04:33 +0000 |
---|---|---|
committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-24 00:04:33 +0000 |
commit | 8569eafc863900c15ba3df7da5b05ac8ec145ec5 (patch) | |
tree | 13b680d773e8197182be85917625d5e4c0fb1a3c /chrome/browser/extensions/extension_message_service.cc | |
parent | 1669e4d96e503460e2888320c5dc6d3217234599 (diff) | |
download | chromium_src-8569eafc863900c15ba3df7da5b05ac8ec145ec5.zip chromium_src-8569eafc863900c15ba3df7da5b05ac8ec145ec5.tar.gz chromium_src-8569eafc863900c15ba3df7da5b05ac8ec145ec5.tar.bz2 |
Another try at enabling the content script messaging test.
Also fixes some issues that that test exposes.
My previous attempt (http://src.chromium.org/viewvc/chrome?view=rev&revision=21324) was reverted.
TEST=no
BUG=no
Review URL: http://codereview.chromium.org/160048
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21483 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_message_service.cc')
-rw-r--r-- | chrome/browser/extensions/extension_message_service.cc | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/chrome/browser/extensions/extension_message_service.cc b/chrome/browser/extensions/extension_message_service.cc index 5424ad2..d4e6d0f 100644 --- a/chrome/browser/extensions/extension_message_service.cc +++ b/chrome/browser/extensions/extension_message_service.cc @@ -130,15 +130,23 @@ void ExtensionMessageService::ProfileDestroyed() { void ExtensionMessageService::AddEventListener(std::string event_name, int render_process_id) { + DCHECK(RenderProcessHost::FromID(render_process_id)) << + "Adding event listener to a non-existant RenderProcessHost."; DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); - DCHECK(listeners_[event_name].count(render_process_id) == 0); + DCHECK_EQ(listeners_[event_name].count(render_process_id), 0u) << event_name; listeners_[event_name].insert(render_process_id); } void ExtensionMessageService::RemoveEventListener(std::string event_name, int render_process_id) { + // It is possible that this RenderProcessHost is being destroyed. If that is + // the case, we'll have already removed his listeners, so do nothing here. + RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id); + if (!rph) + return; + DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); - DCHECK(listeners_[event_name].count(render_process_id) == 1); + DCHECK_EQ(listeners_[event_name].count(render_process_id), 1u) << event_name; listeners_[event_name].erase(render_process_id); } @@ -245,9 +253,15 @@ void ExtensionMessageService::OpenChannelOnUIThreadImpl( DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); // TODO(mpcomplete): notify source if reciever doesn't exist - if (!source || !receiver.sender) + if (!source) return; // Closed while in flight. + if (!receiver.sender) { + // Treat it as a disconnect. + DispatchOnDisconnect(MessagePort(source, MSG_ROUTING_CONTROL), + GET_OPPOSITE_PORT_ID(receiver_port_id)); + } + linked_ptr<MessageChannel> channel(new MessageChannel); channel->opener = MessagePort(source, MSG_ROUTING_CONTROL); channel->receiver = receiver; |