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

Remove some NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED from c/b/extensions Part2

BUG=354046,354458

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266649 0039d316-1c4b-4281-b951-d872f2087c98
parent a60c649c
......@@ -24,6 +24,7 @@
#include "content/public/common/frame_navigate_params.h"
#include "content/public/common/page_transition_types.h"
#include "content/public/test/test_browser_thread.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/features/feature.h"
......@@ -290,13 +291,10 @@ TEST_F(ActiveTabTest, Uninstalling) {
EXPECT_TRUE(IsAllowed(extension, google));
// Uninstalling the extension should clear its tab permissions.
UnloadedExtensionInfo details(extension.get(),
UnloadedExtensionInfo::REASON_DISABLE);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::Source<Profile>(Profile::FromBrowserContext(
web_contents()->GetBrowserContext())),
content::Details<UnloadedExtensionInfo>(&details));
ExtensionRegistry* registry =
ExtensionRegistry::Get(web_contents()->GetBrowserContext());
registry->TriggerOnUnloaded(extension.get(),
UnloadedExtensionInfo::REASON_DISABLE);
// Note: can't EXPECT_FALSE(IsAllowed) here because uninstalled extensions
// are just that... considered to be uninstalled, and the manager might
......
......@@ -6,15 +6,13 @@
#include "base/strings/string_number_conversions.h"
#include "base/values.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/extensions/api/input_ime.h"
#include "chrome/common/extensions/api/input_ime/input_components_handler.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_function_registry.h"
#include "extensions/browser/extension_registry.h"
#if defined(USE_X11)
#include "chrome/browser/chromeos/input_method/input_method_engine.h"
......@@ -776,21 +774,16 @@ bool InputImeKeyEventHandledFunction::RunImpl() {
}
InputImeAPI::InputImeAPI(content::BrowserContext* context)
: profile_(Profile::FromBrowserContext(context)) {
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
content::Source<Profile>(profile_));
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::Source<Profile>(profile_));
EventRouter* event_router = EventRouter::Get(profile_);
: browser_context_(context), extension_registry_observer_(this) {
extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_));
EventRouter* event_router = EventRouter::Get(browser_context_);
event_router->RegisterObserver(this, input_ime::OnActivate::kEventName);
event_router->RegisterObserver(this, input_ime::OnFocus::kEventName);
}
InputImeAPI::~InputImeAPI() {
EventRouter::Get(profile_)->UnregisterObserver(this);
EventRouter::Get(browser_context_)->UnregisterObserver(this);
}
static base::LazyInstance<BrowserContextKeyedAPIFactory<InputImeAPI> >
......@@ -801,42 +794,40 @@ BrowserContextKeyedAPIFactory<InputImeAPI>* InputImeAPI::GetFactoryInstance() {
return g_factory.Pointer();
}
void InputImeAPI::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
if (type == chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED) {
const Extension* extension =
content::Details<const Extension>(details).ptr();
const std::vector<InputComponentInfo>* input_components =
extensions::InputComponents::GetInputComponents(extension);
if (!input_components)
return;
for (std::vector<extensions::InputComponentInfo>::const_iterator component =
input_components->begin(); component != input_components->end();
++component) {
if (component->type == extensions::INPUT_COMPONENT_TYPE_IME) {
// Don't pass profile_ to register ime, instead always use
// GetActiveUserProfile. It is because:
// The original profile for login screen is called signin profile.
// And the active profile is the incognito profile based on signin
// profile. So if |profile_| is signin profile, we need to make sure
// the router/observer runs under its incognito profile, because the
// component extensions were installed under its incognito profile.
input_ime_event_router()->RegisterIme(extension->id(), *component);
}
void InputImeAPI::OnExtensionLoaded(content::BrowserContext* browser_context,
const Extension* extension) {
const std::vector<InputComponentInfo>* input_components =
extensions::InputComponents::GetInputComponents(extension);
if (!input_components)
return;
for (std::vector<extensions::InputComponentInfo>::const_iterator component =
input_components->begin();
component != input_components->end();
++component) {
if (component->type == extensions::INPUT_COMPONENT_TYPE_IME) {
// Don't pass profile_ to register ime, instead always use
// GetActiveUserProfile. It is because:
// The original profile for login screen is called signin profile.
// And the active profile is the incognito profile based on signin
// profile. So if |profile_| is signin profile, we need to make sure
// the router/observer runs under its incognito profile, because the
// component extensions were installed under its incognito profile.
input_ime_event_router()->RegisterIme(extension->id(), *component);
}
} else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) {
const Extension* extension =
content::Details<const UnloadedExtensionInfo>(details)->extension;
const std::vector<InputComponentInfo>* input_components =
extensions::InputComponents::GetInputComponents(extension);
if (!input_components)
return;
if (input_components->size() > 0)
input_ime_event_router()->UnregisterAllImes(extension->id());
}
}
void InputImeAPI::OnExtensionUnloaded(content::BrowserContext* browser_context,
const Extension* extension,
UnloadedExtensionInfo::Reason reason) {
const std::vector<InputComponentInfo>* input_components =
extensions::InputComponents::GetInputComponents(extension);
if (!input_components)
return;
if (input_components->size() > 0)
input_ime_event_router()->UnregisterAllImes(extension->id());
}
void InputImeAPI::OnListenerAdded(const EventListenerInfo& details) {
InputMethodEngineInterface* engine =
input_ime_event_router()->GetActiveEngine(details.extension_id);
......
......@@ -10,15 +10,15 @@
#include <vector>
#include "base/memory/singleton.h"
#include "base/scoped_observer.h"
#include "base/values.h"
#include "chrome/browser/chromeos/input_method/input_method_engine_interface.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_function.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/extension.h"
class Profile;
......@@ -29,6 +29,7 @@ class ImeObserver;
} // namespace chromeos
namespace extensions {
class ExtensionRegistry;
struct InputComponentInfo;
class InputImeEventRouter {
......@@ -219,7 +220,7 @@ class InputImeHideInputViewFunction : public AsyncExtensionFunction {
};
class InputImeAPI : public BrowserContextKeyedAPI,
public content::NotificationObserver,
public ExtensionRegistryObserver,
public EventRouter::Observer {
public:
explicit InputImeAPI(content::BrowserContext* context);
......@@ -228,10 +229,13 @@ class InputImeAPI : public BrowserContextKeyedAPI,
// BrowserContextKeyedAPI implementation.
static BrowserContextKeyedAPIFactory<InputImeAPI>* GetFactoryInstance();
// content::NotificationObserver implementation.
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// ExtensionRegistryObserver implementation.
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;
// EventRouter::Observer implementation.
virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE;
......@@ -246,8 +250,11 @@ class InputImeAPI : public BrowserContextKeyedAPI,
}
static const bool kServiceIsNULLWhileTesting = true;
Profile* const profile_;
content::NotificationRegistrar registrar_;
content::BrowserContext* const browser_context_;
// Listen to extension load, unloaded notifications.
ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
extension_registry_observer_;
};
} // namespace extensions
......
......@@ -35,6 +35,7 @@ class FilterHandler {
bool IsValidProcess(const std::string& process) const;
const api::log_private::Filter* GetFilter() const { return &filter_; }
private:
api::log_private::Filter filter_;
......
......@@ -8,26 +8,25 @@
#include <set>
#include <string>
#include "base/scoped_observer.h"
#include "chrome/browser/extensions/api/log_private/filter_handler.h"
#include "chrome/browser/extensions/api/log_private/log_parser.h"
#include "chrome/browser/extensions/chrome_extension_function.h"
#include "chrome/browser/feedback/system_logs/about_system_logs_fetcher.h"
#include "chrome/common/extensions/api/log_private.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/extension_registry_observer.h"
#include "net/base/net_log.h"
class Profile;
namespace content {
class BrowserContext;
}
namespace extensions {
class ExtensionRegistry;
class LogPrivateAPI : public BrowserContextKeyedAPI,
public content::NotificationObserver,
public ExtensionRegistryObserver,
public net::NetLog::ThreadSafeObserver {
public:
// Convenience method to get the LogPrivateAPI for a profile.
......@@ -42,14 +41,15 @@ class LogPrivateAPI : public BrowserContextKeyedAPI,
// BrowserContextKeyedAPI implementation.
static BrowserContextKeyedAPIFactory<LogPrivateAPI>* GetFactoryInstance();
// content::NotificationObserver implementation.
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
private:
friend class BrowserContextKeyedAPIFactory<LogPrivateAPI>;
// ExtensionRegistryObserver implementation.
virtual void OnExtensionUnloaded(
content::BrowserContext* browser_context,
const Extension* extension,
UnloadedExtensionInfo::Reason reason) OVERRIDE;
// ChromeNetLog::ThreadSafeObserver implementation:
virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE;
......@@ -67,11 +67,14 @@ class LogPrivateAPI : public BrowserContextKeyedAPI,
static const bool kServiceIsNULLWhileTesting = true;
static const bool kServiceRedirectedInIncognito = true;
Profile* const profile_;
content::BrowserContext* const browser_context_;
bool logging_net_internals_;
content::NotificationRegistrar registrar_;
std::set<std::string> net_internal_watches_;
scoped_ptr<base::ListValue> pending_entries_;
// Listen to extension unloaded notifications.
ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
extension_registry_observer_;
};
class LogPrivateGetHistoricalFunction : public AsyncExtensionFunction {
......
......@@ -13,7 +13,6 @@
#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/api/log_private/filter_handler.h"
#include "chrome/browser/extensions/api/log_private/log_parser.h"
#include "chrome/browser/extensions/api/log_private/syslog_parser.h"
......@@ -22,10 +21,9 @@
#include "chrome/browser/net/chrome_net_log.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/log_private.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_function.h"
#include "extensions/browser/extension_registry.h"
using content::BrowserThread;
......@@ -71,11 +69,10 @@ LogPrivateAPI* LogPrivateAPI::Get(content::BrowserContext* context) {
}
LogPrivateAPI::LogPrivateAPI(content::BrowserContext* context)
: profile_(Profile::FromBrowserContext(context)),
logging_net_internals_(false) {
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::Source<Profile>(profile_));
: browser_context_(context),
logging_net_internals_(false),
extension_registry_observer_(this) {
extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_));
}
LogPrivateAPI::~LogPrivateAPI() {
......@@ -100,7 +97,7 @@ static base::LazyInstance<BrowserContextKeyedAPIFactory<LogPrivateAPI> >
// static
BrowserContextKeyedAPIFactory<LogPrivateAPI>*
LogPrivateAPI::GetFactoryInstance() {
return &g_factory.Get();
return g_factory.Pointer();
}
void LogPrivateAPI::OnAddEntry(const net::NetLog::Entry& entry) {
......@@ -133,7 +130,8 @@ void LogPrivateAPI::AddEntriesOnUI(scoped_ptr<base::ListValue> value) {
event_args->Append(value->DeepCopy());
scoped_ptr<Event> event(new Event(events::kOnAddNetInternalsEntries,
event_args.Pass()));
EventRouter::Get(profile_)->DispatchEventToExtension(*ix, event.Pass());
EventRouter::Get(browser_context_)
->DispatchEventToExtension(*ix, event.Pass());
}
}
......@@ -163,14 +161,11 @@ void LogPrivateAPI::StopNetInternalLogging() {
}
}
void LogPrivateAPI::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) {
const Extension* extension =
content::Details<const UnloadedExtensionInfo>(details)->extension;
StopNetInternalsWatch(extension->id());
}
void LogPrivateAPI::OnExtensionUnloaded(
content::BrowserContext* browser_context,
const Extension* extension,
UnloadedExtensionInfo::Reason reason) {
StopNetInternalsWatch(extension->id());
}
LogPrivateGetHistoricalFunction::LogPrivateGetHistoricalFunction() {
......
......@@ -13,6 +13,7 @@
#include "components/infobars/core/infobar.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"
ExtensionInfoBarDelegate::~ExtensionInfoBarDelegate() {
......@@ -41,15 +42,16 @@ ExtensionInfoBarDelegate::ExtensionInfoBarDelegate(
browser_(browser),
#endif
extension_(extension),
extension_registry_observer_(this),
closing_(false) {
extension_view_host_.reset(
extensions::ExtensionViewHostFactory::CreateInfobarHost(url, browser));
extension_view_host_->SetAssociatedWebContents(web_contents);
extension_registry_observer_.Add(
extensions::ExtensionRegistry::Get(browser->profile()));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
content::Source<Profile>(browser->profile()));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::Source<Profile>(browser->profile()));
height_ = std::max(0, height);
height_ = std::min(2 * infobars::InfoBar::kDefaultBarTargetHeight, height_);
......@@ -95,18 +97,20 @@ ExtensionInfoBarDelegate*
return this;
}
void ExtensionInfoBarDelegate::OnExtensionUnloaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UnloadedExtensionInfo::Reason reason) {
if (extension_ == extension)
infobar()->RemoveSelf();
}
void ExtensionInfoBarDelegate::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
if (type == chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE) {
if (extension_view_host_.get() ==
content::Details<extensions::ExtensionHost>(details).ptr())
infobar()->RemoveSelf();
} else {
DCHECK(type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED);
if (extension_ == content::Details<extensions::UnloadedExtensionInfo>(
details)->extension)
infobar()->RemoveSelf();
}
DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE);
if (extension_view_host_.get() ==
content::Details<extensions::ExtensionHost>(details).ptr())
infobar()->RemoveSelf();
}
......@@ -6,9 +6,11 @@
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_INFOBAR_DELEGATE_H_
#include "base/memory/scoped_ptr.h"
#include "base/scoped_observer.h"
#include "chrome/browser/infobars/confirm_infobar_delegate.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/extension_registry_observer.h"
class Browser;
class GURL;
......@@ -19,13 +21,15 @@ class WebContents;
namespace extensions {
class Extension;
class ExtensionRegistry;
class ExtensionViewHost;
}
// The InfobarDelegate for creating and managing state for the ExtensionInfobar
// plus monitor when the extension goes away.
class ExtensionInfoBarDelegate : public infobars::InfoBarDelegate,
public content::NotificationObserver {
public content::NotificationObserver,
public extensions::ExtensionRegistryObserver {
public:
virtual ~ExtensionInfoBarDelegate();
......@@ -59,18 +63,24 @@ class ExtensionInfoBarDelegate : public infobars::InfoBarDelegate,
static scoped_ptr<infobars::InfoBar> CreateInfoBar(
scoped_ptr<ExtensionInfoBarDelegate> delegate);
// InfoBarDelegate:
// InfoBarDelegate.
virtual bool EqualsDelegate(
infobars::InfoBarDelegate* delegate) const OVERRIDE;
virtual void InfoBarDismissed() OVERRIDE;
virtual Type GetInfoBarType() const OVERRIDE;
virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate() OVERRIDE;
// content::NotificationObserver:
// content::NotificationObserver.
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// extensions::ExtensionRegistryObserver.
virtual void OnExtensionUnloaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE;
#if defined(TOOLKIT_VIEWS)
Browser* browser_; // We pass this to the ExtensionInfoBar.
#endif
......@@ -82,6 +92,10 @@ class ExtensionInfoBarDelegate : public infobars::InfoBarDelegate,
const extensions::Extension* extension_;
content::NotificationRegistrar registrar_;
ScopedObserver<extensions::ExtensionRegistry,
extensions::ExtensionRegistryObserver>
extension_registry_observer_;
// The requested height of the infobar (in pixels).
int height_;
......
......@@ -26,6 +26,7 @@
#include "content/public/browser/notification_source.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/pref_names.h"
#include "extensions/common/extension.h"
......@@ -47,12 +48,10 @@ ExtensionToolbarModel::ExtensionToolbarModel(
prefs_(profile_->GetPrefs()),
extensions_initialized_(false),
is_highlighting_(false),
extension_registry_observer_(this),
weak_ptr_factory_(this) {
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
content::Source<Profile>(profile_));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
content::Source<Profile>(profile_));
extension_registry_observer_.Add(ExtensionRegistry::Get(profile_));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY,
content::Source<Profile>(profile_));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
......@@ -180,6 +179,29 @@ void ExtensionToolbarModel::SetVisibleIconCount(int count) {
}
}
void ExtensionToolbarModel::OnExtensionLoaded(
content::BrowserContext* browser_context,
const Extension* extension) {
// We don't want to add the same extension twice. It may have already been
// added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user
// hides the browser action and then disables and enables the extension.
for (size_t i = 0; i < toolbar_items_.size(); i++) {
if (toolbar_items_[i].get() == extension)
return;
}
if (ExtensionActionAPI::GetBrowserActionVisibility(extension_prefs_,
extension->id())) {
AddExtension(extension);
}
}
void ExtensionToolbarModel::OnExtensionUnloaded(
content::BrowserContext* browser_context,
const Extension* extension,
UnloadedExtensionInfo::Reason reason) {
RemoveExtension(extension);
}
void ExtensionToolbarModel::Observe(
int type,
const content::NotificationSource& source,
......@@ -194,29 +216,6 @@ void ExtensionToolbarModel::Observe(
case chrome::NOTIFICATION_EXTENSIONS_READY:
InitializeExtensionList(extension_service);
break;
case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
const Extension* extension =
content::Details<const Extension>(details).ptr();
// We don't want to add the same extension twice. It may have already been
// added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user
// hides the browser action and then disables and enables the extension.
for (size_t i = 0; i < toolbar_items_.size(); i++) {
if (toolbar_items_[i].get() == extension)
return; // Already exists.
}
if (ExtensionActionAPI::GetBrowserActionVisibility(extension_prefs_,
extension->id())) {
AddExtension(extension);
}
break;
}
case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
const Extension* extension =
content::Details<extensions::UnloadedExtensionInfo>(details)
->extension;
RemoveExtension(extension);
break;
}
case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: {
const Extension* extension =
content::Details<const Extension>(details).ptr();
......
......@@ -8,10 +8,12 @@
#include "base/compiler_specific.h"
#include "base/observer_list.h"
#include "base/prefs/pref_change_registrar.h"
#include "base/scoped_observer.h"
#include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/extension.h"
class Browser;
......@@ -20,9 +22,11 @@ class PrefService;
class Profile;
namespace extensions {
class ExtensionRegistry;
// Model for the browser actions toolbar.
class ExtensionToolbarModel : public content::NotificationObserver,
public ExtensionRegistryObserver,
public KeyedService {
public:
ExtensionToolbarModel(Profile* profile, ExtensionPrefs* extension_prefs);
......@@ -137,6 +141,14 @@ class ExtensionToolbarModel : public content::NotificationObserver,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// ExtensionRegistryObserver implementation.
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;
// To be called after the extension service is ready; gets loaded extensions
// from the extension service and their saved order from the pref service
// and constructs |toolbar_items_| from these data.
......@@ -193,6 +205,10 @@ class ExtensionToolbarModel : public content::NotificationObserver,
content::NotificationRegistrar registrar_;
// Listen to extension load, unloaded notifications.
ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
extension_registry_observer_;
// For observing change of toolbar order preference by external entity (sync).
PrefChangeRegistrar pref_change_registrar_;
base::Closure pref_change_callback_;
......
......@@ -12,6 +12,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram.h"
#include "base/scoped_observer.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/chrome_notification_types.h"
......@@ -27,21 +28,17 @@
#include "chrome/browser/ui/global_error/global_error.h"
#include "chrome/browser/ui/global_error/global_error_service.h"
#include "chrome/browser/ui/global_error/global_error_service_factory.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/manifest_url_handler.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_source.h"
#include "extensions/common/extension.h"
#include "grit/chromium_strings.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_registry_observer.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/size.h"
namespace extensions {
......@@ -58,6 +55,10 @@ static const int kMenuCommandId = IDC_EXTERNAL_EXTENSION_ALERT;
class ExternalInstallGlobalError;
namespace extensions {
class ExtensionRegistry;
}
// This class is refcounted to stay alive while we try and pull webstore data.
class ExternalInstallDialogDelegate
: public ExtensionInstallPrompt::Delegate,
......@@ -89,7 +90,7 @@ class ExternalInstallDialogDelegate
virtual void OnWebstoreResponseParseFailure(
const std::string& error) OVERRIDE;
// NotificationObserver:
// content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
......@@ -114,7 +115,8 @@ class ExternalInstallDialogDelegate
// Only shows a menu item, no bubble. Clicking the menu item shows
// an external install dialog.
class ExternalInstallMenuAlert : public GlobalErrorWithStandardBubble,
public content::NotificationObserver {
public content::NotificationObserver,
public ExtensionRegistryObserver {
public:
ExternalInstallMenuAlert(ExtensionService* service,
const Extension* extension);
......@@ -135,17 +137,29 @@ class ExternalInstallMenuAlert : public GlobalErrorWithStandardBubble,
virtual void BubbleViewAcceptButtonPressed(Browser* browser) OVERRIDE;
virtual void BubbleViewCancelButtonPressed(Browser* browser) OVERRIDE;
protected:
ExtensionService* service_;
const Extension* extension_;
private:
// Delete this instance after cleaning jobs.
void Clean();
// content::NotificationObserver implementation.
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
protected:
ExtensionService* service_;
const Extension* extension_;
// ExtensionRegistryObserver implementation.
virtual void OnExtensionLoaded(content::BrowserContext* browser_context,
const Extension* extension) OVERRIDE;
content::NotificationRegistrar registrar_;
private:
// Listen to extension load notifications.
ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
extension_registry_observer_;
DISALLOW_COPY_AND_ASSIGN(ExternalInstallMenuAlert);
};
......@@ -335,14 +349,12 @@ void ExternalInstallDialogDelegate::InstallUIAbort(bool user_initiated) {
// ExternalInstallMenuAlert -------------------------------------------------
ExternalInstallMenuAlert::ExternalInstallMenuAlert(
ExtensionService* service,
const Extension* extension)
ExternalInstallMenuAlert::ExternalInstallMenuAlert(ExtensionService* service,
const Extension* extension)
: service_(service),
extension_(extension) {
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
content::Source<Profile>(service->profile()));
extension_(extension),
extension_registry_observer_(this) {
extension_registry_observer_.Add(ExtensionRegistry::Get(service->profile()));
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_REMOVED,
content::Source<Profile>(service->profile()));
}
......@@ -410,16 +422,25 @@ void ExternalInstallMenuAlert::BubbleViewCancelButtonPressed(
NOTREACHED();
}
void ExternalInstallMenuAlert::OnExtensionLoaded(
content::BrowserContext* browser_context,
const Extension* extension) {
if (extension == extension_)
Clean();
}
void ExternalInstallMenuAlert::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
// The error is invalidated if the extension has been loaded or removed.
DCHECK(type == chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED ||
type == chrome::NOTIFICATION_EXTENSION_REMOVED);
DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_REMOVED);
const Extension* extension = content::Details<const Extension>(details).ptr();
if (extension != extension_)
return;
if (extension == extension_)
Clean();
}
void ExternalInstallMenuAlert::Clean() {
GlobalErrorService* error_service =
GlobalErrorServiceFactory::GetForProfile(service_->profile());
error_service->RemoveGlobalError(this);
......
......@@ -20,8 +20,9 @@ void AddExternalInstallError(ExtensionService* service,
bool is_new_profile);
void RemoveExternalInstallError(ExtensionService* service);
// Used for testing.
bool HasExternalInstallError(ExtensionService* service);
// Used for testing.
bool HasExternalInstallBubble(ExtensionService* service);
} // namespace extensions
......
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