From 1706d76540b092bda26d7101709cf3906e22de91 Mon Sep 17 00:00:00 2001 From: "mpcomplete@google.com" Date: Thu, 23 Apr 2009 18:37:08 +0000 Subject: Arrange so ExtensionMessageService::RendererReady is called on the IO thread. This fixes a bug where it wouldn't notice when a renderer died because it was observing the notification on the wrong thread. This also simplifies some logic in ExtensionMessageService. Review URL: http://codereview.chromium.org/88002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14336 0039d316-1c4b-4281-b951-d872f2087c98 --- .../browser/extensions/extension_message_service.h | 27 ++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'chrome/browser/extensions/extension_message_service.h') diff --git a/chrome/browser/extensions/extension_message_service.h b/chrome/browser/extensions/extension_message_service.h index d4eb856..0c8d63f 100755 --- a/chrome/browser/extensions/extension_message_service.h +++ b/chrome/browser/extensions/extension_message_service.h @@ -52,16 +52,16 @@ class ExtensionMessageService : public NotificationObserver { void PostMessageFromRenderer(int port_id, const std::string& message, ResourceMessageFilter* source); - // --- UI or IO thread: - // Called to let us know that a renderer has been started. - void RendererReady(ResourceMessageFilter* filter); + void RendererReady(ResourceMessageFilter* renderer); // NotificationObserver interface. void Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details); + // --- UI or IO thread: + // Send an event to every registered extension renderer. void DispatchEventToRenderers( const std::string& event_name, const std::string& event_args); @@ -71,15 +71,10 @@ class ExtensionMessageService : public NotificationObserver { typedef std::map ProcessIDMap; ProcessIDMap process_ids_; - // A map of render_process_id to its corresponding message filter, which we - // use for sending messages. - typedef std::map RendererMap; - RendererMap renderers_; - - // Protects the two maps above, since each can be accessed on the IO thread + // Protects the process_ids map, since it can be accessed on the IO thread // or UI thread. Be careful not to hold this lock when calling external // code (especially sending messages) to avoid deadlock. - Lock renderers_lock_; + Lock process_ids_lock_; // --- IO thread only: @@ -96,8 +91,16 @@ class ExtensionMessageService : public NotificationObserver { // For generating unique channel IDs. int next_port_id_; - // For tracking the ResourceMessageFilters we are observing. - std::set filters_; + // A map of render_process_id to its corresponding message filter, which we + // use for sending messages. + typedef std::map RendererMap; + RendererMap renderers_; + + // A unique list of renderers that we are aware of. + std::set renderers_unique_; + + // Set to true when we start observing this notification. + bool observing_renderer_shutdown_; }; #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_SERVICE_H_ -- cgit v1.1