| 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/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/values.h" | 10 #include "base/values.h" |
| 10 #include "chrome/browser/chrome_thread.h" | 11 #include "chrome/browser/chrome_thread.h" |
| 11 #include "chrome/browser/extensions/extension.h" | 12 #include "chrome/browser/extensions/extension.h" |
| 12 #include "chrome/browser/extensions/extension_tabs_module.h" | 13 #include "chrome/browser/extensions/extension_tabs_module.h" |
| 13 #include "chrome/browser/extensions/extension_view.h" | 14 #include "chrome/browser/extensions/extension_view.h" |
| 14 #include "chrome/browser/renderer_host/render_view_host.h" | 15 #include "chrome/browser/renderer_host/render_view_host.h" |
| 15 #include "chrome/browser/renderer_host/render_process_host.h" | 16 #include "chrome/browser/renderer_host/render_process_host.h" |
| 16 #include "chrome/browser/renderer_host/resource_message_filter.h" | 17 #include "chrome/browser/renderer_host/resource_message_filter.h" |
| 17 #include "chrome/browser/tab_contents/tab_contents.h" | 18 #include "chrome/browser/tab_contents/tab_contents.h" |
| 18 #include "chrome/browser/tab_contents/tab_util.h" | 19 #include "chrome/browser/tab_contents/tab_util.h" |
| 19 #include "chrome/common/notification_service.h" | 20 #include "chrome/common/notification_service.h" |
| 20 #include "chrome/common/render_messages.h" | 21 #include "chrome/common/render_messages.h" |
| 21 #include "chrome/common/stl_util-inl.h" | |
| 22 | 22 |
| 23 // Since we have 2 ports for every channel, we just index channels by half the | 23 // Since we have 2 ports for every channel, we just index channels by half the |
| 24 // port ID. | 24 // port ID. |
| 25 #define GET_CHANNEL_ID(port_id) ((port_id) / 2) | 25 #define GET_CHANNEL_ID(port_id) ((port_id) / 2) |
| 26 | 26 |
| 27 // Port1 is always even, port2 is always odd. | 27 // Port1 is always even, port2 is always odd. |
| 28 #define IS_PORT1_ID(port_id) (((port_id) & 1) == 0) | 28 #define IS_PORT1_ID(port_id) (((port_id) & 1) == 0) |
| 29 | 29 |
| 30 // Change even to odd and vice versa, to get the other side of a given channel. | 30 // Change even to odd and vice versa, to get the other side of a given channel. |
| 31 #define GET_OPPOSITE_PORT_ID(source_port_id) ((source_port_id) ^ 1) | 31 #define GET_OPPOSITE_PORT_ID(source_port_id) ((source_port_id) ^ 1) |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 | 210 |
| 211 void ExtensionMessageService::Observe(NotificationType type, | 211 void ExtensionMessageService::Observe(NotificationType type, |
| 212 const NotificationSource& source, | 212 const NotificationSource& source, |
| 213 const NotificationDetails& details) { | 213 const NotificationDetails& details) { |
| 214 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); | 214 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); |
| 215 | 215 |
| 216 DCHECK(type.value == NotificationType::RENDERER_PROCESS_TERMINATED || | 216 DCHECK(type.value == NotificationType::RENDERER_PROCESS_TERMINATED || |
| 217 type.value == NotificationType::RENDERER_PROCESS_CLOSED); | 217 type.value == NotificationType::RENDERER_PROCESS_CLOSED); |
| 218 | 218 |
| 219 RenderProcessHost* renderer = Source<RenderProcessHost>(source).ptr(); | 219 RenderProcessHost* renderer = Source<RenderProcessHost>(source).ptr(); |
| 220 | 220 |
| 221 { | 221 { |
| 222 AutoLock lock(process_ids_lock_); | 222 AutoLock lock(process_ids_lock_); |
| 223 for (ProcessIDMap::iterator it = process_ids_.begin(); | 223 for (ProcessIDMap::iterator it = process_ids_.begin(); |
| 224 it != process_ids_.end(); ) { | 224 it != process_ids_.end(); ) { |
| 225 ProcessIDMap::iterator current = it++; | 225 ProcessIDMap::iterator current = it++; |
| 226 if (current->second == renderer->pid()) { | 226 if (current->second == renderer->pid()) { |
| 227 process_ids_.erase(current); | 227 process_ids_.erase(current); |
| 228 } | 228 } |
| 229 } | 229 } |
| 230 } | 230 } |
| 231 | 231 |
| 232 // Close any channels that share this renderer. | 232 // Close any channels that share this renderer. |
| 233 // TODO(mpcomplete): should we notify the other side of the port? | 233 // TODO(mpcomplete): should we notify the other side of the port? |
| 234 for (MessageChannelMap::iterator it = channels_.begin(); | 234 for (MessageChannelMap::iterator it = channels_.begin(); |
| 235 it != channels_.end(); ) { | 235 it != channels_.end(); ) { |
| 236 MessageChannelMap::iterator current = it++; | 236 MessageChannelMap::iterator current = it++; |
| 237 if (current->second.port1 == renderer || current->second.port2 == renderer) | 237 if (current->second.port1 == renderer || current->second.port2 == renderer) |
| 238 channels_.erase(current); | 238 channels_.erase(current); |
| 239 } | 239 } |
| 240 } | 240 } |
| OLD | NEW |