summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorglider <glider@chromium.org>2014-09-15 05:04:30 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-15 12:22:09 +0000
commit34cdb3e534fc53c9d0ad5b4e9754e6a0710bd905 (patch)
treed0526feb144e0219a1d067323db4a4a2a0ed037b
parent67b1e125b3779c9584d41ce8522a3433aea799d8 (diff)
downloadchromium_src-34cdb3e534fc53c9d0ad5b4e9754e6a0710bd905.zip
chromium_src-34cdb3e534fc53c9d0ad5b4e9754e6a0710bd905.tar.gz
chromium_src-34cdb3e534fc53c9d0ad5b4e9754e6a0710bd905.tar.bz2
Revert of Remove deprecated extension notification from ProcessManager. (patchset #2 id:20001 of https://codereview.chromium.org/566863002/)
Reason for revert: One of the tests crashes with a UAF: http://crbug.com/414245 Original issue's description: > Remove deprecated extension notification from ProcessManager. > > This patch used EntensionRegistryObserver instead of DEPRECATED extension > NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED removed now. > > BUG=411568 > > Committed: https://crrev.com/1bd52ffda33ffc5614dab8e3f3d677f0a528e763 > Cr-Commit-Position: refs/heads/master@{#294799} TBR=bauerb@chromium.org,rockot@chromium.org,limasdf@gmail.com,jitendra.ks@samsung.com NOTREECHECKS=true NOTRY=true BUG=411568 Review URL: https://codereview.chromium.org/570073002 Cr-Commit-Position: refs/heads/master@{#294806}
-rw-r--r--extensions/browser/process_manager.cc60
-rw-r--r--extensions/browser/process_manager.h14
-rw-r--r--extensions/browser/process_manager_unittest.cc12
3 files changed, 46 insertions, 40 deletions
diff --git a/extensions/browser/process_manager.cc b/extensions/browser/process_manager.cc
index 38c476e..c3bcd50 100644
--- a/extensions/browser/process_manager.cc
+++ b/extensions/browser/process_manager.cc
@@ -247,11 +247,16 @@ ProcessManager::ProcessManager(BrowserContext* context,
weak_ptr_factory_(this) {
// ExtensionRegistry is shared between incognito and regular contexts.
DCHECK_EQ(original_context, extension_registry_->browser_context());
- extension_registry_->AddObserver(this);
registrar_.Add(this,
extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
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,
extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
content::Source<BrowserContext>(context));
registrar_.Add(this,
@@ -286,7 +291,6 @@ ProcessManager::ProcessManager(BrowserContext* context,
}
ProcessManager::~ProcessManager() {
- extension_registry_->RemoveObserver(this);
CloseBackgroundHosts();
DCHECK(background_hosts_.empty());
content::DevToolsAgentHost::RemoveAgentStateCallback(devtools_callback_);
@@ -684,6 +688,33 @@ void ProcessManager::Observe(int type,
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: {
ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
if (background_hosts_.erase(host)) {
@@ -749,31 +780,6 @@ 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(
content::DevToolsAgentHost* agent_host,
bool attached) {
diff --git a/extensions/browser/process_manager.h b/extensions/browser/process_manager.h
index 8de9bef..e7be995 100644
--- a/extensions/browser/process_manager.h
+++ b/extensions/browser/process_manager.h
@@ -17,7 +17,6 @@
#include "base/time/time.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
-#include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/view_type.h"
class GURL;
@@ -41,8 +40,7 @@ class ProcessManagerObserver;
// Manages dynamic state of running Chromium extensions. There is one instance
// of this class per Profile. OTR Profiles have a separate instance that keeps
// track of split-mode extensions only.
-class ProcessManager : public content::NotificationObserver,
- public extensions::ExtensionRegistryObserver {
+class ProcessManager : public content::NotificationObserver {
public:
typedef std::set<extensions::ExtensionHost*> ExtensionHostSet;
typedef ExtensionHostSet::const_iterator const_iterator;
@@ -180,16 +178,6 @@ class ProcessManager : public content::NotificationObserver,
const content::NotificationSource& source,
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_;
// The set of ExtensionHosts running viewless background extensions.
diff --git a/extensions/browser/process_manager_unittest.cc b/extensions/browser/process_manager_unittest.cc
index 957e3a2..e04b0d3 100644
--- a/extensions/browser/process_manager_unittest.cc
+++ b/extensions/browser/process_manager_unittest.cc
@@ -111,6 +111,13 @@ TEST_F(ProcessManagerTest, ExtensionNotificationRegistration) {
extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
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(),
extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
original_context()));
@@ -124,6 +131,11 @@ TEST_F(ProcessManagerTest, ExtensionNotificationRegistration) {
EXPECT_EQ(incognito_context(), manager2->GetBrowserContext());
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.
EXPECT_TRUE(IsRegistered(manager2.get(),
extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,