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

Side by Side Diff: extensions/browser/event_listener_map.h

Issue 2887293003: Modernize some extensions code. (Closed)
Patch Set: address comments Created 3 years, 7 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 EXTENSIONS_BROWSER_EVENT_LISTENER_MAP_H_ 5 #ifndef EXTENSIONS_BROWSER_EVENT_LISTENER_MAP_H_
6 #define EXTENSIONS_BROWSER_EVENT_LISTENER_MAP_H_ 6 #define EXTENSIONS_BROWSER_EVENT_LISTENER_MAP_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 std::set<const EventListener*> GetEventListeners(const Event& event); 131 std::set<const EventListener*> GetEventListeners(const Event& event);
132 132
133 const ListenerList& GetEventListenersByName(const std::string& event_name) { 133 const ListenerList& GetEventListenersByName(const std::string& event_name) {
134 return listeners_[event_name]; 134 return listeners_[event_name];
135 } 135 }
136 136
137 // Removes all listeners with process equal to |process|. 137 // Removes all listeners with process equal to |process|.
138 void RemoveListenersForProcess(const content::RenderProcessHost* process); 138 void RemoveListenersForProcess(const content::RenderProcessHost* process);
139 139
140 // Returns true if there are any listeners on the event named |event_name|. 140 // Returns true if there are any listeners on the event named |event_name|.
141 bool HasListenerForEvent(const std::string& event_name); 141 bool HasListenerForEvent(const std::string& event_name) const;
142 142
143 // Returns true if there are any listeners on |event_name| from 143 // Returns true if there are any listeners on |event_name| from
144 // |extension_id|. 144 // |extension_id|.
145 bool HasListenerForExtension(const std::string& extension_id, 145 bool HasListenerForExtension(const std::string& extension_id,
146 const std::string& event_name); 146 const std::string& event_name) const;
147 147
148 // Returns true if this map contains an EventListener that .Equals() 148 // Returns true if this map contains an EventListener that .Equals()
149 // |listener|. 149 // |listener|.
150 bool HasListener(const EventListener* listener); 150 bool HasListener(const EventListener* listener) const;
151 151
152 // Returns true if there is a listener for |extension_id| in |process|. 152 // Returns true if there is a listener for |extension_id| in |process|.
153 bool HasProcessListener(content::RenderProcessHost* process, 153 bool HasProcessListener(content::RenderProcessHost* process,
154 const std::string& extension_id); 154 const std::string& extension_id) const;
155 155
156 // Removes any listeners that |extension_id| has added, both lazy and regular. 156 // Removes any listeners that |extension_id| has added, both lazy and regular.
157 void RemoveListenersForExtension(const std::string& extension_id); 157 void RemoveListenersForExtension(const std::string& extension_id);
158 158
159 // Adds unfiltered lazy listeners as described their serialised descriptions. 159 // Adds unfiltered lazy listeners as described their serialised descriptions.
160 // |event_names| the names of the lazy events. 160 // |event_names| the names of the lazy events.
161 // Note that we can only load lazy listeners in this fashion, because there 161 // Note that we can only load lazy listeners in this fashion, because there
162 // is no way to serialise a RenderProcessHost*. 162 // is no way to serialise a RenderProcessHost*.
163 void LoadUnfilteredLazyListeners(const std::string& extension_id, 163 void LoadUnfilteredLazyListeners(const std::string& extension_id,
164 const std::set<std::string>& event_names); 164 const std::set<std::string>& event_names);
165 165
166 // Adds filtered lazy listeners as described their serialised descriptions. 166 // Adds filtered lazy listeners as described their serialised descriptions.
167 // |filtered| contains a map from event names to filters, each pairing 167 // |filtered| contains a map from event names to filters, each pairing
168 // defining a lazy filtered listener. 168 // defining a lazy filtered listener.
169 void LoadFilteredLazyListeners( 169 void LoadFilteredLazyListeners(
170 const std::string& extension_id, 170 const std::string& extension_id,
171 const base::DictionaryValue& filtered); 171 const base::DictionaryValue& filtered);
172 172
173 private: 173 private:
174 // The key here is an event name. 174 // The key here is an event name.
175 typedef std::map<std::string, ListenerList> ListenerMap; 175 using ListenerMap = std::map<std::string, ListenerList>;
176 176
177 void CleanupListener(EventListener* listener); 177 void CleanupListener(EventListener* listener);
178 bool IsFilteredEvent(const Event& event) const; 178 bool IsFilteredEvent(const Event& event) const;
179 std::unique_ptr<EventMatcher> ParseEventMatcher( 179 std::unique_ptr<EventMatcher> ParseEventMatcher(
180 base::DictionaryValue* filter_dict); 180 base::DictionaryValue* filter_dict);
181 181
182 // Listens for removals from this map. 182 // Listens for removals from this map.
183 Delegate* delegate_; 183 Delegate* const delegate_;
184 184
185 std::set<std::string> filtered_events_; 185 std::set<std::string> filtered_events_;
186 ListenerMap listeners_; 186 ListenerMap listeners_;
187 187
188 std::map<EventFilter::MatcherID, EventListener*> listeners_by_matcher_id_; 188 std::map<EventFilter::MatcherID, EventListener*> listeners_by_matcher_id_;
189 189
190 EventFilter event_filter_; 190 EventFilter event_filter_;
191 191
192 DISALLOW_COPY_AND_ASSIGN(EventListenerMap); 192 DISALLOW_COPY_AND_ASSIGN(EventListenerMap);
193 }; 193 };
194 194
195 } // namespace extensions 195 } // namespace extensions
196 196
197 #endif // EXTENSIONS_BROWSER_EVENT_LISTENER_MAP_H_ 197 #endif // EXTENSIONS_BROWSER_EVENT_LISTENER_MAP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698