Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: chrome/browser/extensions/extension_event_router.h

Issue 7672009: Lazy creating of background pages --enable-lazy-background-pages) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use ExtensionEvent for args to DispatchEventImpl Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // normal profile only works if extension is allowed incognito access). If 60 // normal profile only works if extension is allowed incognito access). If
59 // |event_url| is not empty, the event is only sent to extension with host 61 // |event_url| is not empty, the event is only sent to extension with host
60 // permissions for this url. 62 // permissions for this url.
61 void DispatchEventToRenderers( 63 void DispatchEventToRenderers(
62 const std::string& event_name, 64 const std::string& event_name,
63 const std::string& event_args, 65 const std::string& event_args,
64 Profile* restrict_to_profile, 66 Profile* restrict_to_profile,
65 const GURL& event_url); 67 const GURL& event_url);
66 68
67 // Same as above, except only send the event to the given extension. 69 // Same as above, except only send the event to the given extension.
68 void DispatchEventToExtension( 70 virtual void DispatchEventToExtension(
69 const std::string& extension_id, 71 const std::string& extension_id,
70 const std::string& event_name, 72 const std::string& event_name,
71 const std::string& event_args, 73 const std::string& event_args,
72 Profile* restrict_to_profile, 74 Profile* restrict_to_profile,
73 const GURL& event_url); 75 const GURL& event_url);
74 76
75 // Send different versions of an event to extensions in different profiles. 77 // Send different versions of an event to extensions in different profiles.
76 // This is used in the case of sending one event to extensions that have 78 // This is used in the case of sending one event to extensions that have
77 // incognito access, and another event to extensions that don't (here), 79 // incognito access, and another event to extensions that don't (here),
78 // in order to avoid sending 2 events to "spanning" extensions. 80 // in order to avoid sending 2 events to "spanning" extensions.
79 // If |cross_incognito_profile| is non-NULL and different from 81 // If |cross_incognito_profile| is non-NULL and different from
80 // restrict_to_profile, send the event with cross_incognito_args to the 82 // restrict_to_profile, send the event with cross_incognito_args to the
81 // extensions in that profile that can't cross incognito. 83 // extensions in that profile that can't cross incognito.
82 void DispatchEventsToRenderersAcrossIncognito( 84 void DispatchEventsToRenderersAcrossIncognito(
83 const std::string& event_name, 85 const std::string& event_name,
84 const std::string& event_args, 86 const std::string& event_args,
85 Profile* restrict_to_profile, 87 Profile* restrict_to_profile,
86 const std::string& cross_incognito_args, 88 const std::string& cross_incognito_args,
87 const GURL& event_url); 89 const GURL& event_url);
88 90
89 protected: 91 protected:
92 // The details of an event to be dispatched.
93 struct ExtensionEvent;
94
90 // Shared by DispatchEvent*. If |extension_id| is empty, the event is 95 // Shared by DispatchEvent*. If |extension_id| is empty, the event is
91 // broadcast. 96 // broadcast.
92 virtual void DispatchEventImpl( 97 // An event that just came off the pending list may not be delayed again.
93 const std::string& extension_id, 98 void DispatchEventImpl(const ExtensionEvent& event, bool was_pending);
94 const std::string& event_name, 99
95 const std::string& event_args, 100 // Dispatch may be delayed if the extension has a lazy background page.
96 Profile* restrict_to_profile, 101 bool CanDispatchEventNow(const std::string& extension_id);
97 const std::string& cross_incognito_args, 102
98 const GURL& event_url); 103 // Store the event so that it can be dispatched (in order received)
104 // when the background page is done loading.
105 void AppendEvent(const ExtensionEvent& pending_event);
106 void DispatchPendingEvents(const std::string& extension_id);
99 107
100 private: 108 private:
101 // An extension listening to an event. 109 // An extension listening to an event.
102 struct EventListener; 110 struct EventListener;
103 111
104 virtual void Observe(int type, 112 virtual void Observe(int type,
105 const NotificationSource& source, 113 const NotificationSource& source,
106 const NotificationDetails& details); 114 const NotificationDetails& details);
107 115
108 Profile* profile_; 116 Profile* profile_;
109 117
110 NotificationRegistrar registrar_; 118 NotificationRegistrar registrar_;
111 119
112 scoped_refptr<ExtensionDevToolsManager> extension_devtools_manager_; 120 scoped_refptr<ExtensionDevToolsManager> extension_devtools_manager_;
113 121
122 ScopedRunnableMethodFactory<ExtensionEventRouter> task_factory_;
Matt Perry 2011/08/26 00:13:00 You don't need a task factory in this case. The pu
Matt Perry 2011/08/26 00:13:00 And actually, since you're only using the Tasks fo
Tessa MacDuff 2011/08/26 01:12:53 Thanks for explaining task factories. I think add
123
114 // A map between an event name and a set of extensions that are listening 124 // A map between an event name and a set of extensions that are listening
115 // to that event. 125 // to that event.
116 typedef std::map<std::string, std::set<EventListener> > ListenerMap; 126 typedef std::map<std::string, std::set<EventListener> > ListenerMap;
117 ListenerMap listeners_; 127 ListenerMap listeners_;
118 128
129 // A map between an extension id and the queue of tasks pending
130 // the load of it's background page.
131 typedef std::vector<linked_ptr<Task> > PendingTasksList;
132 typedef std::map<std::string,
133 linked_ptr<PendingTasksList> > PendingTasksPerExtMap;
134 PendingTasksPerExtMap pending_tasks_;
135
119 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter); 136 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter);
120 }; 137 };
121 138
122 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ 139 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698