Commit bbaa913d authored by limasdf's avatar limasdf Committed by Commit bot

Cleanup/ Remove deprecated extension notification from ExtensionHost

Remove deprecated extension notification from ExtensionHost.
Use ExtensionRegistryObserver instead.

BUG=411568

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

Cr-Commit-Position: refs/heads/master@{#318803}
parent c9631120
...@@ -107,9 +107,9 @@ void ExtensionViewHost::LoadInitialURL() { ...@@ -107,9 +107,9 @@ void ExtensionViewHost::LoadInitialURL() {
if (!ExtensionSystem::Get(browser_context())-> if (!ExtensionSystem::Get(browser_context())->
runtime_data()->IsBackgroundPageReady(extension())) { runtime_data()->IsBackgroundPageReady(extension())) {
// Make sure the background page loads before any others. // Make sure the background page loads before any others.
registrar()->Add(this, registrar_.Add(this,
extensions::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, extensions::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
content::Source<Extension>(extension())); content::Source<Extension>(extension()));
return; return;
} }
...@@ -296,13 +296,11 @@ WebContents* ExtensionViewHost::GetVisibleWebContents() const { ...@@ -296,13 +296,11 @@ WebContents* ExtensionViewHost::GetVisibleWebContents() const {
void ExtensionViewHost::Observe(int type, void ExtensionViewHost::Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
if (type == extensions::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY) { DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY);
DCHECK(ExtensionSystem::Get(browser_context())-> DCHECK(ExtensionSystem::Get(browser_context())
runtime_data()->IsBackgroundPageReady(extension())); ->runtime_data()
LoadInitialURL(); ->IsBackgroundPageReady(extension()));
return; LoadInitialURL();
}
ExtensionHost::Observe(type, source, details);
} }
} // namespace extensions } // namespace extensions
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "components/web_modal/popup_manager.h" #include "components/web_modal/popup_manager.h"
#include "components/web_modal/web_contents_modal_dialog_host.h" #include "components/web_modal/web_contents_modal_dialog_host.h"
#include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/extension_host.h" #include "extensions/browser/extension_host.h"
class Browser; class Browser;
...@@ -29,7 +31,8 @@ class ExtensionView; ...@@ -29,7 +31,8 @@ class ExtensionView;
class ExtensionViewHost class ExtensionViewHost
: public ExtensionHost, : public ExtensionHost,
public web_modal::WebContentsModalDialogManagerDelegate, public web_modal::WebContentsModalDialogManagerDelegate,
public web_modal::WebContentsModalDialogHost { public web_modal::WebContentsModalDialogHost,
public content::NotificationObserver {
public: public:
ExtensionViewHost(const Extension* extension, ExtensionViewHost(const Extension* extension,
content::SiteInstance* site_instance, content::SiteInstance* site_instance,
...@@ -127,6 +130,8 @@ class ExtensionViewHost ...@@ -127,6 +130,8 @@ class ExtensionViewHost
// a parent window. // a parent window.
scoped_ptr<web_modal::PopupManager> popup_manager_; scoped_ptr<web_modal::PopupManager> popup_manager_;
content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(ExtensionViewHost); DISALLOW_COPY_AND_ASSIGN(ExtensionViewHost);
}; };
......
...@@ -13,8 +13,6 @@ ...@@ -13,8 +13,6 @@
#include "content/public/browser/content_browser_client.h" #include "content/public/browser/content_browser_client.h"
#include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/render_widget_host_view.h"
...@@ -25,6 +23,7 @@ ...@@ -25,6 +23,7 @@
#include "extensions/browser/extension_host_delegate.h" #include "extensions/browser/extension_host_delegate.h"
#include "extensions/browser/extension_host_observer.h" #include "extensions/browser/extension_host_observer.h"
#include "extensions/browser/extension_host_queue.h" #include "extensions/browser/extension_host_queue.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h" #include "extensions/browser/extension_system.h"
#include "extensions/browser/extensions_browser_client.h" #include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/load_monitoring_extension_host_queue.h" #include "extensions/browser/load_monitoring_extension_host_queue.h"
...@@ -77,15 +76,15 @@ ExtensionHost::ExtensionHost(const Extension* extension, ...@@ -77,15 +76,15 @@ ExtensionHost::ExtensionHost(const Extension* extension,
// Listen for when an extension is unloaded from the same profile, as it may // Listen for when an extension is unloaded from the same profile, as it may
// be the same extension that this points to. // be the same extension that this points to.
registrar_.Add(this, ExtensionRegistry::Get(browser_context_)->AddObserver(this);
extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::Source<BrowserContext>(browser_context_));
// Set up web contents observers and pref observers. // Set up web contents observers and pref observers.
delegate_->OnExtensionHostCreated(host_contents()); delegate_->OnExtensionHostCreated(host_contents());
} }
ExtensionHost::~ExtensionHost() { ExtensionHost::~ExtensionHost() {
ExtensionRegistry::Get(browser_context_)->RemoveObserver(this);
if (extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE && if (extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE &&
extension_ && BackgroundInfo::HasLazyBackgroundPage(extension_) && extension_ && BackgroundInfo::HasLazyBackgroundPage(extension_) &&
load_start_.get()) { load_start_.get()) {
...@@ -210,23 +209,15 @@ bool ExtensionHost::IsBackgroundPage() const { ...@@ -210,23 +209,15 @@ bool ExtensionHost::IsBackgroundPage() const {
return true; return true;
} }
void ExtensionHost::Observe(int type, void ExtensionHost::OnExtensionUnloaded(
const content::NotificationSource& source, content::BrowserContext* browser_context,
const content::NotificationDetails& details) { const Extension* extension,
switch (type) { UnloadedExtensionInfo::Reason reason) {
case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: // The extension object will be deleted after this notification has been sent.
// The extension object will be deleted after this notification has been // Null it out so that dirty pointer issues don't arise in cases when multiple
// sent. Null it out so that dirty pointer issues don't arise in cases // ExtensionHost objects pointing to the same Extension are present.
// when multiple ExtensionHost objects pointing to the same Extension are if (extension_ == extension) {
// present. extension_ = nullptr;
if (extension_ == content::Details<UnloadedExtensionInfo>(details)->
extension) {
extension_ = nullptr;
}
break;
default:
NOTREACHED() << "Unexpected notification sent.";
break;
} }
} }
......
...@@ -7,18 +7,16 @@ ...@@ -7,18 +7,16 @@
#include <set> #include <set>
#include <string> #include <string>
#include <vector>
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/timer/elapsed_timer.h" #include "base/timer/elapsed_timer.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "extensions/browser/deferred_start_render_host.h" #include "extensions/browser/deferred_start_render_host.h"
#include "extensions/browser/extension_function_dispatcher.h" #include "extensions/browser/extension_function_dispatcher.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/stack_frame.h" #include "extensions/common/stack_frame.h"
#include "extensions/common/view_type.h" #include "extensions/common/view_type.h"
...@@ -49,7 +47,7 @@ class ExtensionHost : public DeferredStartRenderHost, ...@@ -49,7 +47,7 @@ class ExtensionHost : public DeferredStartRenderHost,
public content::WebContentsDelegate, public content::WebContentsDelegate,
public content::WebContentsObserver, public content::WebContentsObserver,
public ExtensionFunctionDispatcher::Delegate, public ExtensionFunctionDispatcher::Delegate,
public content::NotificationObserver { public ExtensionRegistryObserver {
public: public:
ExtensionHost(const Extension* extension, ExtensionHost(const Extension* extension,
content::SiteInstance* site_instance, content::SiteInstance* site_instance,
...@@ -127,14 +125,12 @@ class ExtensionHost : public DeferredStartRenderHost, ...@@ -127,14 +125,12 @@ class ExtensionHost : public DeferredStartRenderHost,
content::MediaStreamType type) override; content::MediaStreamType type) override;
bool IsNeverVisible(content::WebContents* web_contents) override; bool IsNeverVisible(content::WebContents* web_contents) override;
// content::NotificationObserver: // ExtensionRegistryObserver:
void Observe(int type, void OnExtensionUnloaded(content::BrowserContext* browser_context,
const content::NotificationSource& source, const Extension* extension,
const content::NotificationDetails& details) override; UnloadedExtensionInfo::Reason reason) override;
protected: protected:
content::NotificationRegistrar* registrar() { return &registrar_; }
// Called after the extension page finishes loading but before the // Called after the extension page finishes loading but before the
// EXTENSION_HOST_DID_STOP_LOADING notification is sent. // EXTENSION_HOST_DID_STOP_LOADING notification is sent.
virtual void OnDidStopLoading(); virtual void OnDidStopLoading();
...@@ -191,8 +187,6 @@ class ExtensionHost : public DeferredStartRenderHost, ...@@ -191,8 +187,6 @@ class ExtensionHost : public DeferredStartRenderHost,
// Messages sent out to the renderer that have not been acknowledged yet. // Messages sent out to the renderer that have not been acknowledged yet.
std::set<int> unacked_messages_; std::set<int> unacked_messages_;
content::NotificationRegistrar registrar_;
ExtensionFunctionDispatcher extension_function_dispatcher_; ExtensionFunctionDispatcher extension_function_dispatcher_;
// The type of view being hosted. // The type of view being hosted.
......
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