Commit 1bd52ffd authored by jitendra.ks's avatar jitendra.ks Committed by Commit bot

Remove deprecated extension notification from ProcessManager.

This patch used EntensionRegistryObserver instead of DEPRECATED extension
NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED removed now.

BUG=411568

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

Cr-Commit-Position: refs/heads/master@{#294799}
parent 0bd04aeb
...@@ -247,15 +247,10 @@ ProcessManager::ProcessManager(BrowserContext* context, ...@@ -247,15 +247,10 @@ ProcessManager::ProcessManager(BrowserContext* context,
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
// ExtensionRegistry is shared between incognito and regular contexts. // ExtensionRegistry is shared between incognito and regular contexts.
DCHECK_EQ(original_context, extension_registry_->browser_context()); DCHECK_EQ(original_context, extension_registry_->browser_context());
extension_registry_->AddObserver(this);
registrar_.Add(this, registrar_.Add(this,
extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
content::Source<BrowserContext>(original_context)); content::Source<BrowserContext>(original_context));
registrar_.Add(this,
extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
content::Source<BrowserContext>(original_context));
registrar_.Add(this,
extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::Source<BrowserContext>(original_context));
registrar_.Add(this, registrar_.Add(this,
extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
content::Source<BrowserContext>(context)); content::Source<BrowserContext>(context));
...@@ -291,6 +286,7 @@ ProcessManager::ProcessManager(BrowserContext* context, ...@@ -291,6 +286,7 @@ ProcessManager::ProcessManager(BrowserContext* context,
} }
ProcessManager::~ProcessManager() { ProcessManager::~ProcessManager() {
extension_registry_->RemoveObserver(this);
CloseBackgroundHosts(); CloseBackgroundHosts();
DCHECK(background_hosts_.empty()); DCHECK(background_hosts_.empty());
content::DevToolsAgentHost::RemoveAgentStateCallback(devtools_callback_); content::DevToolsAgentHost::RemoveAgentStateCallback(devtools_callback_);
...@@ -688,33 +684,6 @@ void ProcessManager::Observe(int type, ...@@ -688,33 +684,6 @@ void ProcessManager::Observe(int type,
break; break;
} }
case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
BrowserContext* context = content::Source<BrowserContext>(source).ptr();
ExtensionSystem* system = ExtensionSystem::Get(context);
if (system->ready().is_signaled()) {
// The extension system is ready, so create the background host.
const Extension* extension =
content::Details<const Extension>(details).ptr();
CreateBackgroundHostForExtensionLoad(this, extension);
}
break;
}
case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
const Extension* extension =
content::Details<UnloadedExtensionInfo>(details)->extension;
for (ExtensionHostSet::iterator iter = background_hosts_.begin();
iter != background_hosts_.end(); ++iter) {
ExtensionHost* host = *iter;
if (host->extension_id() == extension->id()) {
CloseBackgroundHost(host);
break;
}
}
UnregisterExtension(extension->id());
break;
}
case extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED: { case extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED: {
ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
if (background_hosts_.erase(host)) { if (background_hosts_.erase(host)) {
...@@ -780,6 +749,31 @@ void ProcessManager::Observe(int type, ...@@ -780,6 +749,31 @@ void ProcessManager::Observe(int type,
} }
} }
void ProcessManager::OnExtensionLoaded(content::BrowserContext* browser_context,
const extensions::Extension* extension) {
ExtensionSystem* system = ExtensionSystem::Get(browser_context);
if (system->ready().is_signaled()) {
// The extension system is ready, so create the background host.
CreateBackgroundHostForExtensionLoad(this, extension);
}
}
void ProcessManager::OnExtensionUnloaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UnloadedExtensionInfo::Reason reason) {
for (ExtensionHostSet::iterator iter = background_hosts_.begin();
iter != background_hosts_.end();
++iter) {
ExtensionHost* host = *iter;
if (host->extension_id() == extension->id()) {
CloseBackgroundHost(host);
break;
}
}
UnregisterExtension(extension->id());
}
void ProcessManager::OnDevToolsStateChanged( void ProcessManager::OnDevToolsStateChanged(
content::DevToolsAgentHost* agent_host, content::DevToolsAgentHost* agent_host,
bool attached) { bool attached) {
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/view_type.h" #include "extensions/common/view_type.h"
class GURL; class GURL;
...@@ -40,7 +41,8 @@ class ProcessManagerObserver; ...@@ -40,7 +41,8 @@ class ProcessManagerObserver;
// Manages dynamic state of running Chromium extensions. There is one instance // Manages dynamic state of running Chromium extensions. There is one instance
// of this class per Profile. OTR Profiles have a separate instance that keeps // of this class per Profile. OTR Profiles have a separate instance that keeps
// track of split-mode extensions only. // track of split-mode extensions only.
class ProcessManager : public content::NotificationObserver { class ProcessManager : public content::NotificationObserver,
public extensions::ExtensionRegistryObserver {
public: public:
typedef std::set<extensions::ExtensionHost*> ExtensionHostSet; typedef std::set<extensions::ExtensionHost*> ExtensionHostSet;
typedef ExtensionHostSet::const_iterator const_iterator; typedef ExtensionHostSet::const_iterator const_iterator;
...@@ -178,6 +180,16 @@ class ProcessManager : public content::NotificationObserver { ...@@ -178,6 +180,16 @@ class ProcessManager : public content::NotificationObserver {
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE; const content::NotificationDetails& details) OVERRIDE;
// extensions::ExtensionRegistryObserver:
virtual void OnExtensionLoaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension) OVERRIDE;
virtual void OnExtensionUnloaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE;
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
// The set of ExtensionHosts running viewless background extensions. // The set of ExtensionHosts running viewless background extensions.
......
...@@ -110,13 +110,6 @@ TEST_F(ProcessManagerTest, ExtensionNotificationRegistration) { ...@@ -110,13 +110,6 @@ TEST_F(ProcessManagerTest, ExtensionNotificationRegistration) {
EXPECT_TRUE(IsRegistered(manager1.get(), EXPECT_TRUE(IsRegistered(manager1.get(),
extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
original_context())); original_context()));
EXPECT_TRUE(IsRegistered(manager1.get(),
extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
original_context()));
EXPECT_TRUE(
IsRegistered(manager1.get(),
extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
original_context()));
EXPECT_TRUE(IsRegistered(manager1.get(), EXPECT_TRUE(IsRegistered(manager1.get(),
extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
original_context())); original_context()));
...@@ -131,11 +124,6 @@ TEST_F(ProcessManagerTest, ExtensionNotificationRegistration) { ...@@ -131,11 +124,6 @@ TEST_F(ProcessManagerTest, ExtensionNotificationRegistration) {
EXPECT_EQ(incognito_context(), manager2->GetBrowserContext()); EXPECT_EQ(incognito_context(), manager2->GetBrowserContext());
EXPECT_EQ(0u, manager2->background_hosts().size()); EXPECT_EQ(0u, manager2->background_hosts().size());
// Some notifications are observed for the original context.
EXPECT_TRUE(IsRegistered(manager2.get(),
extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
original_context()));
// Some notifications are observed for the incognito context. // Some notifications are observed for the incognito context.
EXPECT_TRUE(IsRegistered(manager2.get(), EXPECT_TRUE(IsRegistered(manager2.get(),
extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
......
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