OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_MESSAGE_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_MESSAGE_SERVICE_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_MESSAGE_SERVICE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_MESSAGE_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/linked_ptr.h" | 13 #include "base/memory/linked_ptr.h" |
14 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
15 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
16 | 16 |
17 class ExtensionHost; | |
18 class Profile; | 17 class Profile; |
19 | 18 |
20 namespace content { | 19 namespace content { |
21 class RenderProcessHost; | 20 class RenderProcessHost; |
22 class WebContents; | 21 class WebContents; |
23 } | 22 } |
24 | 23 |
25 namespace extensions { | 24 namespace extensions { |
| 25 class ExtensionHost; |
26 class LazyBackgroundTaskQueue; | 26 class LazyBackgroundTaskQueue; |
27 | 27 |
28 // This class manages message and event passing between renderer processes. | 28 // This class manages message and event passing between renderer processes. |
29 // It maintains a list of processes that are listening to events and a set of | 29 // It maintains a list of processes that are listening to events and a set of |
30 // open channels. | 30 // open channels. |
31 // | 31 // |
32 // Messaging works this way: | 32 // Messaging works this way: |
33 // - An extension-owned script context (like a background page or a content | 33 // - An extension-owned script context (like a background page or a content |
34 // script) adds an event listener to the "onConnect" event. | 34 // script) adds an event listener to the "onConnect" event. |
35 // - Another context calls "extension.connect()" to open a channel to the | 35 // - Another context calls "extension.connect()" to open a channel to the |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 // Potentially registers a pending task with the LazyBackgroundTaskQueue | 116 // Potentially registers a pending task with the LazyBackgroundTaskQueue |
117 // to open a channel. Returns true if a task was queued. | 117 // to open a channel. Returns true if a task was queued. |
118 bool MaybeAddPendingOpenChannelTask(Profile* profile, | 118 bool MaybeAddPendingOpenChannelTask(Profile* profile, |
119 const OpenChannelParams& params); | 119 const OpenChannelParams& params); |
120 | 120 |
121 // Callbacks for LazyBackgroundTaskQueue tasks. The queue passes in an | 121 // Callbacks for LazyBackgroundTaskQueue tasks. The queue passes in an |
122 // ExtensionHost to its task callbacks, though some of our callbacks don't | 122 // ExtensionHost to its task callbacks, though some of our callbacks don't |
123 // use that argument. | 123 // use that argument. |
124 void PendingOpenChannel(const OpenChannelParams& params, | 124 void PendingOpenChannel(const OpenChannelParams& params, |
125 int source_process_id, | 125 int source_process_id, |
126 ExtensionHost* host); | 126 extensions::ExtensionHost* host); |
127 void PendingCloseChannel(int port_id, | 127 void PendingCloseChannel(int port_id, |
128 bool connection_error, | 128 bool connection_error, |
129 ExtensionHost* host) { | 129 extensions::ExtensionHost* host) { |
130 if (host) | 130 if (host) |
131 CloseChannel(port_id, connection_error); | 131 CloseChannel(port_id, connection_error); |
132 } | 132 } |
133 void PendingPostMessage(int port_id, | 133 void PendingPostMessage(int port_id, |
134 const std::string& message, | 134 const std::string& message, |
135 ExtensionHost* host) { | 135 extensions::ExtensionHost* host) { |
136 if (host) | 136 if (host) |
137 PostMessageFromRenderer(port_id, message); | 137 PostMessageFromRenderer(port_id, message); |
138 } | 138 } |
139 | 139 |
140 content::NotificationRegistrar registrar_; | 140 content::NotificationRegistrar registrar_; |
141 MessageChannelMap channels_; | 141 MessageChannelMap channels_; |
142 PendingChannelMap pending_channels_; | 142 PendingChannelMap pending_channels_; |
143 | 143 |
144 // Weak pointer. Guaranteed to outlive this class. | 144 // Weak pointer. Guaranteed to outlive this class. |
145 LazyBackgroundTaskQueue* lazy_background_task_queue_; | 145 LazyBackgroundTaskQueue* lazy_background_task_queue_; |
146 | 146 |
147 DISALLOW_COPY_AND_ASSIGN(MessageService); | 147 DISALLOW_COPY_AND_ASSIGN(MessageService); |
148 }; | 148 }; |
149 | 149 |
150 } // namespace extensions | 150 } // namespace extensions |
151 | 151 |
152 #endif // CHROME_BROWSER_EXTENSIONS_MESSAGE_SERVICE_H_ | 152 #endif // CHROME_BROWSER_EXTENSIONS_MESSAGE_SERVICE_H_ |
OLD | NEW |