| 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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_SERVICE_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_SERVICE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_SERVICE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/lock.h" | 11 #include "base/lock.h" |
| 12 #include "chrome/common/notification_observer.h" |
| 12 | 13 |
| 13 class ExtensionView; | 14 class ExtensionView; |
| 14 class ResourceMessageFilter; | 15 class ResourceMessageFilter; |
| 15 class URLRequestContext; | 16 class URLRequestContext; |
| 16 | 17 |
| 17 // This class manages message passing between renderer processes. It maintains | 18 // This class manages message passing between renderer processes. It maintains |
| 18 // a list of available extensions and which renderers each lives in, as well as | 19 // a list of available extensions and which renderers each lives in, as well as |
| 19 // a set of open channels. | 20 // a set of open channels. |
| 20 // | 21 // |
| 21 // Terminology: | 22 // Terminology: |
| 22 // channel: connection between two ports (one of which belongs to an extension) | 23 // channel: connection between two ports (one of which belongs to an extension) |
| 23 // port: an IPC::Message::Sender interface through which we communicate to a | 24 // port: an IPC::Message::Sender interface through which we communicate to a |
| 24 // process. We use MessageFilters for this since that allows us to send our | 25 // process. We use MessageFilters for this since that allows us to send our |
| 25 // messages on the IO thread. | 26 // messages on the IO thread. |
| 26 class ExtensionMessageService { | 27 class ExtensionMessageService : public NotificationObserver { |
| 27 public: | 28 public: |
| 28 // Returns the message service for the given context. Messages can only | 29 // Returns the message service for the given context. Messages can only |
| 29 // be sent within a single context. | 30 // be sent within a single context. |
| 30 static ExtensionMessageService* GetInstance(URLRequestContext* context); | 31 static ExtensionMessageService* GetInstance(URLRequestContext* context); |
| 31 | 32 |
| 32 ExtensionMessageService(); | 33 ExtensionMessageService(); |
| 33 | 34 |
| 34 // --- UI thread only: | 35 // --- UI thread only: |
| 35 | 36 |
| 36 // Register an extension and its corresponding renderer process. | 37 // Register an extension and its corresponding renderer process. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 47 | 48 |
| 48 // Sends a message from a renderer to the given port. | 49 // Sends a message from a renderer to the given port. |
| 49 void PostMessageFromRenderer(int port_id, const std::string& message, | 50 void PostMessageFromRenderer(int port_id, const std::string& message, |
| 50 ResourceMessageFilter* source); | 51 ResourceMessageFilter* source); |
| 51 | 52 |
| 52 // --- UI or IO thread: | 53 // --- UI or IO thread: |
| 53 | 54 |
| 54 // Called to let us know that a renderer has been started. | 55 // Called to let us know that a renderer has been started. |
| 55 void RendererReady(ResourceMessageFilter* port); | 56 void RendererReady(ResourceMessageFilter* port); |
| 56 | 57 |
| 57 // Called to let us know that a renderer is going away. | 58 // NotificationObserver interface. |
| 58 void RendererShutdown(ResourceMessageFilter* port); | 59 void Observe(NotificationType type, |
| 60 const NotificationSource& source, |
| 61 const NotificationDetails& details); |
| 59 | 62 |
| 60 private: | 63 private: |
| 61 // A map of extension ID to the render_process_id that the extension lives in. | 64 // A map of extension ID to the render_process_id that the extension lives in. |
| 62 typedef std::map<std::string, int> ProcessIDMap; | 65 typedef std::map<std::string, int> ProcessIDMap; |
| 63 ProcessIDMap process_ids_; | 66 ProcessIDMap process_ids_; |
| 64 | 67 |
| 65 // A map of render_process_id to its corresponding message filter, which we | 68 // A map of render_process_id to its corresponding message filter, which we |
| 66 // use for sending messages. | 69 // use for sending messages. |
| 67 typedef std::map<int, ResourceMessageFilter*> RendererMap; | 70 typedef std::map<int, ResourceMessageFilter*> RendererMap; |
| 68 RendererMap renderers_; | 71 RendererMap renderers_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 82 | 85 |
| 83 // A map of channel ID to its channel object. | 86 // A map of channel ID to its channel object. |
| 84 typedef std::map<int, MessageChannel> MessageChannelMap; | 87 typedef std::map<int, MessageChannel> MessageChannelMap; |
| 85 MessageChannelMap channels_; | 88 MessageChannelMap channels_; |
| 86 | 89 |
| 87 // For generating unique channel IDs. | 90 // For generating unique channel IDs. |
| 88 int next_port_id_; | 91 int next_port_id_; |
| 89 }; | 92 }; |
| 90 | 93 |
| 91 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_SERVICE_H_ | 94 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_SERVICE_H_ |
| OLD | NEW |