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

Unified Diff: extensions/browser/api/api_resource_manager.h

Issue 346193002: Use ExtensionRegistry in EventRouter and ApiResourceManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: extensions/browser/api/api_resource_manager.h
diff --git a/extensions/browser/api/api_resource_manager.h b/extensions/browser/api/api_resource_manager.h
index e0c9b811865d297c0785129bb252e068f57b4a42..309d06af75a1460199e1bc8e227b0eeda6fc0413 100644
--- a/extensions/browser/api/api_resource_manager.h
+++ b/extensions/browser/api/api_resource_manager.h
@@ -11,6 +11,7 @@
#include "base/lazy_instance.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/ref_counted.h"
+#include "base/scoped_observer.h"
#include "base/threading/non_thread_safe.h"
#include "chrome/browser/chrome_notification_types.h"
#include "components/keyed_service/core/keyed_service.h"
@@ -20,6 +21,8 @@
#include "content/public/browser/notification_service.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/extension_host.h"
+#include "extensions/browser/extension_registry.h"
+#include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/extension.h"
namespace extensions {
@@ -75,13 +78,14 @@ class UDPSocketEventDispatcher;
template <class T>
class ApiResourceManager : public BrowserContextKeyedAPI,
public base::NonThreadSafe,
- public content::NotificationObserver {
+ public content::NotificationObserver,
+ public ExtensionRegistryObserver {
public:
explicit ApiResourceManager(content::BrowserContext* context)
- : thread_id_(T::kThreadId), data_(new ApiResourceData(thread_id_)) {
- registrar_.Add(this,
- chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
- content::NotificationService::AllSources());
+ : thread_id_(T::kThreadId),
+ data_(new ApiResourceData(thread_id_)),
+ extension_registry_observer_(this) {
+ extension_registry_observer_.Add(ExtensionRegistry::Get(context));
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
content::NotificationService::AllSources());
@@ -136,19 +140,17 @@ class ApiResourceManager : public BrowserContextKeyedAPI,
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE {
- switch (type) {
- case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
- std::string id = content::Details<extensions::UnloadedExtensionInfo>(
- details)->extension->id();
- data_->InitiateExtensionUnloadedCleanup(id);
- break;
- }
- case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: {
- ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
- data_->InitiateExtensionSuspendedCleanup(host->extension_id());
- break;
- }
- }
+ DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, type);
+ ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
+ data_->InitiateExtensionSuspendedCleanup(host->extension_id());
+ }
+
+ // ExtensionRegistryObserver:
+ virtual void OnExtensionUnloaded(
+ content::BrowserContext* browser_context,
+ const Extension* extension,
+ UnloadedExtensionInfo::Reason reason) OVERRIDE {
+ data_->InitiateExtensionUnloadedCleanup(extension->id());
}
private:
@@ -341,6 +343,9 @@ class ApiResourceManager : public BrowserContextKeyedAPI,
content::BrowserThread::ID thread_id_;
content::NotificationRegistrar registrar_;
scoped_refptr<ApiResourceData> data_;
+
+ ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
+ extension_registry_observer_;
};
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698