| OLD | NEW |
| 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 #include "extensions/browser/event_listener_map.h" | 5 #include "extensions/browser/event_listener_map.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 return false; | 98 return false; |
| 99 if (listener->filter()) { | 99 if (listener->filter()) { |
| 100 std::unique_ptr<EventMatcher> matcher( | 100 std::unique_ptr<EventMatcher> matcher( |
| 101 ParseEventMatcher(listener->filter())); | 101 ParseEventMatcher(listener->filter())); |
| 102 MatcherID id = event_filter_.AddEventMatcher(listener->event_name(), | 102 MatcherID id = event_filter_.AddEventMatcher(listener->event_name(), |
| 103 std::move(matcher)); | 103 std::move(matcher)); |
| 104 listener->set_matcher_id(id); | 104 listener->set_matcher_id(id); |
| 105 listeners_by_matcher_id_[id] = listener.get(); | 105 listeners_by_matcher_id_[id] = listener.get(); |
| 106 filtered_events_.insert(listener->event_name()); | 106 filtered_events_.insert(listener->event_name()); |
| 107 } | 107 } |
| 108 linked_ptr<EventListener> listener_ptr(listener.release()); | 108 EventListener* listener_ptr = listener.get(); |
| 109 listeners_[listener_ptr->event_name()].push_back(listener_ptr); | 109 listeners_[listener->event_name()].push_back(std::move(listener)); |
| 110 | 110 |
| 111 delegate_->OnListenerAdded(listener_ptr.get()); | 111 delegate_->OnListenerAdded(listener_ptr); |
| 112 | 112 |
| 113 return true; | 113 return true; |
| 114 } | 114 } |
| 115 | 115 |
| 116 std::unique_ptr<EventMatcher> EventListenerMap::ParseEventMatcher( | 116 std::unique_ptr<EventMatcher> EventListenerMap::ParseEventMatcher( |
| 117 DictionaryValue* filter_dict) { | 117 DictionaryValue* filter_dict) { |
| 118 return std::unique_ptr<EventMatcher>(new EventMatcher( | 118 return std::unique_ptr<EventMatcher>(new EventMatcher( |
| 119 base::WrapUnique(filter_dict->DeepCopy()), MSG_ROUTING_NONE)); | 119 base::WrapUnique(filter_dict->DeepCopy()), MSG_ROUTING_NONE)); |
| 120 } | 120 } |
| 121 | 121 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 return false; | 182 return false; |
| 183 } | 183 } |
| 184 | 184 |
| 185 void EventListenerMap::RemoveListenersForExtension( | 185 void EventListenerMap::RemoveListenersForExtension( |
| 186 const std::string& extension_id) { | 186 const std::string& extension_id) { |
| 187 for (ListenerMap::iterator it = listeners_.begin(); it != listeners_.end(); | 187 for (ListenerMap::iterator it = listeners_.begin(); it != listeners_.end(); |
| 188 it++) { | 188 it++) { |
| 189 for (ListenerList::iterator it2 = it->second.begin(); | 189 for (ListenerList::iterator it2 = it->second.begin(); |
| 190 it2 != it->second.end();) { | 190 it2 != it->second.end();) { |
| 191 if ((*it2)->extension_id() == extension_id) { | 191 if ((*it2)->extension_id() == extension_id) { |
| 192 linked_ptr<EventListener> listener(*it2); | 192 std::unique_ptr<EventListener> listener_removed = std::move(*it2); |
| 193 CleanupListener(listener.get()); | 193 CleanupListener(listener_removed.get()); |
| 194 it2 = it->second.erase(it2); | 194 it2 = it->second.erase(it2); |
| 195 delegate_->OnListenerRemoved(listener.get()); | 195 delegate_->OnListenerRemoved(listener_removed.get()); |
| 196 } else { | 196 } else { |
| 197 it2++; | 197 it2++; |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 | 202 |
| 203 void EventListenerMap::LoadUnfilteredLazyListeners( | 203 void EventListenerMap::LoadUnfilteredLazyListeners( |
| 204 const std::string& extension_id, | 204 const std::string& extension_id, |
| 205 const std::set<std::string>& event_names) { | 205 const std::set<std::string>& event_names) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 } | 254 } |
| 255 | 255 |
| 256 void EventListenerMap::RemoveListenersForProcess( | 256 void EventListenerMap::RemoveListenersForProcess( |
| 257 const content::RenderProcessHost* process) { | 257 const content::RenderProcessHost* process) { |
| 258 CHECK(process); | 258 CHECK(process); |
| 259 for (ListenerMap::iterator it = listeners_.begin(); it != listeners_.end(); | 259 for (ListenerMap::iterator it = listeners_.begin(); it != listeners_.end(); |
| 260 it++) { | 260 it++) { |
| 261 for (ListenerList::iterator it2 = it->second.begin(); | 261 for (ListenerList::iterator it2 = it->second.begin(); |
| 262 it2 != it->second.end();) { | 262 it2 != it->second.end();) { |
| 263 if ((*it2)->process() == process) { | 263 if ((*it2)->process() == process) { |
| 264 linked_ptr<EventListener> listener(*it2); | 264 std::unique_ptr<EventListener> listener_removed = std::move(*it2); |
| 265 CleanupListener(it2->get()); | 265 CleanupListener(listener_removed.get()); |
| 266 it2 = it->second.erase(it2); | 266 it2 = it->second.erase(it2); |
| 267 delegate_->OnListenerRemoved(listener.get()); | 267 delegate_->OnListenerRemoved(listener_removed.get()); |
| 268 } else { | 268 } else { |
| 269 it2++; | 269 it2++; |
| 270 } | 270 } |
| 271 } | 271 } |
| 272 } | 272 } |
| 273 } | 273 } |
| 274 | 274 |
| 275 void EventListenerMap::CleanupListener(EventListener* listener) { | 275 void EventListenerMap::CleanupListener(EventListener* listener) { |
| 276 // If the listener doesn't have a filter then we have nothing to clean up. | 276 // If the listener doesn't have a filter then we have nothing to clean up. |
| 277 if (listener->matcher_id() == -1) | 277 if (listener->matcher_id() == -1) |
| 278 return; | 278 return; |
| 279 event_filter_.RemoveEventMatcher(listener->matcher_id()); | 279 event_filter_.RemoveEventMatcher(listener->matcher_id()); |
| 280 CHECK_EQ(1u, listeners_by_matcher_id_.erase(listener->matcher_id())); | 280 CHECK_EQ(1u, listeners_by_matcher_id_.erase(listener->matcher_id())); |
| 281 } | 281 } |
| 282 | 282 |
| 283 bool EventListenerMap::IsFilteredEvent(const Event& event) const { | 283 bool EventListenerMap::IsFilteredEvent(const Event& event) const { |
| 284 return filtered_events_.count(event.event_name) > 0u; | 284 return filtered_events_.count(event.event_name) > 0u; |
| 285 } | 285 } |
| 286 | 286 |
| 287 } // namespace extensions | 287 } // namespace extensions |
| OLD | NEW |