Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/singleton.h" | 7 #include "base/singleton.h" |
| 8 #include "chrome/browser/chrome_thread.h" | 8 #include "chrome/browser/chrome_thread.h" |
| 9 #include "chrome/browser/extensions/extension.h" | 9 #include "chrome/browser/extensions/extension.h" |
| 10 #include "chrome/browser/extensions/extension_view.h" | 10 #include "chrome/browser/extensions/extension_view.h" |
| 11 #include "chrome/browser/renderer_host/render_view_host.h" | 11 #include "chrome/browser/renderer_host/render_view_host.h" |
| 12 #include "chrome/browser/renderer_host/render_process_host.h" | 12 #include "chrome/browser/renderer_host/render_process_host.h" |
| 13 #include "chrome/browser/renderer_host/resource_message_filter.h" | 13 #include "chrome/browser/renderer_host/resource_message_filter.h" |
| 14 #include "chrome/common/notification_service.h" | |
| 14 #include "chrome/common/render_messages.h" | 15 #include "chrome/common/render_messages.h" |
| 15 #include "chrome/common/stl_util-inl.h" | 16 #include "chrome/common/stl_util-inl.h" |
| 16 | 17 |
| 17 // Since we have 2 ports for every channel, we just index channels by half the | 18 // Since we have 2 ports for every channel, we just index channels by half the |
| 18 // port ID. | 19 // port ID. |
| 19 #define GET_CHANNEL_ID(port_id) ((port_id) / 2) | 20 #define GET_CHANNEL_ID(port_id) ((port_id) / 2) |
| 20 | 21 |
| 21 // Port1 is always even, port2 is always odd. | 22 // Port1 is always even, port2 is always odd. |
| 22 #define IS_PORT1_ID(port_id) (((port_id) & 1) == 0) | 23 #define IS_PORT1_ID(port_id) (((port_id) & 1) == 0) |
| 23 | 24 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 } | 126 } |
| 126 | 127 |
| 127 int source_port_id = GET_OPPOSITE_PORT_ID(port_id); | 128 int source_port_id = GET_OPPOSITE_PORT_ID(port_id); |
| 128 dest->Send(new ViewMsg_ExtensionHandleMessage(message, source_port_id)); | 129 dest->Send(new ViewMsg_ExtensionHandleMessage(message, source_port_id)); |
| 129 } | 130 } |
| 130 | 131 |
| 131 void ExtensionMessageService::RendererReady(ResourceMessageFilter* renderer) { | 132 void ExtensionMessageService::RendererReady(ResourceMessageFilter* renderer) { |
| 132 AutoLock lock(renderers_lock_); | 133 AutoLock lock(renderers_lock_); |
| 133 DCHECK(renderers_.find(renderer->GetProcessId()) == renderers_.end()); | 134 DCHECK(renderers_.find(renderer->GetProcessId()) == renderers_.end()); |
| 134 renderers_[renderer->GetProcessId()] = renderer; | 135 renderers_[renderer->GetProcessId()] = renderer; |
| 136 | |
| 137 NotificationService::current()->AddObserver( | |
|
Matt Perry
2009/04/17 23:31:02
This doesn't work. RendererReady is called on the
| |
| 138 this, | |
| 139 NotificationType::RESOURCE_MESSAGE_FILTER_SHUTDOWN, | |
| 140 Source<ResourceMessageFilter>(renderer)); | |
| 135 } | 141 } |
| 136 | 142 |
| 137 void ExtensionMessageService::RendererShutdown( | 143 void ExtensionMessageService::Observe(NotificationType type, |
| 138 ResourceMessageFilter* renderer) { | 144 const NotificationSource& source, |
| 145 const NotificationDetails& details) { | |
| 146 DCHECK(type.value == NotificationType::RESOURCE_MESSAGE_FILTER_SHUTDOWN); | |
| 147 ResourceMessageFilter* filter = Source<ResourceMessageFilter>(source).ptr(); | |
| 148 | |
| 139 { | 149 { |
| 140 AutoLock lock(renderers_lock_); | 150 AutoLock lock(renderers_lock_); |
| 141 DCHECK(renderers_.find(renderer->GetProcessId()) != renderers_.end()); | 151 DCHECK(renderers_.find(filter->GetProcessId()) != renderers_.end()); |
| 142 renderers_.erase(renderer->GetProcessId()); | 152 renderers_.erase(filter->GetProcessId()); |
| 143 } | 153 } |
| 144 | 154 |
| 145 // Close any channels that share this filter. | 155 // Close any channels that share this filter. |
| 146 // TODO(mpcomplete): should we notify the other side of the port? | 156 // TODO(mpcomplete): should we notify the other side of the port? |
| 147 for (MessageChannelMap::iterator it = channels_.begin(); | 157 for (MessageChannelMap::iterator it = channels_.begin(); |
| 148 it != channels_.end(); ) { | 158 it != channels_.end(); ) { |
| 149 MessageChannelMap::iterator current = it++; | 159 MessageChannelMap::iterator current = it++; |
| 150 if (current->second.port1 == renderer || current->second.port2 == renderer) | 160 if (current->second.port1 == filter || current->second.port2 == filter) |
| 151 channels_.erase(current); | 161 channels_.erase(current); |
| 152 } | 162 } |
| 163 | |
| 164 NotificationService::current()->RemoveObserver( | |
| 165 this, | |
| 166 NotificationType::RESOURCE_MESSAGE_FILTER_SHUTDOWN, | |
| 167 Source<ResourceMessageFilter>(filter)); | |
| 153 } | 168 } |
| 169 | |
| OLD | NEW |