diff options
author | limasdf <limasdf@gmail.com> | 2014-09-16 17:21:43 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-17 00:21:59 +0000 |
commit | d37917586956816bf0a0b0f02e68d7b2998e412e (patch) | |
tree | 431eab25957b8578a2404c22f8aca0ee8d2a29e1 /apps | |
parent | 416440522fa2e5034c76a2adbe069bc7c6faaf55 (diff) | |
download | chromium_src-d37917586956816bf0a0b0f02e68d7b2998e412e.zip chromium_src-d37917586956816bf0a0b0f02e68d7b2998e412e.tar.gz chromium_src-d37917586956816bf0a0b0f02e68d7b2998e412e.tar.bz2 |
Remove deprecated extension notification from AppLoadService
BUG=354046
Review URL: https://codereview.chromium.org/441553002
Cr-Commit-Position: refs/heads/master@{#295186}
Diffstat (limited to 'apps')
-rw-r--r-- | apps/app_load_service.cc | 102 | ||||
-rw-r--r-- | apps/app_load_service.h | 13 | ||||
-rw-r--r-- | apps/app_load_service_factory.cc | 6 |
3 files changed, 64 insertions, 57 deletions
diff --git a/apps/app_load_service.cc b/apps/app_load_service.cc index efafb1b..fe224c5 100644 --- a/apps/app_load_service.cc +++ b/apps/app_load_service.cc @@ -16,6 +16,7 @@ #include "extensions/browser/app_window/app_window_registry.h" #include "extensions/browser/extension_host.h" #include "extensions/browser/extension_prefs.h" +#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_system.h" #include "extensions/browser/notification_types.h" #include "extensions/common/extension.h" @@ -36,12 +37,12 @@ AppLoadService::AppLoadService(Profile* profile) registrar_.Add(this, extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, content::NotificationService::AllSources()); - registrar_.Add(this, - extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, - content::NotificationService::AllSources()); + extensions::ExtensionRegistry::Get(profile_)->AddObserver(this); } -AppLoadService::~AppLoadService() {} +AppLoadService::~AppLoadService() { + extensions::ExtensionRegistry::Get(profile_)->RemoveObserver(this); +} void AppLoadService::RestartApplication(const std::string& extension_id) { post_reload_actions_[extension_id].action_type = RESTART; @@ -84,64 +85,59 @@ AppLoadService* AppLoadService::Get(Profile* profile) { void AppLoadService::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { - switch (type) { - case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { - extensions::ExtensionHost* host = - content::Details<extensions::ExtensionHost>(details).ptr(); - const Extension* extension = host->extension(); - // It is possible for an extension to be unloaded before it stops loading. - if (!extension) - break; - std::map<std::string, PostReloadAction>::iterator it = - post_reload_actions_.find(extension->id()); - if (it == post_reload_actions_.end()) - break; - - switch (it->second.action_type) { - case LAUNCH: - LaunchPlatformApp(profile_, extension); - break; - case RESTART: - RestartPlatformApp(profile_, extension); - break; - case LAUNCH_WITH_COMMAND_LINE: - LaunchPlatformAppWithCommandLine( - profile_, extension, it->second.command_line, - it->second.current_dir); - break; - default: - NOTREACHED(); - } - - post_reload_actions_.erase(it); + DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING); + extensions::ExtensionHost* host = + content::Details<extensions::ExtensionHost>(details).ptr(); + const Extension* extension = host->extension(); + // It is possible for an extension to be unloaded before it stops loading. + if (!extension) + return; + std::map<std::string, PostReloadAction>::iterator it = + post_reload_actions_.find(extension->id()); + if (it == post_reload_actions_.end()) + return; + + switch (it->second.action_type) { + case LAUNCH: + LaunchPlatformApp(profile_, extension); + break; + case RESTART: + RestartPlatformApp(profile_, extension); break; - } - case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { - const extensions::UnloadedExtensionInfo* unload_info = - content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); - if (!unload_info->extension->is_platform_app()) - break; - - extensions::ExtensionPrefs* extension_prefs = - extensions::ExtensionPrefs::Get(profile_); - if (WasUnloadedForReload(*unload_info) && - extension_prefs->IsActive(unload_info->extension->id()) && - !HasPostReloadAction(unload_info->extension->id())) { - post_reload_actions_[unload_info->extension->id()].action_type = LAUNCH; - } + case LAUNCH_WITH_COMMAND_LINE: + LaunchPlatformAppWithCommandLine( + profile_, extension, it->second.command_line, it->second.current_dir); break; - } default: NOTREACHED(); } + + post_reload_actions_.erase(it); +} + +void AppLoadService::OnExtensionUnloaded( + content::BrowserContext* browser_context, + const Extension* extension, + extensions::UnloadedExtensionInfo::Reason reason) { + if (!extension->is_platform_app()) + return; + + extensions::ExtensionPrefs* extension_prefs = + extensions::ExtensionPrefs::Get(browser_context); + if (WasUnloadedForReload(extension->id(), reason) && + extension_prefs->IsActive(extension->id()) && + !HasPostReloadAction(extension->id())) { + post_reload_actions_[extension->id()].action_type = LAUNCH; + } } bool AppLoadService::WasUnloadedForReload( - const extensions::UnloadedExtensionInfo& unload_info) { - if (unload_info.reason == extensions::UnloadedExtensionInfo::REASON_DISABLE) { + const extensions::ExtensionId& extension_id, + const extensions::UnloadedExtensionInfo::Reason reason) { + if (reason == extensions::UnloadedExtensionInfo::REASON_DISABLE) { ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_); - return (prefs->GetDisableReasons(unload_info.extension->id()) & - Extension::DISABLE_RELOAD) != 0; + return (prefs->GetDisableReasons(extension_id) & + Extension::DISABLE_RELOAD) != 0; } return false; } diff --git a/apps/app_load_service.h b/apps/app_load_service.h index 1f49980..041b1ab 100644 --- a/apps/app_load_service.h +++ b/apps/app_load_service.h @@ -13,6 +13,7 @@ #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_registry_observer.h" class Profile; @@ -25,7 +26,8 @@ namespace apps { // Monitors apps being reloaded and performs app specific actions (like launch // or restart) on them. Also provides an interface to schedule these actions. class AppLoadService : public KeyedService, - public content::NotificationObserver { + public content::NotificationObserver, + public extensions::ExtensionRegistryObserver { public: enum PostReloadActionType { LAUNCH, @@ -67,8 +69,15 @@ class AppLoadService : public KeyedService, 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; + bool WasUnloadedForReload( - const extensions::UnloadedExtensionInfo& unload_info); + const extensions::ExtensionId& extension_id, + const extensions::UnloadedExtensionInfo::Reason reason); bool HasPostReloadAction(const std::string& extension_id); // Map of extension id to reload action. Absence from the map implies diff --git a/apps/app_load_service_factory.cc b/apps/app_load_service_factory.cc index 0733667..94eac78 100644 --- a/apps/app_load_service_factory.cc +++ b/apps/app_load_service_factory.cc @@ -9,6 +9,7 @@ #include "components/keyed_service/content/browser_context_dependency_manager.h" #include "extensions/browser/app_window/app_window_registry.h" #include "extensions/browser/extension_prefs_factory.h" +#include "extensions/browser/extension_registry_factory.h" #include "extensions/browser/extension_system_provider.h" #include "extensions/browser/extensions_browser_client.h" @@ -28,10 +29,11 @@ AppLoadServiceFactory::AppLoadServiceFactory() : BrowserContextKeyedServiceFactory( "AppLoadService", BrowserContextDependencyManager::GetInstance()) { + DependsOn(extensions::AppWindowRegistry::Factory::GetInstance()); + DependsOn(extensions::ExtensionPrefsFactory::GetInstance()); + DependsOn(extensions::ExtensionRegistryFactory::GetInstance()); DependsOn( extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); - DependsOn(extensions::ExtensionPrefsFactory::GetInstance()); - DependsOn(extensions::AppWindowRegistry::Factory::GetInstance()); } AppLoadServiceFactory::~AppLoadServiceFactory() { |