| 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/memory/linked_ptr.h" |
| 13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/task.h" |
| 14 #include "content/common/notification_observer.h" | 16 #include "content/common/notification_observer.h" |
| 15 #include "content/common/notification_registrar.h" | 17 #include "content/common/notification_registrar.h" |
| 16 #include "ipc/ipc_message.h" | 18 #include "ipc/ipc_message.h" |
| 17 | 19 |
| 18 class GURL; | 20 class GURL; |
| 19 class Extension; | 21 class Extension; |
| 20 class ExtensionDevToolsManager; | 22 class ExtensionDevToolsManager; |
| 21 class Profile; | 23 class Profile; |
| 22 class RenderProcessHost; | 24 class RenderProcessHost; |
| 23 | 25 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 90 |
| 89 protected: | 91 protected: |
| 90 // Shared by DispatchEvent*. If |extension_id| is empty, the event is | 92 // Shared by DispatchEvent*. If |extension_id| is empty, the event is |
| 91 // broadcast. | 93 // broadcast. |
| 92 virtual void DispatchEventImpl( | 94 virtual void DispatchEventImpl( |
| 93 const std::string& extension_id, | 95 const std::string& extension_id, |
| 94 const std::string& event_name, | 96 const std::string& event_name, |
| 95 const std::string& event_args, | 97 const std::string& event_args, |
| 96 Profile* restrict_to_profile, | 98 Profile* restrict_to_profile, |
| 97 const std::string& cross_incognito_args, | 99 const std::string& cross_incognito_args, |
| 98 const GURL& event_url); | 100 const GURL& event_url, |
| 101 bool was_pending); |
| 102 |
| 103 // Dispatch may be delayed if the extension has a lazy background page. |
| 104 // An event that just came off the pending list may not be delayed again. |
| 105 bool CanDispatchEventNow(const std::string& extension_id, |
| 106 bool was_pending); |
| 107 |
| 108 // Store the event so that it can be dispatched (in order recieved) |
| 109 // when the background page is done loading. |
| 110 void AppendEvent(const std::string& extension_id, |
| 111 const std::string& event_name, |
| 112 const std::string& event_args, |
| 113 Profile* restrict_to_profile, |
| 114 const std::string& cross_incognito_args, |
| 115 const GURL& event_url); |
| 116 void DispatchPendingEvents(const std::string& extension_id); |
| 99 | 117 |
| 100 private: | 118 private: |
| 101 // An extension listening to an event. | 119 // An extension listening to an event. |
| 102 struct EventListener; | 120 struct EventListener; |
| 103 | 121 |
| 104 virtual void Observe(int type, | 122 virtual void Observe(int type, |
| 105 const NotificationSource& source, | 123 const NotificationSource& source, |
| 106 const NotificationDetails& details); | 124 const NotificationDetails& details); |
| 107 | 125 |
| 108 Profile* profile_; | 126 Profile* profile_; |
| 109 | 127 |
| 110 NotificationRegistrar registrar_; | 128 NotificationRegistrar registrar_; |
| 111 | 129 |
| 112 scoped_refptr<ExtensionDevToolsManager> extension_devtools_manager_; | 130 scoped_refptr<ExtensionDevToolsManager> extension_devtools_manager_; |
| 113 | 131 |
| 132 ScopedRunnableMethodFactory<ExtensionEventRouter> task_factory_; |
| 133 |
| 114 // A map between an event name and a set of extensions that are listening | 134 // A map between an event name and a set of extensions that are listening |
| 115 // to that event. | 135 // to that event. |
| 116 typedef std::map<std::string, std::set<EventListener> > ListenerMap; | 136 typedef std::map<std::string, std::set<EventListener> > ListenerMap; |
| 117 ListenerMap listeners_; | 137 ListenerMap listeners_; |
| 118 | 138 |
| 139 // A map between an extension id and the queue of tasks pending |
| 140 // the load of it's background page. |
| 141 typedef std::vector<linked_ptr<Task> > PendingTasksList; |
| 142 typedef std::map<std::string, |
| 143 linked_ptr<PendingTasksList> > PendingTasksPerExtMap; |
| 144 PendingTasksPerExtMap pending_tasks_; |
| 145 |
| 119 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter); | 146 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter); |
| 120 }; | 147 }; |
| 121 | 148 |
| 122 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ | 149 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ |
| OLD | NEW |