Commit 1a3586c0 authored by mek's avatar mek Committed by Commit bot

When an extension is unloaded, unregister all event listeners, not just the lazy ones.

This fixes a problem where event listeners could stick around for a
short time period after an extension is unloaded, causing problems
with the onInstalled event for a new version of an extension.

BUG=449654

Review URL: https://codereview.chromium.org/877233002

Cr-Commit-Position: refs/heads/master@{#313556}
parent e09a9b07
...@@ -176,15 +176,17 @@ bool EventListenerMap::HasProcessListener(content::RenderProcessHost* process, ...@@ -176,15 +176,17 @@ bool EventListenerMap::HasProcessListener(content::RenderProcessHost* process,
return false; return false;
} }
void EventListenerMap::RemoveLazyListenersForExtension( void EventListenerMap::RemoveListenersForExtension(
const std::string& extension_id) { const std::string& extension_id) {
for (ListenerMap::iterator it = listeners_.begin(); it != listeners_.end(); for (ListenerMap::iterator it = listeners_.begin(); it != listeners_.end();
it++) { it++) {
for (ListenerList::iterator it2 = it->second.begin(); for (ListenerList::iterator it2 = it->second.begin();
it2 != it->second.end();) { it2 != it->second.end();) {
if ((*it2)->IsLazy() && (*it2)->extension_id() == extension_id) { if ((*it2)->extension_id() == extension_id) {
CleanupListener(it2->get()); linked_ptr<EventListener> listener(*it2);
CleanupListener(listener.get());
it2 = it->second.erase(it2); it2 = it->second.erase(it2);
delegate_->OnListenerRemoved(listener.get());
} else { } else {
it2++; it2++;
} }
......
...@@ -154,8 +154,8 @@ class EventListenerMap { ...@@ -154,8 +154,8 @@ class EventListenerMap {
bool HasProcessListener(content::RenderProcessHost* process, bool HasProcessListener(content::RenderProcessHost* process,
const std::string& extension_id); const std::string& extension_id);
// Removes any lazy listeners that |extension_id| has added. // Removes any listeners that |extension_id| has added, both lazy and regular.
void RemoveLazyListenersForExtension(const std::string& extension_id); void RemoveListenersForExtension(const std::string& extension_id);
// Adds unfiltered lazy listeners as described their serialised descriptions. // Adds unfiltered lazy listeners as described their serialised descriptions.
// |event_names| the names of the lazy events. // |event_names| the names of the lazy events.
......
...@@ -241,13 +241,13 @@ TEST_F(EventListenerMapTest, HostSuffixFilterEquality) { ...@@ -241,13 +241,13 @@ TEST_F(EventListenerMapTest, HostSuffixFilterEquality) {
ASSERT_TRUE(filter1->Equals(filter2.get())); ASSERT_TRUE(filter1->Equals(filter2.get()));
} }
TEST_F(EventListenerMapTest, RemoveLazyListeners) { TEST_F(EventListenerMapTest, RemoveListenersForExtension) {
listeners_->AddListener(EventListener::ForExtension( listeners_->AddListener(EventListener::ForExtension(
kEvent1Name, kExt1Id, NULL, CreateHostSuffixFilter("google.com"))); kEvent1Name, kExt1Id, NULL, CreateHostSuffixFilter("google.com")));
listeners_->AddListener(EventListener::ForExtension( listeners_->AddListener(EventListener::ForExtension(
kEvent2Name, kExt1Id, NULL, CreateHostSuffixFilter("google.com"))); kEvent2Name, kExt1Id, NULL, CreateHostSuffixFilter("google.com")));
listeners_->RemoveLazyListenersForExtension(kExt1Id); listeners_->RemoveListenersForExtension(kExt1Id);
scoped_ptr<Event> event(CreateNamedEvent(kEvent1Name)); scoped_ptr<Event> event(CreateNamedEvent(kEvent1Name));
event->filter_info.SetURL(GURL("http://www.google.com")); event->filter_info.SetURL(GURL("http://www.google.com"));
...@@ -343,7 +343,7 @@ TEST_F(EventListenerMapTest, HasListenerForExtension) { ...@@ -343,7 +343,7 @@ TEST_F(EventListenerMapTest, HasListenerForExtension) {
ASSERT_FALSE(listeners_->HasListenerForExtension(kExt2Id, kEvent1Name)); ASSERT_FALSE(listeners_->HasListenerForExtension(kExt2Id, kEvent1Name));
listeners_->RemoveListenersForProcess(process_.get()); listeners_->RemoveListenersForProcess(process_.get());
ASSERT_TRUE(listeners_->HasListenerForExtension(kExt1Id, kEvent1Name)); ASSERT_TRUE(listeners_->HasListenerForExtension(kExt1Id, kEvent1Name));
listeners_->RemoveLazyListenersForExtension(kExt1Id); listeners_->RemoveListenersForExtension(kExt1Id);
ASSERT_FALSE(listeners_->HasListenerForExtension(kExt1Id, kEvent1Name)); ASSERT_FALSE(listeners_->HasListenerForExtension(kExt1Id, kEvent1Name));
} }
......
...@@ -763,8 +763,8 @@ void EventRouter::OnExtensionLoaded(content::BrowserContext* browser_context, ...@@ -763,8 +763,8 @@ void EventRouter::OnExtensionLoaded(content::BrowserContext* browser_context,
void EventRouter::OnExtensionUnloaded(content::BrowserContext* browser_context, void EventRouter::OnExtensionUnloaded(content::BrowserContext* browser_context,
const Extension* extension, const Extension* extension,
UnloadedExtensionInfo::Reason reason) { UnloadedExtensionInfo::Reason reason) {
// Remove all registered lazy listeners from our cache. // Remove all registered listeners from our cache.
listeners_.RemoveLazyListenersForExtension(extension->id()); listeners_.RemoveListenersForExtension(extension->id());
} }
Event::Event(const std::string& event_name, Event::Event(const std::string& event_name,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment