summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlimasdf@gmail.com <limasdf@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-04 18:53:12 +0000
committerlimasdf@gmail.com <limasdf@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-04 18:53:12 +0000
commit4243f9a4e7bd733c775444b15a117717a05516a8 (patch)
tree30e70130cc35232cb5e79afebc5891efe17c4897
parent61ff6ae4a377fd69955f524db79a4112dc5b3732 (diff)
downloadchromium_src-4243f9a4e7bd733c775444b15a117717a05516a8.zip
chromium_src-4243f9a4e7bd733c775444b15a117717a05516a8.tar.gz
chromium_src-4243f9a4e7bd733c775444b15a117717a05516a8.tar.bz2
Use ExtensionRegistry instead of deprecated extension's notification in EventRouter.
And Make EventRouterTest inherit ExtensionsTest to setup for test. R=kalman@chromium.org BUG=354046 TEST=unittest Review URL: https://codereview.chromium.org/430243002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287383 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--extensions/browser/event_router.cc48
-rw-r--r--extensions/browser/event_router.h14
-rw-r--r--extensions/browser/event_router_unittest.cc3
3 files changed, 36 insertions, 29 deletions
diff --git a/extensions/browser/event_router.cc b/extensions/browser/event_router.cc
index d8ae867..fd39a7b 100644
--- a/extensions/browser/event_router.cc
+++ b/extensions/browser/event_router.cc
@@ -169,6 +169,7 @@ EventRouter::EventRouter(BrowserContext* browser_context,
ExtensionPrefs* extension_prefs)
: browser_context_(browser_context),
extension_prefs_(extension_prefs),
+ extension_registry_observer_(this),
listeners_(this) {
registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
content::NotificationService::AllSources());
@@ -177,12 +178,7 @@ EventRouter::EventRouter(BrowserContext* browser_context,
registrar_.Add(this,
extensions::NOTIFICATION_EXTENSION_ENABLED,
content::Source<BrowserContext>(browser_context_));
- registrar_.Add(this,
- extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
- content::Source<BrowserContext>(browser_context_));
- registrar_.Add(this,
- extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
- content::Source<BrowserContext>(browser_context_));
+ extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_));
}
EventRouter::~EventRouter() {}
@@ -750,33 +746,29 @@ void EventRouter::Observe(int type,
}
break;
}
- case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
- // Add all registered lazy listeners to our cache.
- const Extension* extension =
- content::Details<const Extension>(details).ptr();
- std::set<std::string> registered_events =
- GetRegisteredEvents(extension->id());
- listeners_.LoadUnfilteredLazyListeners(extension->id(),
- registered_events);
- const DictionaryValue* filtered_events =
- GetFilteredEvents(extension->id());
- if (filtered_events)
- listeners_.LoadFilteredLazyListeners(extension->id(), *filtered_events);
- break;
- }
- case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
- // Remove all registered lazy listeners from our cache.
- UnloadedExtensionInfo* unloaded =
- content::Details<UnloadedExtensionInfo>(details).ptr();
- listeners_.RemoveLazyListenersForExtension(unloaded->extension->id());
- break;
- }
default:
NOTREACHED();
- return;
}
}
+void EventRouter::OnExtensionLoaded(content::BrowserContext* browser_context,
+ const Extension* extension) {
+ // Add all registered lazy listeners to our cache.
+ std::set<std::string> registered_events =
+ GetRegisteredEvents(extension->id());
+ listeners_.LoadUnfilteredLazyListeners(extension->id(), registered_events);
+ const DictionaryValue* filtered_events = GetFilteredEvents(extension->id());
+ if (filtered_events)
+ listeners_.LoadFilteredLazyListeners(extension->id(), *filtered_events);
+}
+
+void EventRouter::OnExtensionUnloaded(content::BrowserContext* browser_context,
+ const Extension* extension,
+ UnloadedExtensionInfo::Reason reason) {
+ // Remove all registered lazy listeners from our cache.
+ listeners_.RemoveLazyListenersForExtension(extension->id());
+}
+
Event::Event(const std::string& event_name,
scoped_ptr<base::ListValue> event_args)
: event_name(event_name),
diff --git a/extensions/browser/event_router.h b/extensions/browser/event_router.h
index c8c5226..fba6144 100644
--- a/extensions/browser/event_router.h
+++ b/extensions/browser/event_router.h
@@ -15,10 +15,12 @@
#include "base/containers/hash_tables.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/ref_counted.h"
+#include "base/scoped_observer.h"
#include "base/values.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/event_listener_map.h"
+#include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/event_filtering_info.h"
#include "ipc/ipc_sender.h"
@@ -35,12 +37,14 @@ class ActivityLog;
class Extension;
class ExtensionHost;
class ExtensionPrefs;
+class ExtensionRegistry;
struct Event;
struct EventDispatchInfo;
struct EventListenerInfo;
class EventRouter : public content::NotificationObserver,
+ public ExtensionRegistryObserver,
public EventListenerMap::Delegate {
public:
// These constants convey the state of our knowledge of whether we're in
@@ -207,6 +211,13 @@ class EventRouter : public content::NotificationObserver,
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
+ // ExtensionRegistryObserver implementation.
+ virtual void OnExtensionLoaded(content::BrowserContext* browser_context,
+ const Extension* extension) OVERRIDE;
+ virtual void OnExtensionUnloaded(
+ content::BrowserContext* browser_context,
+ const Extension* extension,
+ UnloadedExtensionInfo::Reason reason) OVERRIDE;
// Returns true if the given listener map contains a event listeners for
// the given event. If |extension_id| is non-empty, we also check that that
@@ -292,6 +303,9 @@ class EventRouter : public content::NotificationObserver,
content::NotificationRegistrar registrar_;
+ ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
+ extension_registry_observer_;
+
EventListenerMap listeners_;
// Map from base event name to observer.
diff --git a/extensions/browser/event_router_unittest.cc b/extensions/browser/event_router_unittest.cc
index b063880..3789aec 100644
--- a/extensions/browser/event_router_unittest.cc
+++ b/extensions/browser/event_router_unittest.cc
@@ -12,6 +12,7 @@
#include "base/values.h"
#include "content/public/browser/notification_service.h"
#include "extensions/browser/event_listener_map.h"
+#include "extensions/browser/extensions_test.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace extensions {
@@ -81,7 +82,7 @@ scoped_ptr<EventListener> CreateEventListenerForURL(
} // namespace
-class EventRouterTest : public testing::Test {
+class EventRouterTest : public ExtensionsTest {
public:
EventRouterTest()
: notification_service_(content::NotificationService::Create()) {}