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

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: fix memory leak 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
« no previous file with comments | « chrome/browser/about_flags.cc ('k') | chrome/browser/extensions/extension_event_router.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
14 #include "content/common/notification_observer.h" 15 #include "content/common/notification_observer.h"
15 #include "content/common/notification_registrar.h" 16 #include "content/common/notification_registrar.h"
16 #include "ipc/ipc_message.h" 17 #include "ipc/ipc_message.h"
17 18
18 class GURL; 19 class GURL;
19 class Extension; 20 class Extension;
20 class ExtensionDevToolsManager; 21 class ExtensionDevToolsManager;
21 class Profile; 22 class Profile;
22 class RenderProcessHost; 23 class RenderProcessHost;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // normal profile only works if extension is allowed incognito access). If 59 // 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 60 // |event_url| is not empty, the event is only sent to extension with host
60 // permissions for this url. 61 // permissions for this url.
61 void DispatchEventToRenderers( 62 void DispatchEventToRenderers(
62 const std::string& event_name, 63 const std::string& event_name,
63 const std::string& event_args, 64 const std::string& event_args,
64 Profile* restrict_to_profile, 65 Profile* restrict_to_profile,
65 const GURL& event_url); 66 const GURL& event_url);
66 67
67 // Same as above, except only send the event to the given extension. 68 // Same as above, except only send the event to the given extension.
68 void DispatchEventToExtension( 69 virtual void DispatchEventToExtension(
69 const std::string& extension_id, 70 const std::string& extension_id,
70 const std::string& event_name, 71 const std::string& event_name,
71 const std::string& event_args, 72 const std::string& event_args,
72 Profile* restrict_to_profile, 73 Profile* restrict_to_profile,
73 const GURL& event_url); 74 const GURL& event_url);
74 75
75 // Send different versions of an event to extensions in different profiles. 76 // 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 77 // 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), 78 // incognito access, and another event to extensions that don't (here),
78 // in order to avoid sending 2 events to "spanning" extensions. 79 // in order to avoid sending 2 events to "spanning" extensions.
79 // If |cross_incognito_profile| is non-NULL and different from 80 // If |cross_incognito_profile| is non-NULL and different from
80 // restrict_to_profile, send the event with cross_incognito_args to the 81 // restrict_to_profile, send the event with cross_incognito_args to the
81 // extensions in that profile that can't cross incognito. 82 // extensions in that profile that can't cross incognito.
82 void DispatchEventsToRenderersAcrossIncognito( 83 void DispatchEventsToRenderersAcrossIncognito(
83 const std::string& event_name, 84 const std::string& event_name,
84 const std::string& event_args, 85 const std::string& event_args,
85 Profile* restrict_to_profile, 86 Profile* restrict_to_profile,
86 const std::string& cross_incognito_args, 87 const std::string& cross_incognito_args,
87 const GURL& event_url); 88 const GURL& event_url);
88 89
89 protected: 90 protected:
91 // The details of an event to be dispatched.
92 struct ExtensionEvent;
93
90 // Shared by DispatchEvent*. If |extension_id| is empty, the event is 94 // Shared by DispatchEvent*. If |extension_id| is empty, the event is
91 // broadcast. 95 // broadcast.
92 virtual void DispatchEventImpl( 96 // An event that just came off the pending list may not be delayed again.
93 const std::string& extension_id, 97 void DispatchEventImpl(const linked_ptr<ExtensionEvent>& event,
94 const std::string& event_name, 98 bool was_pending);
95 const std::string& event_args, 99
96 Profile* restrict_to_profile, 100 // Dispatch may be delayed if the extension has a lazy background page.
97 const std::string& cross_incognito_args, 101 bool CanDispatchEventNow(const std::string& extension_id);
98 const GURL& event_url); 102
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 linked_ptr<ExtensionEvent>& 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
114 // A map between an event name and a set of extensions that are listening 122 // A map between an event name and a set of extensions that are listening
115 // to that event. 123 // to that event.
116 typedef std::map<std::string, std::set<EventListener> > ListenerMap; 124 typedef std::map<std::string, std::set<EventListener> > ListenerMap;
117 ListenerMap listeners_; 125 ListenerMap listeners_;
118 126
127 // A map between an extension id and the queue of events pending
128 // the load of it's background page.
129 typedef std::vector<linked_ptr<ExtensionEvent> > PendingEventsList;
130 typedef std::map<std::string,
131 linked_ptr<PendingEventsList> > PendingEventsPerExtMap;
132 PendingEventsPerExtMap pending_events_;
133
119 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter); 134 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter);
120 }; 135 };
121 136
122 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ 137 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_
OLDNEW
« no previous file with comments | « chrome/browser/about_flags.cc ('k') | chrome/browser/extensions/extension_event_router.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698