Commit c6273c83 authored by limasdf@gmail.com's avatar limasdf@gmail.com

Remove deprecated extension notifications from ProcessManager and use ExtensionRegistry instead.

ProcessManagerTest inherts ExtensionsTest for the test settings. So now unit test is passed.

R=rdevlin.cronin@chromium.org
BUG=354046
TEST=extensions_unittests

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287521 0039d316-1c4b-4281-b951-d872f2087c98
parent 8aa55065
...@@ -245,18 +245,13 @@ ProcessManager::ProcessManager(BrowserContext* context, ...@@ -245,18 +245,13 @@ ProcessManager::ProcessManager(BrowserContext* context,
devtools_callback_(base::Bind(&ProcessManager::OnDevToolsStateChanged, devtools_callback_(base::Bind(&ProcessManager::OnDevToolsStateChanged,
base::Unretained(this))), base::Unretained(this))),
last_background_close_sequence_id_(0), last_background_close_sequence_id_(0),
weak_ptr_factory_(this) { weak_ptr_factory_(this),
extension_registry_observer_(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());
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));
...@@ -267,6 +262,7 @@ ProcessManager::ProcessManager(BrowserContext* context, ...@@ -267,6 +262,7 @@ ProcessManager::ProcessManager(BrowserContext* context,
content::NotificationService::AllSources()); content::NotificationService::AllSources());
registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
content::NotificationService::AllSources()); content::NotificationService::AllSources());
extension_registry_observer_.Add(extension_registry_);
// Note: event_page_idle_time_ must be sufficiently larger (e.g. 2x) than // Note: event_page_idle_time_ must be sufficiently larger (e.g. 2x) than
// kKeepaliveThrottleIntervalInSeconds in ppapi/proxy/plugin_globals. // kKeepaliveThrottleIntervalInSeconds in ppapi/proxy/plugin_globals.
...@@ -664,33 +660,6 @@ void ProcessManager::Observe(int type, ...@@ -664,33 +660,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)) {
...@@ -756,6 +725,30 @@ void ProcessManager::Observe(int type, ...@@ -756,6 +725,30 @@ void ProcessManager::Observe(int type,
} }
} }
void ProcessManager::OnExtensionLoaded(content::BrowserContext* browser_context,
const Extension* extension) {
if (ExtensionSystem::Get(browser_context)->ready().is_signaled()) {
// The extension system is ready, so create the background host.
CreateBackgroundHostForExtensionLoad(this, extension);
}
}
void ProcessManager::OnExtensionUnloaded(
content::BrowserContext* browser_context,
const Extension* extension,
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) {
......
...@@ -14,9 +14,11 @@ ...@@ -14,9 +14,11 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/scoped_observer.h"
#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 +42,8 @@ class ProcessManagerObserver; ...@@ -40,7 +42,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 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;
...@@ -173,6 +176,14 @@ class ProcessManager : public content::NotificationObserver { ...@@ -173,6 +176,14 @@ class ProcessManager : public content::NotificationObserver {
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE; const content::NotificationDetails& details) OVERRIDE;
// ExtensionRegistryObserver:
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;
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
// The set of ExtensionHosts running viewless background extensions. // The set of ExtensionHosts running viewless background extensions.
...@@ -279,6 +290,9 @@ class ProcessManager : public content::NotificationObserver { ...@@ -279,6 +290,9 @@ class ProcessManager : public content::NotificationObserver {
// Must be last member, see doc on WeakPtrFactory. // Must be last member, see doc on WeakPtrFactory.
base::WeakPtrFactory<ProcessManager> weak_ptr_factory_; base::WeakPtrFactory<ProcessManager> weak_ptr_factory_;
ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
extension_registry_observer_;
DISALLOW_COPY_AND_ASSIGN(ProcessManager); DISALLOW_COPY_AND_ASSIGN(ProcessManager);
}; };
......
...@@ -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