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/app_load_service.cc | |
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/app_load_service.cc')
-rw-r--r-- | apps/app_load_service.cc | 102 |
1 files changed, 49 insertions, 53 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; } |