diff options
author | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-01 21:17:49 +0000 |
---|---|---|
committer | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-01 21:17:49 +0000 |
commit | 4b5d64ff3d7d95247ed4f078d8bf585a1726794d (patch) | |
tree | 050a523a5bbccf28ade0814b38bcc9bee187cd04 /chrome/browser/extensions/extension_message_service.h | |
parent | 912445b6db66140aecb3bc822075a6e9bb9d7e33 (diff) | |
download | chromium_src-4b5d64ff3d7d95247ed4f078d8bf585a1726794d.zip chromium_src-4b5d64ff3d7d95247ed4f078d8bf585a1726794d.tar.gz chromium_src-4b5d64ff3d7d95247ed4f078d8bf585a1726794d.tar.bz2 |
Pass down the opener tab when a message channel is opened to an extension.
Also did a bunch of cleanup of ExtensionMessageService. I converted it to
primarily UI-thread habitation, with one function that needs to be on the IO
thread so it can handle a synchronous IPC message.
TEST=N/A
Review URL: http://codereview.chromium.org/99261
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15097 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_message_service.h')
-rwxr-xr-x | chrome/browser/extensions/extension_message_service.h | 73 |
1 files changed, 36 insertions, 37 deletions
diff --git a/chrome/browser/extensions/extension_message_service.h b/chrome/browser/extensions/extension_message_service.h index 52b1682..343c632 100755 --- a/chrome/browser/extensions/extension_message_service.h +++ b/chrome/browser/extensions/extension_message_service.h @@ -12,8 +12,8 @@ #include "base/lock.h" #include "chrome/common/notification_observer.h" -class ExtensionView; -class ListValue; +class MessageLoop; +class RenderProcessHost; class ResourceMessageFilter; class URLRequestContext; @@ -44,33 +44,33 @@ class ExtensionMessageService : public NotificationObserver { void AddEventListener(std::string event_name, int render_process_id); void RemoveEventListener(std::string event_name, int render_process_id); - // --- IO thread only: - - // Given an extension's ID, opens a channel between the given renderer "port" - // and that extension. Returns a channel ID to be used for posting messages - // between the processes, or -1 if the extension doesn't exist. - int OpenChannelToExtension(const std::string& extension_id, - ResourceMessageFilter* source); - // Sends a message from a renderer to the given port. - void PostMessageFromRenderer(int port_id, const std::string& message, - ResourceMessageFilter* source); + // TODO(mpcomplete): include the source tab. + void PostMessageFromRenderer(int port_id, const std::string& message); - // Called to let us know that a renderer has been started. - void RendererReady(ResourceMessageFilter* renderer); + // Send an event to every registered extension renderer. + void DispatchEventToRenderers( + const std::string& event_name, const std::string& event_args); // NotificationObserver interface. void Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details); - // --- UI or IO thread: + // --- IO thread only: - // Send an event to every registered extension renderer. - void DispatchEventToRenderers( - const std::string& event_name, const std::string& event_args); + // Given an extension's ID, opens a channel between the given renderer "port" + // and that extension. Returns a channel ID to be used for posting messages + // between the processes, or -1 if the extension doesn't exist. + // This runs on the IO thread so that it can be used in a synchronous IPC + // message. + int OpenChannelToExtension(int routing_id, const std::string& extension_id, + ResourceMessageFilter* source); private: + // The UI message loop, used for posting tasks. + MessageLoop* ui_loop_; + // A map of extension ID to the render_process_id that the extension lives in. typedef std::map<std::string, int> ProcessIDMap; ProcessIDMap process_ids_; @@ -85,36 +85,35 @@ class ExtensionMessageService : public NotificationObserver { typedef std::map<std::string, std::set<int> > ListenerMap; ListenerMap listeners_; - // Protects listeners_ map, since it can be accessed from either the IO or - // UI thread. Be careful not to hold this lock when calling external code - // (especially sending messages) to avoid deadlock. - Lock listener_lock_; + // --- UI thread only: - // --- IO thread only: + // UI-thread specific initialization. Does nothing if called more than once. + void Init(); - // The connection between two renderers. + // Handles channel creation and notifies the destination that a channel was + // opened. + void OpenChannelOnUIThread(int source_routing_id, + int source_port_id, int source_process_id, + int dest_port_id, int dest_process_id); + + // The connection between two renderers. It is possible that both ports + // refer to the same renderer. struct MessageChannel { - ResourceMessageFilter* port1; - ResourceMessageFilter* port2; + RenderProcessHost* port1; + RenderProcessHost* port2; }; // A map of channel ID to its channel object. typedef std::map<int, MessageChannel> MessageChannelMap; MessageChannelMap channels_; - // For generating unique channel IDs. - int next_port_id_; - - // A map of render_process_id to its corresponding message filter, which we - // use for sending messages. - typedef std::map<int, ResourceMessageFilter*> RendererMap; - RendererMap renderers_; + // True if Init has been called. + bool initialized_; - // A unique list of renderers that we are aware of. - std::set<ResourceMessageFilter*> renderers_unique_; + // --- IO thread only: - // Set to true when we start observing this notification. - bool observing_renderer_shutdown_; + // For generating unique channel IDs. + int next_port_id_; DISALLOW_COPY_AND_ASSIGN(ExtensionMessageService); }; |