Index: apps/app_load_service.cc |
diff --git a/apps/app_load_service.cc b/apps/app_load_service.cc |
index efafb1b427e9756de2111adffea5cb15d108d6d7..fe224c5e8ebf7b64a0d2a419ca001be383bc6eaf 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; |
} |