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

Remove NOTIFICATION_EXTENSION_LOADED_DEPRECATED from c/b/ui/extensions

BUG=354046

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270070 0039d316-1c4b-4281-b951-d872f2087c98
parent 314184c5
......@@ -24,7 +24,8 @@ ExtensionEnableFlow::ExtensionEnableFlow(Profile* profile,
extension_id_(extension_id),
delegate_(delegate),
parent_contents_(NULL),
parent_window_(NULL) {
parent_window_(NULL),
extension_registry_observer_(this) {
}
ExtensionEnableFlow::~ExtensionEnableFlow() {
......@@ -110,9 +111,8 @@ void ExtensionEnableFlow::CreatePrompt() {
}
void ExtensionEnableFlow::StartObserving() {
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
content::Source<Profile>(profile_));
extension_registry_observer_.Add(
extensions::ExtensionRegistry::Get(profile_));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOAD_ERROR,
content::Source<Profile>(profile_));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
......@@ -127,16 +127,6 @@ void ExtensionEnableFlow::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
const Extension* extension =
content::Details<const Extension>(details).ptr();
if (extension->id() == extension_id_) {
StopObserving();
CheckPermissionAndMaybePromptUser();
}
break;
}
case chrome::NOTIFICATION_EXTENSION_LOAD_ERROR: {
StopObserving();
delegate_->ExtensionEnableFlowAborted(false);
......@@ -149,7 +139,6 @@ void ExtensionEnableFlow::Observe(int type,
StopObserving();
delegate_->ExtensionEnableFlowAborted(false);
}
break;
}
default:
......@@ -157,6 +146,15 @@ void ExtensionEnableFlow::Observe(int type,
}
}
void ExtensionEnableFlow::OnExtensionLoaded(
content::BrowserContext* browser_context,
const Extension* extension) {
if (extension->id() == extension_id_) {
StopObserving();
CheckPermissionAndMaybePromptUser();
}
}
void ExtensionEnableFlow::InstallUIProceed() {
ExtensionService* service =
extensions::ExtensionSystem::Get(profile_)->extension_service();
......
......@@ -10,10 +10,12 @@
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/scoped_observer.h"
#include "chrome/browser/extensions/extension_install_prompt.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/page_navigator.h"
#include "extensions/browser/extension_registry_observer.h"
class ExtensionEnableFlowDelegate;
......@@ -22,6 +24,10 @@ class PageNavigator;
class WebContents;
}
namespace extensions {
class ExtensionRegistry;
}
// ExtensionEnableFlow performs an UI flow to enable a disabled/terminated
// extension. It calls its delegate when enabling is done or is aborted.
// Callback on the delegate might be called synchronously if there is no
......@@ -31,7 +37,8 @@ class WebContents;
// flow is aborted when user declines it.
class ExtensionEnableFlow : public ExtensionInstallPrompt::Delegate,
public content::PageNavigator,
public content::NotificationObserver {
public content::NotificationObserver,
public extensions::ExtensionRegistryObserver {
public:
ExtensionEnableFlow(Profile* profile,
const std::string& extension_id,
......@@ -77,6 +84,11 @@ class ExtensionEnableFlow : public ExtensionInstallPrompt::Delegate,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// extensions::ExtensionRegistryObserver overrides:
virtual void OnExtensionLoaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension) OVERRIDE;
// ExtensionInstallPrompt::Delegate overrides:
virtual void InstallUIProceed() OVERRIDE;
virtual void InstallUIAbort(bool user_initiated) OVERRIDE;
......@@ -104,6 +116,11 @@ class ExtensionEnableFlow : public ExtensionInstallPrompt::Delegate,
scoped_ptr<ExtensionInstallPrompt> prompt_;
content::NotificationRegistrar registrar_;
// Listen to extension load notification.
ScopedObserver<extensions::ExtensionRegistry,
extensions::ExtensionRegistryObserver>
extension_registry_observer_;
DISALLOW_COPY_AND_ASSIGN(ExtensionEnableFlow);
};
......
......@@ -10,11 +10,13 @@
#include "base/message_loop/message_loop.h"
#include "base/time/time.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/extensions/api/extension_action/action_info.h"
#include "chrome/common/extensions/api/omnibox/omnibox_handler.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
using content::Details;
......@@ -31,12 +33,13 @@ const int kAnimationWaitRetries = 10;
ExtensionInstalledBubble::ExtensionInstalledBubble(Delegate* delegate,
const Extension* extension,
Browser *browser,
Browser* browser,
const SkBitmap& icon)
: delegate_(delegate),
extension_(extension),
browser_(browser),
icon_(icon),
extension_registry_observer_(this),
animation_wait_retries_(0),
weak_factory_(this) {
if (!extensions::OmniboxInfo::GetKeyword(extension).empty())
......@@ -54,11 +57,9 @@ ExtensionInstalledBubble::ExtensionInstalledBubble(Delegate* delegate,
// fired, but all of the EXTENSION_LOADED Observers have run. Only then can we
// be sure that a BrowserAction or PageAction has had views created which we
// can inspect for the purpose of previewing of pointing to them.
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
content::Source<Profile>(browser->profile()));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::Source<Profile>(browser->profile()));
extension_registry_observer_.Add(
extensions::ExtensionRegistry::Get(browser->profile()));
registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSING,
content::Source<Browser>(browser));
}
......@@ -82,38 +83,35 @@ void ExtensionInstalledBubble::ShowInternal() {
}
}
void ExtensionInstalledBubble::OnExtensionLoaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension) {
if (extension == extension_) {
animation_wait_retries_ = 0;
// PostTask to ourself to allow all EXTENSION_LOADED Observers to run.
base::MessageLoopForUI::current()->PostTask(
FROM_HERE,
base::Bind(&ExtensionInstalledBubble::ShowInternal,
weak_factory_.GetWeakPtr()));
}
}
void ExtensionInstalledBubble::OnExtensionUnloaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UnloadedExtensionInfo::Reason reason) {
if (extension == extension_) {
// Extension is going away, make sure ShowInternal won't be called.
weak_factory_.InvalidateWeakPtrs();
extension_ = NULL;
}
}
void ExtensionInstalledBubble::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
const Extension* extension = Details<const Extension>(details).ptr();
if (extension == extension_) {
animation_wait_retries_ = 0;
// PostTask to ourself to allow all EXTENSION_LOADED Observers to run.
base::MessageLoopForUI::current()->PostTask(
FROM_HERE,
base::Bind(&ExtensionInstalledBubble::ShowInternal,
weak_factory_.GetWeakPtr()));
}
break;
}
case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
const Extension* extension =
Details<extensions::UnloadedExtensionInfo>(details)->extension;
if (extension == extension_) {
// Extension is going away, make sure ShowInternal won't be called.
weak_factory_.InvalidateWeakPtrs();
extension_ = NULL;
}
break;
}
case chrome::NOTIFICATION_BROWSER_CLOSING:
delete delegate_;
break;
default:
NOTREACHED() << "Received unexpected notification";
}
DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_CLOSING)
<< "Received unexpected notification";
delete delegate_;
}
......@@ -6,14 +6,17 @@
#define CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_INSTALLED_BUBBLE_H_
#include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/extension_registry_observer.h"
#include "third_party/skia/include/core/SkBitmap.h"
class Browser;
namespace extensions {
class Extension;
class ExtensionRegistry;
}
// Provides feedback to the user upon successful installation of an
......@@ -27,7 +30,8 @@ class Extension;
// don't specify a default icon.
//
// ExtensionInstallBubble manages its own lifetime.
class ExtensionInstalledBubble : public content::NotificationObserver {
class ExtensionInstalledBubble : public content::NotificationObserver,
public extensions::ExtensionRegistryObserver {
public:
// The behavior and content of this Bubble comes in these varieties:
enum BubbleType {
......@@ -72,6 +76,15 @@ class ExtensionInstalledBubble : 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;
// The view delegate that shows the bubble. Owns us.
Delegate* delegate_;
......@@ -82,6 +95,11 @@ class ExtensionInstalledBubble : public content::NotificationObserver {
BubbleType type_;
content::NotificationRegistrar registrar_;
// Listen to extension load, unloaded notifications.
ScopedObserver<extensions::ExtensionRegistry,
extensions::ExtensionRegistryObserver>
extension_registry_observer_;
// The number of times to retry showing the bubble if the browser action
// toolbar is animating.
int animation_wait_retries_;
......
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