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

Side by Side Diff: chrome/browser/extensions/event_listener_map.cc

Issue 12301019: Correct the OnListenerRemoved semantic of EventListenerMap::Delegate (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 10 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
« no previous file with comments | « no previous file | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/extensions/event_listener_map.h" 5 #include "chrome/browser/extensions/event_listener_map.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 8
9 #include "chrome/browser/extensions/event_router.h" 9 #include "chrome/browser/extensions/event_router.h"
10 10
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 DictionaryValue* filter_dict) { 73 DictionaryValue* filter_dict) {
74 return scoped_ptr<EventMatcher>(new EventMatcher( 74 return scoped_ptr<EventMatcher>(new EventMatcher(
75 scoped_ptr<DictionaryValue>(filter_dict->DeepCopy()))); 75 scoped_ptr<DictionaryValue>(filter_dict->DeepCopy())));
76 } 76 }
77 77
78 bool EventListenerMap::RemoveListener(const EventListener* listener) { 78 bool EventListenerMap::RemoveListener(const EventListener* listener) {
79 ListenerList& listeners = listeners_[listener->event_name]; 79 ListenerList& listeners = listeners_[listener->event_name];
80 for (ListenerList::iterator it = listeners.begin(); it != listeners.end(); 80 for (ListenerList::iterator it = listeners.begin(); it != listeners.end();
81 it++) { 81 it++) {
82 if ((*it)->Equals(listener)) { 82 if ((*it)->Equals(listener)) {
83 delegate_->OnListenerRemoved(it->get());
84 CleanupListener(it->get()); 83 CleanupListener(it->get());
85 // Popping from the back should be cheaper than erase(it). 84 // Popping from the back should be cheaper than erase(it).
86 std::swap(*it, listeners.back()); 85 std::swap(*it, listeners.back());
87 listeners.pop_back(); 86 listeners.pop_back();
87 delegate_->OnListenerRemoved(listener);
88 return true; 88 return true;
89 } 89 }
90 } 90 }
91 return false; 91 return false;
92 } 92 }
93 93
94 bool EventListenerMap::HasListenerForEvent(const std::string& event_name) { 94 bool EventListenerMap::HasListenerForEvent(const std::string& event_name) {
95 ListenerMap::iterator it = listeners_.find(event_name); 95 ListenerMap::iterator it = listeners_.find(event_name);
96 return it != listeners_.end() && !it->second.empty(); 96 return it != listeners_.end() && !it->second.empty();
97 } 97 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 } 208 }
209 209
210 void EventListenerMap::RemoveListenersForProcess( 210 void EventListenerMap::RemoveListenersForProcess(
211 const content::RenderProcessHost* process) { 211 const content::RenderProcessHost* process) {
212 CHECK(process); 212 CHECK(process);
213 for (ListenerMap::iterator it = listeners_.begin(); it != listeners_.end(); 213 for (ListenerMap::iterator it = listeners_.begin(); it != listeners_.end();
214 it++) { 214 it++) {
215 for (ListenerList::iterator it2 = it->second.begin(); 215 for (ListenerList::iterator it2 = it->second.begin();
216 it2 != it->second.end();) { 216 it2 != it->second.end();) {
217 if ((*it2)->process == process) { 217 if ((*it2)->process == process) {
218 delegate_->OnListenerRemoved(it2->get()); 218 linked_ptr<EventListener> listener(*it2);
219 CleanupListener(it2->get()); 219 CleanupListener(it2->get());
220 it2 = it->second.erase(it2); 220 it2 = it->second.erase(it2);
221 delegate_->OnListenerRemoved(listener.get());
221 } else { 222 } else {
222 it2++; 223 it2++;
223 } 224 }
224 } 225 }
225 } 226 }
226 } 227 }
227 228
228 void EventListenerMap::CleanupListener(EventListener* listener) { 229 void EventListenerMap::CleanupListener(EventListener* listener) {
229 // If the listener doesn't have a filter then we have nothing to clean up. 230 // If the listener doesn't have a filter then we have nothing to clean up.
230 if (listener->matcher_id == -1) 231 if (listener->matcher_id == -1)
231 return; 232 return;
232 event_filter_.RemoveEventMatcher(listener->matcher_id); 233 event_filter_.RemoveEventMatcher(listener->matcher_id);
233 CHECK_EQ(1u, listeners_by_matcher_id_.erase(listener->matcher_id)); 234 CHECK_EQ(1u, listeners_by_matcher_id_.erase(listener->matcher_id));
234 } 235 }
235 236
236 bool EventListenerMap::IsFilteredEvent(const Event& event) const { 237 bool EventListenerMap::IsFilteredEvent(const Event& event) const {
237 return filtered_events_.count(event.event_name) > 0u; 238 return filtered_events_.count(event.event_name) > 0u;
238 } 239 }
239 240
240 } // namespace extensions 241 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698