OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_EVENT_ROUTER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/memory/linked_ptr.h" | 14 #include "base/memory/linked_ptr.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
17 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
18 #include "ipc/ipc_message.h" | 18 #include "ipc/ipc_message.h" |
19 | 19 |
20 class GURL; | 20 class GURL; |
21 class Extension; | 21 class Extension; |
22 class ExtensionDevToolsManager; | 22 class ExtensionDevToolsManager; |
23 class Profile; | 23 class Profile; |
| 24 |
| 25 namespace content { |
24 class RenderProcessHost; | 26 class RenderProcessHost; |
| 27 } |
25 | 28 |
26 class ExtensionEventRouter : public content::NotificationObserver { | 29 class ExtensionEventRouter : public content::NotificationObserver { |
27 public: | 30 public: |
28 // Sends an event via ipc_sender to the given extension. Can be called on | 31 // Sends an event via ipc_sender to the given extension. Can be called on |
29 // any thread. | 32 // any thread. |
30 static void DispatchEvent(IPC::Message::Sender* ipc_sender, | 33 static void DispatchEvent(IPC::Message::Sender* ipc_sender, |
31 const std::string& extension_id, | 34 const std::string& extension_id, |
32 const std::string& event_name, | 35 const std::string& event_name, |
33 const std::string& event_args, | 36 const std::string& event_args, |
34 const GURL& event_url); | 37 const GURL& event_url); |
35 | 38 |
36 explicit ExtensionEventRouter(Profile* profile); | 39 explicit ExtensionEventRouter(Profile* profile); |
37 virtual ~ExtensionEventRouter(); | 40 virtual ~ExtensionEventRouter(); |
38 | 41 |
39 // Add or remove the process/extension pair as a listener for |event_name|. | 42 // Add or remove the process/extension pair as a listener for |event_name|. |
40 // Note that multiple extensions can share a process due to process | 43 // Note that multiple extensions can share a process due to process |
41 // collapsing. Also, a single extension can have 2 processes if it is a split | 44 // collapsing. Also, a single extension can have 2 processes if it is a split |
42 // mode extension. | 45 // mode extension. |
43 void AddEventListener(const std::string& event_name, | 46 void AddEventListener(const std::string& event_name, |
44 RenderProcessHost* process, | 47 content::RenderProcessHost* process, |
45 const std::string& extension_id); | 48 const std::string& extension_id); |
46 void RemoveEventListener(const std::string& event_name, | 49 void RemoveEventListener(const std::string& event_name, |
47 RenderProcessHost* process, | 50 content::RenderProcessHost* process, |
48 const std::string& extension_id); | 51 const std::string& extension_id); |
49 | 52 |
50 // Returns true if there is at least one listener for the given event. | 53 // Returns true if there is at least one listener for the given event. |
51 bool HasEventListener(const std::string& event_name); | 54 bool HasEventListener(const std::string& event_name); |
52 | 55 |
53 // Returns true if the extension is listening to the given event. | 56 // Returns true if the extension is listening to the given event. |
54 bool ExtensionHasEventListener(const std::string& extension_id, | 57 bool ExtensionHasEventListener(const std::string& extension_id, |
55 const std::string& event_name); | 58 const std::string& event_name); |
56 | 59 |
57 // Send an event to every registered extension renderer. If | 60 // Send an event to every registered extension renderer. If |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 144 |
142 // Track of the number of dispatched events that have not yet sent an | 145 // Track of the number of dispatched events that have not yet sent an |
143 // ACK from the renderer. | 146 // ACK from the renderer. |
144 void IncrementInFlightEvents(const std::string& extension_id); | 147 void IncrementInFlightEvents(const std::string& extension_id); |
145 std::map<std::string, int> in_flight_events_; | 148 std::map<std::string, int> in_flight_events_; |
146 | 149 |
147 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter); | 150 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter); |
148 }; | 151 }; |
149 | 152 |
150 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ | 153 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ |
OLD | NEW |