summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/api/declarative
diff options
context:
space:
mode:
authorlimasdf@gmail.com <limasdf@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-13 05:09:44 +0000
committerlimasdf@gmail.com <limasdf@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-13 05:09:44 +0000
commitd0c44b74dc1c764c51ca4e9c0158265dca631120 (patch)
tree7c6ab517cf403e198509bf6399c6e4152c976d03 /chrome/browser/extensions/api/declarative
parentb9dfeb996c0ed9546071eae66fdfbeecbc6a1733 (diff)
downloadchromium_src-d0c44b74dc1c764c51ca4e9c0158265dca631120.zip
chromium_src-d0c44b74dc1c764c51ca4e9c0158265dca631120.tar.gz
chromium_src-d0c44b74dc1c764c51ca4e9c0158265dca631120.tar.bz2
Use ExtensionRegistryObserver instead of deprecated extension notification from c/b/e/api.
This clean up alarm, declarative, idle, push_messaing API. R=kalman@chromium.org BUG=354046, 354458 TEST=unit_tests Review URL: https://codereview.chromium.org/275383002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270024 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/api/declarative')
-rw-r--r--chrome/browser/extensions/api/declarative/rules_registry_service.cc36
-rw-r--r--chrome/browser/extensions/api/declarative/rules_registry_service.h18
2 files changed, 33 insertions, 21 deletions
diff --git a/chrome/browser/extensions/api/declarative/rules_registry_service.cc b/chrome/browser/extensions/api/declarative/rules_registry_service.cc
index 42d0ca4..567dd4e 100644
--- a/chrome/browser/extensions/api/declarative/rules_registry_service.cc
+++ b/chrome/browser/extensions/api/declarative/rules_registry_service.cc
@@ -20,6 +20,7 @@
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/render_process_host.h"
+#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
namespace extensions {
@@ -43,17 +44,13 @@ bool IsWebView(const RulesRegistryService::WebViewKey& webview_key) {
RulesRegistryService::RulesRegistryService(content::BrowserContext* context)
: content_rules_registry_(NULL),
+ extension_registry_observer_(this),
profile_(Profile::FromBrowserContext(context)) {
if (profile_) {
- registrar_.Add(this,
- chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
- content::Source<Profile>(profile_->GetOriginalProfile()));
+ extension_registry_observer_.Add(ExtensionRegistry::Get(profile_));
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
content::Source<Profile>(profile_->GetOriginalProfile()));
- registrar_.Add(this,
- chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
- content::Source<Profile>(profile_->GetOriginalProfile()));
registrar_.Add(
this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
content::NotificationService::AllBrowserContextsAndSources());
@@ -206,18 +203,24 @@ void RulesRegistryService::NotifyRegistriesHelper(
}
}
+void RulesRegistryService::OnExtensionLoaded(
+ content::BrowserContext* browser_context,
+ const Extension* extension) {
+ NotifyRegistriesHelper(&RulesRegistry::OnExtensionLoaded, extension->id());
+}
+
+void RulesRegistryService::OnExtensionUnloaded(
+ content::BrowserContext* browser_context,
+ const Extension* extension,
+ UnloadedExtensionInfo::Reason reason) {
+ NotifyRegistriesHelper(&RulesRegistry::OnExtensionUnloaded, extension->id());
+}
+
void RulesRegistryService::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
- case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
- const Extension* extension =
- content::Details<UnloadedExtensionInfo>(details)->extension;
- NotifyRegistriesHelper(&RulesRegistry::OnExtensionUnloaded,
- extension->id());
- break;
- }
case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: {
const Extension* extension =
content::Details<const Extension>(details).ptr();
@@ -225,13 +228,6 @@ void RulesRegistryService::Observe(
extension->id());
break;
}
- case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
- const Extension* extension =
- content::Details<const Extension>(details).ptr();
- NotifyRegistriesHelper(&RulesRegistry::OnExtensionLoaded,
- extension->id());
- break;
- }
case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
content::RenderProcessHost* process =
content::Source<content::RenderProcessHost>(source).ptr();
diff --git a/chrome/browser/extensions/api/declarative/rules_registry_service.h b/chrome/browser/extensions/api/declarative/rules_registry_service.h
index ae23372..97097ea 100644
--- a/chrome/browser/extensions/api/declarative/rules_registry_service.h
+++ b/chrome/browser/extensions/api/declarative/rules_registry_service.h
@@ -12,11 +12,13 @@
#include "base/callback_forward.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_vector.h"
+#include "base/scoped_observer.h"
#include "chrome/browser/extensions/api/declarative/rules_registry.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
+#include "extensions/browser/extension_registry_observer.h"
class Profile;
@@ -27,6 +29,7 @@ class NotificationSource;
namespace extensions {
class ContentRulesRegistry;
+class ExtensionRegistry;
class RulesRegistry;
class RulesRegistryStorageDelegate;
}
@@ -36,7 +39,8 @@ namespace extensions {
// This class owns all RulesRegistries implementations of an ExtensionService.
// This class lives on the UI thread.
class RulesRegistryService : public BrowserContextKeyedAPI,
- public content::NotificationObserver {
+ public content::NotificationObserver,
+ public ExtensionRegistryObserver {
public:
typedef RulesRegistry::WebViewKey WebViewKey;
struct RulesRegistryKey {
@@ -105,6 +109,14 @@ class RulesRegistryService : public BrowserContextKeyedAPI,
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;
+
// Iterates over all registries, and calls |notification_callback| on them
// with |extension_id| as the argument. If a registry lives on a different
// thread, the call is posted to that thread, so no guarantee of synchronous
@@ -131,6 +143,10 @@ class RulesRegistryService : public BrowserContextKeyedAPI,
content::NotificationRegistrar registrar_;
+ // Listen to extension load, unloaded notification.
+ ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
+ extension_registry_observer_;
+
Profile* profile_;
DISALLOW_COPY_AND_ASSIGN(RulesRegistryService);